C Programming - Const - Discussion
Discussion Forum : Const - Find Output of Program (Q.No. 2)
2.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>
union employee
{
char name[15];
int age;
float salary;
};
const union employee e1;
int main()
{
strcpy(e1.name, "K");
printf("%s %d %f", e1.name, e1.age, e1.salary);
return 0;
}
Answer: Option
Explanation:
The output will be (in 16-bit platform DOS):
K 75 0.000000
Discussion:
28 comments Page 2 of 3.
Deepak said:
1 decade ago
char is of 1 byte.
So char name[15] will take 15 byte.
So this is the max.
So it should allocate 15 bytes.
So char name[15] will take 15 byte.
So this is the max.
So it should allocate 15 bytes.
Akshit said:
1 decade ago
The answer is correct (D). The explanation made by Pavel is Correct. Checked it out with my compiler.
Varunrao.rao@gmail.com said:
9 years ago
Here string copy function is used. It updates the union using reference.
So, no error is correct.
So, no error is correct.
Sona said:
1 decade ago
I think ascii value don't take the float value, so float value is 0.000000.
Maheep Sharma said:
1 decade ago
Why float is not sharing the same memory and not outputting as 75.000000 ?
Subhchintak said:
1 decade ago
Why has const variable not been defined at the time of declaration.
Avi said:
1 decade ago
How strcpy is being used to store values in a constant variable ?
Avi said:
1 decade ago
Can we initialize more than one member of union at a time?
Div said:
1 decade ago
I would also like to know how e1.age gets the value 75 ?
Archana said:
1 decade ago
Can anyone explain why float doesn't take 75. 000000?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers