C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 10)
10.
Point out the error in the program?
#include<stdio.h>

int main()
{
    struct bits
    {
        float f:2;
    }bit;

    printf("%d\n", sizeof(bit));
    return 0;
}
4
2
Error: cannot set bit field for float
Error: Invalid member access in structure
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Avinash said:   1 decade ago
A bit field can only be defined of an int or unsigned integer but some compilers also permitted for char and long word.
(1)

Maheshkumar said:   2 decades ago
answer is in the option itself i.e bitfields will not set for float datatype

Sachin kakatkar said:   1 decade ago
bit field variable must be only signed or unsigned int type.

Karthi said:   1 decade ago
May I know why can't apply flag for float ?

Parth said:   1 decade ago
Can anyone say that why we can't allow bit to float. I mean any.

Restriction for that?

Post your comments here:

Your comments will be displayed after verification.