Try this before running!

2 views
Skip to first unread message

TheSuyog

unread,
Feb 4, 2011, 9:32:41 AM2/4/11
to Knowledge Test
Try this code, valid/invalid and output:

#define Print(Exp) printf(#Exp" = %d", Exp)

void main()
{
int x = 3, y = 4;
Print(x/y);
}

&

void main()
{
int Arr[] = {1, 2, 3, 4, 5};
printf("%d", 2[Arr]);
}

Taken from some campus exam questions, so try to answer before you
execute.

Neha

unread,
Feb 28, 2011, 1:04:39 PM2/28/11
to Knowledge Test

output of
void main()
{
       int Arr[]  = {1, 2, 3, 4, 5};
       printf("%d", 2[Arr]);

}

it will print the element with index 2 of the array i.e. 3..
This is so because 2[Arr] is equivalent to *(2+Arr) i.e adding 2 to
the base address of array Arr and then calculating the value at that
address.

and please give me the solution of 1st question....

TheSuyog

unread,
Mar 2, 2011, 4:00:49 AM3/2/11
to Knowledge Test
@Neha: thanx for the explanation! I never guessed it worked like
this....

But how does define directive evaluate?? Anyone?
Reply all
Reply to author
Forward
0 new messages