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


Please Help Members By Posting Answers For Below Questions

What is openmp in c?

612


What is the difference between struct and typedef struct in c?

657


What are the storage classes in C?

625


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

2188


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.

1592






What is structure in c explain with example?

638


Can math operations be performed on a void pointer?

587


What is difference between union and structure in c?

578


Write a program to swap two numbers without using a temporary variable?

611


Write a factorial program using C.

643


What is character set?

685


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

644


What is the difference between volatile and const volatile?

565


What are the 5 types of organizational structures?

550


Why double pointer is used in c?

567