Assume any value of k eg 1
Q1 d=k++/++k……..print d and k, k=3;
why is the reult 1 for d???
Q2 d=printf(“%d%d%d”,++k,k,k++);
printf(“%d%d%d”,k++,k,k++);
Why the result vary in both the printf statements.???
Q3 printf(“%d%d%d”,k,k++,++k);
what will be the output and WHY???
Q4 printf(“%d%d%d”,++k,k++,k);
output and WHY??
Q5 printf(“%d%d%d”,k++,++k,k);
output and WHY??
before i give u solution,i will tell you how a post and preincrement work.
1.the operation is start from right to left and printing the value from left to right.
2.In preincrement first the value is increment then operation is performed and In postincrement first operation is performed then increment.
3.In postincrement the value is print after the operation is performed but in preincrement the value is print after all the operation is performed and print value from left to right.
qns1.assume the value of k is 1.
d=k++/++k;
it means first value of k is 2 through ++k and now the value of k is 2,so d=2/2=1.
other problem u can solve easily through this rule…
Why are u executing ++k(denominator) 1st???
don’t look it as denominator or numerator..
it is just an expression in c in which the priority of pre-increment is higher than that of post increment….
but if we go accoring to precedence table the priority of k++ is higher than ++k
hahaha……….its not possible to get the right answer at one go