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;
}
1
2
4
10
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
50 comments Page 3 of 5.

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.

Keerthana said:   7 years ago
Enum is an integer by default. So size will be 2bytes.

Hence the output:2.

Manisha said:   5 years ago
No, the right Answer should be 4.

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.

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.

Swe said:   1 decade ago
Thanks sundar.

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.

Runa said:   2 decades ago
Since val1 is assigned as 0 since its a int I nthink the sizeof usage gives us 2 bytes as answer.

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)

Sundar said:   1 decade ago
Hi Guys,

If we run this program in DOS (compiled with Turbo C), it will show the output as 2. Because it is a 16-bit platform. If you compile in a 32-bit platform like Linux (compiled with GCC compiler), it will show 4 as the output.

The online compiler given in this websites is a 32 bit (Linux) platform. Show it will show the output as 4.

Hope you understand better. Have a nice day.!


Post your comments here:

Your comments will be displayed after verification.