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.
Shweta said:
2 decades ago
as first variable is assigned the value in the enum (VAL1=0) , so rest variables will automatically get initialized. And the anwser is correct, because at a time the object will be having the value of a single variable (i.e. 2bytes)
Cherry said:
1 decade ago
Hi guys. Initial value i.e. val1=0, remaining enumeration constants by default incremented by 1 then. At a time it (var) contains only one enumeration constant. So that answer is 2 (in 16-bit platform).
I hope you understand.
I hope you understand.
Vijay said:
3 years ago
enum returns an integer value.
So its size is int size only.
In 16 bit computers or os => int = 2bytes. <= present problem in 16 bit platform so,output is 2 bytes.
in 32 & 64 bit computer => int = 4bytes.
So its size is int size only.
In 16 bit computers or os => int = 2bytes. <= present problem in 16 bit platform so,output is 2 bytes.
in 32 & 64 bit computer => int = 4bytes.
Sbgore said:
2 years ago
The answer is 2 because it performs operations based 16-bit compiler.
It is 4 when it should be 32-bit compiler. An enum variable typically occupies the same amount of memory as an int type.
It is 4 when it should be 32-bit compiler. An enum variable typically occupies the same amount of memory as an int type.
Chinmay said:
1 decade ago
enum values are basically integer values with restriction imposed on the range of values it can take. Since they are integer values so they shall be having size same as that of an integer.
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.
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).
Yakesh said:
1 decade ago
"sizeof () " operator returns the actual size of a data type.
For ex: sizeof (float) ; returns 4 bytes.
Here enum treated as integer data type hence returns 2bytes.
For ex: sizeof (float) ; returns 4 bytes.
Here enum treated as integer data type hence returns 2bytes.
Srividhya said:
2 decades ago
May be the first variable(VAL1=0) is initialized to zero(integer), so the total size seems to 2 bytes only. The other variables are not initialized.
Sohail said:
7 years ago
Sizeof enumeration is always sizeof int. In 16-bit compiler (ie. Turbo c/c++) it will be 2 bytes and in 32-bit compiler (ie. gcc)it will be 4 byte.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers