-
Junior Member
C Code Snippet
[FONT='Times New Roman','serif']Which is the output produced by the following program
main()
{
int n=2;
printf("%d %d\n", ++n, n*n);
}
a) 3,6 b) 3,4 c) 2,4 d) cannot determine[/FONT]
-
Junior Member
Re: C Code Snippet
c)2,4
printf first evaluates n*n and then n++.
-
Junior Member
Re: C Code Snippet
The C language, by default, uses the CDECL calling convention, but most compilers allow the programmer to specify another convention via a specifier keyword. These keywords are not part of the ISO-ANSI C standard, so you should always check with your compiler documentation about implementation specifics.
In the CDECL calling convention the following holds:
1.Arguments are passed on the stack in Right-to-Left order.
2. The calling function cleans the stack. This allows CDECL functions to have variable-length argument lists (aka variadic functions).
In the STDCALL calling convention the following holds:
1. STDCALL passes arguments right-to-left.
2. The called function cleans the stack, unlike CDECL. This means that STDCALL doesn't allow variable-length argument lists.
There is another convention FASTCALL, This uses the arguments to be stored in registers to some extent and on to stack after that.
main()
{
int n=2;
printf("%d %d\n", ++n, n*n);
}
it is equivalent to
printf("%d %d\n", 3, 2*2);
So output is 3, 4
-
Junior Member
Re: C Code Snippet
answer is 3,4.....
coz the execution starts from right...
hence n*n is 2*2=4...
then ++n is ++2=3 ..ie..preincrement...
so getting o/p as 3,4...
-
Expert Member
Re: C Code Snippet
The answer is b option, (3,4)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules