reopened by
1,411 views
0 votes
0 votes
It is not any gate question but just my doubt over the topic C programming?

Ques:- What will be the output of the following program?

void main(){

      int a=0,x=0;

      a = 10;

      x = ++a + ++a + ++a;

      printf("Value of X = %d and Value of A = %d",x,a);

}

 

What will be the output of the above program?

Please give explanation also for your answer.

(Please tell what was your approach in this answer)
reopened by

1 Answer

1 votes
1 votes
here a is initialized to 0 and x is initialised to 0.

in the next line value of a becomes 10,

x=++a + ++a + ++a

there will be many answers depends upon order of evaluations so output of program is undefined.

for example one of the answer will be x=36 and a=13 when we go from right to left

when we evaluate the expression after computing final value of a then x=39 and a=13

there might be other answers too so output is undefined

Related questions

0 votes
0 votes
2 answers
1
1 votes
1 votes
1 answer
2
Prajwal Bhat asked Aug 19, 2016
1,116 views
#include<stdio.h>int main(){int a = 10, b = 20, c = 30, d = 40;printf("%d%d%d",a, b, c);printf("%d%d%d", d);return 0;}What is the Output and when I run it I am getting so...
0 votes
0 votes
1 answer
3
Rohit Gupta 8 asked Nov 8, 2017
7,131 views
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?C = 100 for(i=0; i<n; i++) for (j=0; j<n; j++) { Temp = A[i][j] + C A[...
0 votes
0 votes
1 answer
4
Ankush Tiwari asked Aug 20, 2016
473 views
#include<stdio.h int main() { char *p1="xyz"; char *p2="xyz"; if(p1==p2) printf("equal"); else printf("unequal"); }Output is equal how??? please explain