2012-09-23 64 views
1

可能重複:
What does 'unsigned temp:3' mean?:操作員用C

什麼 「:」 操作者在C.意味着下面的程序的輸出是-1 -1 -3。怎麼樣?

#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; 
} 
+0

重複的[這個問題](http://stackoverflow.com/questions/7383844/colon-operator-in-a-variable-declaration-statement-inside-struct)? – Curious

回答

2

冒號指定該字段有多少位寬。 所以a有點寬,b 2位寬,c 4位寬。