1

Possible Duplicate:
What does 'unsigned temp:3' mean?

What does ":" operator mean in C. The output of the program below is -1 -1 -3. How?

#include<stdio.h>
struct emp
{
    int a:1;
    int b:2;
    int c:4;
} hey;

int main()
{
    hey.a=1;
    hey.b=3;
    hey.c=13;
    printf("%d",hey.a);
    printf("%d",hey.b);
    printf("%d",hey.c);
    return 0;
}
Community
  • 1
  • 1
  • Duplicate of [this question](http://stackoverflow.com/questions/7383844/colon-operator-in-a-variable-declaration-statement-inside-struct)? – Curious Sep 23 '12 at 17:37

1 Answers1

2

The colon specifies how much bit width the field has. So a is a bit wide, b 2 bits wide and c 4 bits wide.

Lews Therin
  • 10,907
  • 4
  • 48
  • 72