#include<stdio.h>
main()
{
int a=1;
int b=0;
b=++a + ++a;
printf("%d %d",a,b);
}
Answers were Sorted based on User's Feedback
Answer / banavathvishnu
let consider the statement
b = ++a + ++a;
++a will be 2
++a again will be 3
now replace its value in the expression
b = a + a = 3+3=6
hence a is 3 and b is 6
| Is This Answer Correct ? | 26 Yes | 12 No |
Answer / 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 |
Answer / ashok
initially a=1,b=0
++a=2 //1+1=2
++a=3 //2+1=3
b=2+3=5
answer:a=3 b=5
| Is This Answer Correct ? | 6 Yes | 4 No |
Answer / anand
answer should be 3 5
b = 2 + 3
b = ++a + ++a
here the compiler will work as below
b = ++a + 2
thn
b = 3 + 2
thn
b = 5
| Is This Answer Correct ? | 9 Yes | 10 No |
Answer / vijay r15
ans 3 6
Let me explain
First a=1&b=0
b=++a + ++a;
The operation will be as
b= ++1 + ++a
=2 + ++a
=2 + ++2
=2 + 3=a+a now a=3
Remember here is the trick
Now b= a + a
I.e b=3+3=6
Got it
Vijay r15
For any clarification mail to
raj.vijay55@gmail.com
| Is This Answer Correct ? | 2 Yes | 4 No |
write a program in c language that uses function to locate and return the smallest and largest integers in an array,number and their position in the array. it should also find and return the range of the numbers , that is , the difference between the largest number and the smallest.
Why doesnt this code work?
how can we use static and extern?and where can we use this?
How can I read in an object file and jump to locations in it?
multiple of 9 without useing +,* oprator
Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.
what is the difference between c and c++?
An interactive c program to read basic salary of 15 persons. each person gets 25% of basic as HRA, 15%of basic as conveyance allowances, 10%of basic as entertainment allowances.The total salary is calculated by adding basic+HRA+CA+EA.Calculate how many out of 15 get salary above 10,000.Rs also print the salary of each employee
what type of language is C?
Which of the Following is not defined in string.h? A)strspn() B)strerror() C)memchr() D)strod()
Write a c program to enter a string of paragraph and replacing a particular word which is repeated in the paragraph by another word?
2 Answers ME, Synfusion, Wipro,
How can a string be converted to a number?