#include<stdio.h>
main()
{
int a=1;
int b=0;
b=++a + ++a;
printf("%d %d",a,b);
}

Answer Posted / aditya gupta

Let me make this more clear... infact if the case is of
pre-increment:

1- find all the variables of pre-increment, and compute them
2- do the assignment.

for example, what I do:
main()
{
int a=1; // initialization
int b=0; // initialization

b=++a + ++a; // find the pre-increment i.e. 2 increments of
'a' so now 'a' in this step will be incremented by 2 so now
'a' will contain 1+2=3. so now a=3. Again before assignment
compute 'a+a' which is '3+3'=6

printf("%d %d",a,b); //3 6

}

Just a trick:- always compute the pre-increments in the same
step...

If I say b= ++a + ++a; answer is 3 and 6
If I say b= ++a + a++; answer is 3 and 4 because in this
line one pre-increment is there. So now '++a + a++'= "2 + 2"



Thanks!!
Aditya Gupta

Is This Answer Correct ?    8 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is c pass by value or reference?

595


What does %2f mean in c?

674


how to execute a program using if else condition and the output should enter number and the number is odd only...

1654


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

807


What is printf () in c?

578






what is use of malloc and calloc?

1382


Which is more efficient, a switch statement or an if else chain?

583


Does free set pointer to null?

563


Linked lists -- can you tell me how to check whether a linked list is circular?

646


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

588


What is volatile c?

524


What should malloc(0) do? Return a null pointer or a pointer to 0 bytes?

586


Why c is called a mid level programming language?

605


What do you mean by Recursion Function?

629


Tell me the use of bit field in c language?

629