I have a question in an interview for which I had to find a way out of the following code. I tried, but it was wrong. Please explain the following code.
#include<stdio.h>
int main()
{
int x=0,a;
while(x++ < 5)
{
a=x;
printf("a = %d \n",a);
static int x=3;
printf("x = %d \n",x);
x+=2;
}
return 0;
}
Output:
a = 1
x = 3
a = 2
x = 5
a = 3
x = 7
a = 4
x = 9
a = 5
x = 11
Can someone explain what is going on here?
user4415235
source
share