(i) Basic data types of C language

Source: Internet
Author: User

first of all, a little bit of program development of the past (listen to Ditte Tang Teacher's class according to their own understanding of the description, just to facilitate their own understanding, not necessarily accurate): In the Assembly era, C language has not been born in the era, our programmers can only use assembly language programming, so in assembly language, There is no concept of data type, so how do we manipulate memory? The method is to use the memory's starting address, the size of the memory. And then, over time, in the process of programming, we often use memory like 4 bytes in size, 2 bytes of memory and so on. So when we need to manipulate memory every time need to know I want to operate the 2 bytes of memory size of the starting address and so on, so it is very troublesome, more error-prone. So when C was born, The concept of data types appears in the C language. This data type is the memory size we often use a name, so that we operate and use of memory more convenient, such as 4 bytes of called int,1 byte is called char ... Wait a minute.

So what is the understanding of the data type after the simple past?

1: data types can be interpreted as aliases of fixed memory sizes : int represents 1 bytes, short represents 2 bytes, char represents 1 bytes ....

2: The data type is the mold that creates the variable : equivalent to the data type as a mold to the memory, you can get the corresponding size of memory according to this data type. For example, int is the mold, you can create a 4-byte variable by "one place" in memory.

1#include <stdio.h>2 3 intMain ()4 {5   Charc =0;6    Shorts =0;7   inti =0;8 9printf"%d,%d/n",sizeof(Char),sizeof(c));Tenprintf"%d,%d/n",sizeof( Short),sizeof(s)); Oneprintf"%d,%d/n",sizeof(int),sizeof(i)); A  -   return 0;  -}

What is the nature of the variable that is created by the model of the data type?

1: The variable is an alias for the actual contiguous storage space.

2: The program uses variables to request and name the storage space.

3: The storage space can be used by the name of the variable.

4: A variable belongs to a data type.

5: The size of the memory in which the variable resides depends on the type of data that the dress belongs to.

#include <stdio.h>typedefintint32;typedef unsignedCharByte;typedefstruct_tag_ts{BYTE B1;    BYTE B2;  Shorts; INT32 i;} TS;intMain () {INT32 i32;    BYTE b;        TS TS; printf ("%d,%d\n",sizeof(INT32),sizeof(I32)); printf ("%d,%d\n",sizeof(BYTE),sizeof(b)); printf ("%d,%d\n",sizeof(TS),sizeof(TS)); return 0;}

(i) Basic data types of 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.