C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 13)
13.
What will be the output of the program given below in 16-bit platform ?
#include<stdio.h>
int main()
{
enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var;
printf("%d\n", sizeof(var));
return 0;
}
Discussion:
50 comments Page 2 of 5.
Sundar said:
1 decade ago
@Janak
It will display a junk/garbage value (the value stored by other programs previously in that memory location reserved for the variable in the current program).
It will display a junk/garbage value (the value stored by other programs previously in that memory location reserved for the variable in the current program).
Kunal said:
1 decade ago
In borland c++ compiler ans is also 4...i run the program...
Lovely said:
1 decade ago
Thanks sundar. Thank you very much.
Swe said:
1 decade ago
Thanks sundar.
Sridhar said:
1 decade ago
As it is an int type it gives 2 as answer.
Satyaprakash said:
1 decade ago
Thanks to rohit.
Pallavi said:
1 decade ago
In C enum is internally treated as Integer.Hence size of enum will be size of an integer (ie)2 bytes(visual C or turbo C) or 4 bytes(GCC compiler Linux) depending upon the compiler.
Kiru said:
1 decade ago
Enum is keyword to define named integer constants in 16-bit compiler. The integer value take 2bytes to store the value and for GCC 4 bytes to store it. The variable can store only integer value you can answer. And if you want to initialize, initialize at part of declaration at any cost.
Ramakant said:
1 decade ago
@Pallavi
But there are 5 integer (VAL1=0, VAL2, VAL3, VAL4, VAL5)
So sizeof(var) will be 10 byte........
Please explain me?
But there are 5 integer (VAL1=0, VAL2, VAL3, VAL4, VAL5)
So sizeof(var) will be 10 byte........
Please explain me?
Girija said:
1 decade ago
@ Ramakant
there is no issue of how many variable/elements are in enum.
so that Pallavi is right.
thanks Pallavi
there is no issue of how many variable/elements are in enum.
so that Pallavi is right.
thanks Pallavi
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers