C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 7)
7.
Point out the error in the program in 16-bit platform?
#include<stdio.h>
int main()
{
struct bits
{
int i:40;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
Discussion:
19 comments Page 1 of 2.
Harshith M L said:
1 decade ago
The width of int is 4 bytes (32 bits) or 2 bytes (16 bits) depending upon the machine, so the allocation for int is upto 32 bits. The declaration int i:40; exceeds the width of int so the compiler generates the error:width of 'i' exceeds its type.
Vimal said:
1 decade ago
What is meant by "i:40"?
Kamal said:
1 decade ago
'i:40' it means allocating the bit size for i.
Ram said:
1 decade ago
int i:40;
What does it mean the above statement?
What does it mean the above statement?
Vikram said:
1 decade ago
It means 'i' can store an integer which contains 40 bits in it.
Generally integer size can be either 16 bits in a 16 bit machine or 32 bits in a 32 bit machine.
But here, we are trying to store 40 bits for integer which is wrong and so compiler generates error.
Generally integer size can be either 16 bits in a 16 bit machine or 32 bits in a 32 bit machine.
But here, we are trying to store 40 bits for integer which is wrong and so compiler generates error.
Chanders said:
1 decade ago
Yes, you are apsolutely correct.
Deepak said:
1 decade ago
If we assign like int i:30;
Is it right or wrong ?
Is it right or wrong ?
Santosh said:
1 decade ago
I:30 is right and it will give output 4 in 32-bit OS.
Maheshwar Prasad said:
1 decade ago
Size is large so can't accept this "i:40" because int 32 accept 32-bit value.
FlameNfire said:
1 decade ago
When we write "int i=40" the compiler does it "int i=0; i=40;" (compiler does it in 2 steps) ,
When we write "int i:40" the compiler just declare an integer and assign 40 to it, which saves time.
When we write "int i:40" the compiler just declare an integer and assign 40 to it, which saves time.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers