Find the output for the following code
My question is
Find the output for the following code
void main()
{
int i=7;
printf("%d",i++*i++);
}
Advance Thanks,
R.Rengaraj
{Java Certification Quiz}
{On this forum my 20th Question.}
Member • Dec 11, 2009
Member • Dec 11, 2009
Member • Dec 11, 2009
void main() { int i=7; printf("%d \n",i++*i++); printf("%d",i); }will give the output as:
56
9
Member • Dec 11, 2009
Member • Dec 11, 2009
Dear sarveshgupta,sarveshguptai++ means using post increment that is when we use it in any expression it uses the current value of that variable that is being carried forward from previous statement and then increment after compiler reads it so that any next time compiler reads the variable again it will read the incremented value
now we are doing i++ * i++ this implies
first time the value read is 7 which was the initial value of i and it gets incremented so for next operand i++ it takes the value 8 and after using 8 it increments it to 9
since we are using them only till here we get the value as 7*8 =56
if we try to print the value of i at the end of the program it will be 9
void main() { int i=7; printf("%d \n",i++*i++); printf("%d",i); }will give the output as:
Member • Dec 12, 2009
Good Point. In fact printf statement handles execution from right to left (in C).rengarajDear sarveshgupta,
Your answer is right, but you stated as 7*8 why i can be 8*7,
bcoz, if execution is being handled from right to left.
R.Rengaraj
Member • Dec 12, 2009
Member • Dec 12, 2009
Member • Dec 12, 2009
Member • Dec 12, 2009