main()
{int i=5; // line 1
i=(++i)/(i++); // line 2
printf("%d",i); // line 3
} output is 2 but if we replace line 2 and line 3 by
printf("%d",i=(++i)/(i++)); then output is 1. Why?
Answer Posted / gagandeep bansal
working of incr/decr operator:first pre operators then
rest of operators then post operators
so,2 line become:i=6/(5++); /*pre operator*/
i=6/5=1; /*rest of operators*/
now post incr operator will work so,i=2; /*post operator*/
so output is 2.
in second case:i=6/(5++); /*pre operator*/
i=6/5==1; /*rest of operators*/
now post incr operator will work so,i=2;
again i=3/(2++);
i=1;
so,output is 1.
becouse in case of post operators first assign then
incr/decr.
Is This Answer Correct ? | 9 Yes | 3 No |
Post New Answer View All Answers
What is openmp in c?
What is the difference between struct and typedef struct in c?
What are the storage classes in C?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.
What is structure in c explain with example?
Can math operations be performed on a void pointer?
What is difference between union and structure in c?
Write a program to swap two numbers without using a temporary variable?
Write a factorial program using C.
What is character set?
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
What is the difference between volatile and const volatile?
What are the 5 types of organizational structures?
Why double pointer is used in c?