Sunday, 25 February 2018

C interview question 5

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

C interview question 8

What will be the output of the given code? #include <stdio.h> int main(void) { float a = 3.14; printf("%f",a%3); ...