04-c language data types, constants, variables

Source: Internet
Author: User

One, data 1. What is Data

Life is always with the data, such as weight data, blood pressure data, stock price data and so on. In our use of computer process, will be exposed to a variety of data, there are document data, image data, video data, as well as chat QQ generated text data, with thunder download file data.

2. Classification of data

The data stored in the computer can be divided into two types: static data and Dynamic Data.

1> static data

L Concept: Static data refers to some permanent data that is generally stored on the hard disk. Hard disk storage space is generally relatively large, now ordinary computer hard disk has about 500G, so the hard disk can be stored in some relatively large files.

L Storage Duration: After the computer shuts down, the data is still in, as long as you do not actively delete or the hard drive is not bad, the data is always in.

What is static data: Static data is usually stored on the hard disk in the form of files, such as documents, photos, videos, etc.

2> Dynamic Data (temporary data)

L Concept: Dynamic Data refers to the temporary data that is generated dynamically during the process of running the program, which is generally stored in memory. Memory storage space is generally relatively small, now the average computer memory only about 4 G, so be careful to use memory, do not occupy too much memory space.

Storage Duration: After the computer shuts down, the temporary data will be erased.

What is Dynamic Data: When a program (software) is run, the entire program is loaded into memory, and during the run of the program, a variety of temporary data is generated that is stored in memory. When the program stops running or the computer is forced to shut down, all temporary data generated by the program will be erased.

You might ask, why not load all the applications into the hard drive, since the storage space is so large? One of the main reasons is that the memory accesses faster than the hard disk n times.

What data does the programmer care about the most?

3> conversion of static and dynamic Data

Static--Dynamic

dynamic-Static

3. Size of the data

1) both static and dynamic data are composed of 0 and 1. How do 0 and 1 make so much data?

2) data are size, static data will occupy the space of the hard disk, dynamic Data occupies memory space

3) The larger the data, the more the 0 and 1 are included, bits and bytes

4) 1 KB = b,1 MB = 1024x768 kb,1 GB = 1024x768 mb,1 TB = 1024x768 GB

4. Various data in the app

5. Data types in the C language

Because of the wide variety of data in the app, C-language data is classified to facilitate the operation of data.

Two, constant 1. What is a constant

Constant, which represents some fixed data

2. Classification of constants

1> integral type constant (int)

Includes all integers, such as 6, 27, 109, 256, 10, 0, 289, etc.

2> floating-point constant (float\double)

Floating-point constants are divided into double and float two data types

U double: double-precision floating point, in fact, is a decimal. such as 5.43, 2.3, 0.0 and so on (note that 0.0 is also a decimal)

U float: single-precision floating-point type, also a decimal, is less accurate than a double, meaning that it can represent a smaller number of decimal places. To differentiate from double, the float type data is terminated with F, such as 5.43f, -2.3f, 0.0f. It should be noted that there is absolutely no 10f in this format, the compiler will directly error, only decimals allowed to add F.

3> character constant (char)

You enclose a number (0~9), English letter (A~z, a~z), or other symbol (+ 、-、!、?, and so on) in single quotation marks, which makes up a character constant. such as ' 6 ', ' A ', ' F ', ' + ', ' $ ' and so on.

Note: The single quotation mark can only enclose 1 characters, and cannot be Chinese characters, the following wording is wrong: ' abc ', ' 123456 ', ' Male '

4> string Constants

U enclose one or more characters in double quotation marks (""), which makes up a string constant. such as "6", "Male", "wow haha", "ABCD", "MY_CAR4", in fact printf ("Hello World"); the statement "Hello World" is a string constant.

What is the difference between 6, ' 6 ' and ' 6 ' in usage? This is not to be discussed and will be introduced later.

Third, the variable 1. What is a variable

When the value of a data needs to change or be uncertain, it should be represented by a variable. such as game points.

2. Defining variables

1> Purpose

You must define any variable before it is used.

The purpose of defining variables is to allocate a chunk of memory to the variable to store the data later.

If you define more than one variable, you allocate different storage space for each variable.

2> format

Variable type variable name;

such as int num;

L variable name belongs to identifier

L Variable Type

U different types of variables occupy different sizes of storage space. Memory is extremely limited, allocating the appropriate storage space

The type of data stored by the U constraint variable (convenient operation)

3> instances

int main ()

{

int i;

char c;

int A, B;

return 0;

}

3. Use of variables

1> Assignment Value

L put something in the variable, it's assignment. With a semicolon after the assignment statement;

i = 10;

Note: The equals sign here is not "equal" in mathematics, but rather the assignment operator in C, which assigns the right constant 10 to the left variable i

L first assignment, which can be called "Initialize"

L Two types of initialization

U define first, then initialize: int A; A = 10;

The U-definition is initialized at the same time: int a = 10;

2> modification

L can modify the value of a variable and assign it multiple times. Each assignment will overwrite the original value

i = 10;

i = 20;

The last value of the variable i is 20

L use printf to output the value of one \ Multiple variables

int a = ten, c = 11;

printf ("a=%d, c=%d", A, c);

L Double\float\char output, some tips for formatting characters

Double height = 1.55;

char blood = ' A ';

printf ("height=%.2f, blood type is%c", height, blood);

L Simple Add-subtract operation

int a = 10 + 20;

Do not use when not initialized (the following wording is not recommended)

int score;

printf ("score=%d", score);

Transfer of values between 3> variables

L can assign the value of a variable to another variable

int a = 10;

int b = A;

L Continuous Assignment

A = b = 10;

4. Common errors

1> variable name is the same as int a = 10; int a = 12;

The scope of the 2> variable is not correct

Creation and release process of U variables

U code block scope {int a = 10;}

04-c language data types, constants, variables

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.