+ 5

Structure in c

The output is 11, could you explain why? #include <stdio.h> struct xyz{ int a; }; int main() { struct xyz obj1={1}; struct xyz obj2=obj1; printf("%d", obj2.a); obj2.a=100; printf("%d", obj1.a ); return 0; }

13th Jan 2019, 7:47 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
2 Respostas
+ 9
obj1={1}; //the a int for obj1 is 1 so a=1 //Then obj2=obj1; //obj2 is also 1 printf("%d",obj2.a); //print 1 ....... printf("%d",obj1.a); /*print 1 so the global output is 11 if you add "\n" to the first print statement you get an output of: 1 1 /*
13th Jan 2019, 9:30 AM
Uni
Uni - avatar
0
Hey ans??
13th Sep 2021, 5:16 AM
Prudhvitha Reddy
Prudhvitha Reddy - avatar