#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
Explain what does it mean when a pointer is used in an if statement?
Differentiate fundamental data types and derived data types in C.
Which built-in library function can be used to match a patter from the string?
write a proram to reverse the string using switch case?
What is the difference between exit() and _exit() function in c?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
What is keyword with example?
What does %p mean?
How do you print an address?
to find the closest pair
What is the main difference between calloc () and malloc ()?
What are the similarities between c and c++?
Write a program to print all permutations of a given string.
What is C language ?