What will the output of the given code?
#include<stdio.h>
void main ()
{
int a=3;
a = ++a + ++a;
printf ("a=%d",a);
}
Ans:10
Reason:
Here pre-increment operator is used so the value of a is increased to 4 again another pre-increment operator which increases the value of a to 5 , then the value of a is added and assigned to a .
a = ++a + ++a;
a=3
++a=4
++a=5
a = 5 + 5;
a = 10;
No comments:
Post a Comment