#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



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

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

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

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

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

Answer / m.karthiga

3 6

Is This Answer Correct ?    19 Yes 15 No

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

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

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

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

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

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

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

Answer / sas

2 5

Is This Answer Correct ?    0 Yes 6 No

Post New Answer

More C Interview Questions

Give differences between - new and malloc() , delete and free() ?

0 Answers   Genpact,


will u give me old quesrion papers for aptitude for L & t info tech?

1 Answers   Hindustan, L&T,


Why calloc is better than malloc?

0 Answers  


What is d'n in c?

0 Answers  


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

0 Answers   Huawei,


What is the difference between calloc() and realloc()?

1 Answers  


Can you mix old-style and new-style function syntax?

0 Answers  


On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area

0 Answers  


Input any no. and print all the the numbers that comes before it like this for e.g input = 4 0 01 012 0123 01234 plz answer it 2day

3 Answers  


I have an array of 100 elements, each of which is a random integer. I want to know which of the elements: a) are multiples of 2 b) are multiples of 2 AND 5 c) have a remainder of 3 when divided by 7

1 Answers  


Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)

6 Answers   Subex,


What is a program flowchart and how does it help in writing a program?

0 Answers  


Categories