Basic data types and variables in C

Source: Internet
Author: User

Data types in the C language

      1. Basic data types

1) integral type (int%d)

2) character type (char%c)

3) Float type%d

①. Single-precision float (float)

②. Double-precision floating-point type (double)

    1. 2. Pointer type void *

      3. Empty type void

    2. 4. Construction type

1) Array a[]

2) Structure struct

3) enum enum

4) Common Body Union

Note: There is no Boolean type in the C language, which means that start and pause are generally represented by 0 and 1.

Variables in the C language

(i) Definition

If the value of a data is indeterminate or often needs to be changed, it is represented by a variable.

(ii) Defining variables

Purpose: Variables must be defined before they can be used. Allocate a piece of storage space in memory to the variable to store the data later. If more than one variable is defined, multiple variables are allocated different storage spaces.

Format: Variable type + variable name;

Example: int A;char c;

Note: variable names are identifiers and require a naming convention that conforms to identifiers.

Question: Why are there many types of variables defined?

A: Different types of variables occupy a different size of storage space, because memory is extremely limited, allocating the appropriate storage space can be stored in the least space to save space.

Remember: You should define variables to save as long as you are unsure of the data. Under the 64-bit compiler, the int type occupies 4 bytes, and the total 4x8=32bit,char type is 1 bytes.

(iii) Use of variables

Initialization: There are two kinds of forms. 1.int A;a=10;2.int a=10;

Modify: You can modify the value of a variable and assign it multiple times to overwrite it.

Output: Use placeholder output variables. The various types of placeholders are as follows:

Int%d or%i

Float/double%f (output 6 bits By default, can be controlled using. 2f)

Long%ld

Long Long%lld

Char%c

String%s

Unsigned Long%zd

Basic data types and variables in C

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.