In the interview, the int length in C is often asked, the following summarizes as the information:
First look at the general rules:
Standard C specifies that the int length is equal to the machine word size, Short's representation range cannot be greater than the representation range of int, and long cannot be less than the representation range of Int. On the 32 platform (the so-called 32-bit platform refers to the universal register data width is 32) write code, short is generally 16 bits, and long and int is 32 bits. On 16-bit platforms, int and short are generally 16 bits, while long is 32 bits.
The following code is actually tested:
#include <stdio.h>#include<stdlib.h>intMain () {printf ("len int =%d\n",sizeof(int)); printf ("len short =%d\n",sizeof( Short)); printf ("len long =%d\n",sizeof(Long)); printf ("len Long long =%d\n",sizeof(Long Long)); printf ("len float =%d\n",sizeof(float)); printf ("len double =%d\n",sizeof(Double)); Char*a="Test"; CharB[] ="Test"; printf ("len *a =%d\n",sizeof(a)); printf ("len b[] =%d\n",sizeof(b)); typedefstructnode{intvalue; structnode*Next; }node; Node node; printf ("len struct Node =%d\n",sizeof(node));}
The output is as follows:
Lenint=4Len Short=2LenLong=4LenLong Long=8Lenfloat=4LenDouble=8Len*a =4Len B[]=5LenstructNode =8
Used to think that the C inside int is 16 bits, it seems that the machine is now 32 bits.
Length of data type in C language