Length of data type in C language

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.