Vote Up 0 Vote Down

different output c and java program

what is the output of this c and java in same code/programs...and why,output is different.?

// c program
‪#‎include‬<stdio.h>
void main()
{
int i=2;
printf("%d %d",++i,i++ );
getch();
}
//java program
class Increament
{
p s v m(String[] arg)
{
int i=2;
println(++i +""+ i++);
}
}
flag

Answers


Vote Up 0 Vote Down
in Java - the value of i will be incremented by ++i as it is an pre-increment statement and value of i will become 3 then for post increment statement the value of i will be changed in the memory but it will use the same value as 3 so the output will be 3 3 ... note - after execution of program the value of i will be 4
flag | link |
Vote Up 0 Vote Down
The idea is that ++a increments a and returns that value, while a++ returns a's value and then increments a.
flag | link |
Vote Up 0 Vote Down
-in c compiler compiles the following statement
//printf("%d %d",++i,i++);
from right to left therefore c o/p defferent from java...
flag | link |

Your Answer

Login before answering

Login with facebook