6.) Is the following statement correct or what is the output?
int i=0;
printf("%d %d %d",i++,i++,i++);
Ans - No, it is not. The order of evaluation of functional arguments is unspecified according to the C and C++ standards.
C90 standard:
6.5.2.2 Function calls
The order of evaluation of the function designator, the actual arguments, and
subexpressions within the actual arguments is unspecified, but there is a sequence point
before the actual call.
C++ Standard
5.2.2 Function call
The order of evaluation of arguments is unspecified. All side effects of argument expression evaluations
take effect before the function is entered. The order of evaluation of the postfix expression and the argument expression list is unspecified.
Moreover, please differentiate between ‘C-calling convention’ and the ‘order of evaluation of arguments’. These two are different.
7.) Can we call main() recursively in our C/C++ Programs?
Ans – The C standard allows you to call main() recursively. But serious programs anyhow don’t use this fundamental. It is one of the reasons why C++ does NOT allow you to call main() recursively. This is what the standard says for the exclusion of this C Compatibility:
Annex to C Compatibilty
3.6
Change: Main cannot be called recursively and cannot have its address taken
Rationale: The main function may require special actions.
Effect on original feature: Deletion of semantically well-defined feature
Difficulty of converting: Trivial: create an intermediary function such as mymain(argc, argv).
How widely used: Seldom