#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
Write program to remove duplicate in an array?
Explain how do I determine whether a character is numeric, alphabetic, and so on?
Explain how many levels deep can include files be nested?
What is 2c dna?
What are dangling pointers in c?
program to find out date after adding 31 days to a date in the month of febraury also consider the leap year
how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions
How macro execution is faster than function ?
Difference between pass by reference and pass by value?
Explain what are its uses in c programming?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What is a MAC Address?
Is array name a pointer?
What is the purpose of the statement: strcat (S2, S1)?
How can I call fortran?