C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 4)
4.
What will be the output of the program in 16 bit platform (Turbo C under DOS) ?
#include<stdio.h>
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
Answer: Option
Explanation:
Since C is a compiler dependent language, in Turbo C (DOS) the output will be 2, but in GCC (Linux) the output will be 4.
Discussion:
38 comments Page 3 of 4.
Chandana said:
8 years ago
Then the answer to given question should be 9 but it is given 2 why?
The amd size of the function returns the number of bytes and it is in bits.
The amd size of the function returns the number of bytes and it is in bits.
Prakash said:
7 years ago
Actually, this is a bit field program in that, the bit field only accepts the int and char member not a float that's wise giving an error.
Raka said:
1 decade ago
@Ashu piyush is right
for int 2 byte memory allocated in the 16 bit cmopiler
for int 4 byte momory allocated in the 32 bit compiler
for int 2 byte memory allocated in the 16 bit cmopiler
for int 4 byte momory allocated in the 32 bit compiler
MAHESH said:
1 decade ago
9 bytes =>1 bit (8 bytes) +1 byte. But by padding it gives 2 bits since single bytes can't be printed.
Strr said:
1 decade ago
When 2 bytes are enough for storing 9 bits. Why GCC takes 4 bytes ? what is the logic behind 4 bytes ?
Sneha said:
1 decade ago
Bitfielda can only have int, unsigned int, signed int as their data type and not float.
Hari said:
2 decades ago
In windows base complier the answer is C (i.e. 4)
Sridevi explanation is correct
Sridevi explanation is correct
Dhruv said:
5 years ago
Total 4+4+1 = 9 bits (not bytes).
1 byte = 8 bits.
So the answer is 2 bytes.
1 byte = 8 bits.
So the answer is 2 bytes.
(4)
Niks said:
8 years ago
4 also the correct answer because as mentioned it depends on the compiler.
Rajen said:
2 decades ago
Bit is a structure of int type and it's sizeof(int_var) returns 2.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers