3. Data type, operator and expression of C language

Source: Internet
Author: User
Tags arithmetic operators

C-language data types, operators, and expressions

1. Data type of C

    

The data type determines:

(1) Number of bytes of data in memory

(2) Data value range

(3) operations that can be performed

2. Constants and variables

Constants and symbolic constants

The amount of value that cannot be changed during a program's operation is called a constant

Constant zones are divided into different types:

Integral type 100, 125,-1000

Real: 3.14, 0.23

Character type: ' A ', ' B '

String type: "A", "ADFDG", "1233"

Use a symbol to represent a constant, which is called a symbolic constant.

#define Price 30//price is a symbolic constant

Variable:

Definition: The amount whose value can be changed

Definition Format: Data type variable name;

The variable should have a name and occupy a certain storage unit in memory

Variable name barrier variable value has different meanings

Variable Mingshi to a symbolic address

Identifier:

Definition: A string sequence that identifies a variable name, a symbolic constant name, a function name, an array name, a file name-----a name

Naming rules:

Can only consist of letters, numbers, underscores, and the first character must be a letter or an underscore

Case sensitivity

Cannot use keywords

Use: Define first, then use

3. Integral type Data

Three ways to represent integer constants

Decimal integer: Represented by a number 0~0 and a positive sign.

such as: 123,-234,0

Octal integers: Starting with the number 0 followed by a number 1~7 representation

such as: 0123,0112

Hexadecimal integer: Starting with 0x, followed by a 0~9,a~f,a~f representation

such as: 0x123,0xff

Supplemental knowledge: The way data is stored in memory

Memory to be directly composed of cells

A byte is usually made up of 8 bits

The value for each bits is 0 or 1

4. Floating-point data

How to represent floating-point constants

(1) Decimals: 0.123

(2) Index 3e-3

In your computer, use exponential to represent floating-point data

Note that there must be a number before the letter e, and the exponent after E must be an integer

Eg:1e-3

123.456 normalized exponential representation of 1.23456e3

5. Character type data

Character constants

Definition: Single character or escape character enclosed in single quotation marks

such as: ' A ' a ' \ n ' \ t '

The value of the character constant: the ASCII code value

such as: ' A '---' a '---65

Definition Format: Char variable name = value

char ch = 65; with char ch = ' A '; is equivalent to

      

Escape character: A backslash followed by a character or a code value represents

Character variables:

Stores a character constant, takes one byte, and holds a char

Definition form:

Char Ch1,ch2;

Assignment value:

CH1 = ' a '; CH2 = ' B ';

How to store character data in memory and how to use it

ASCII code value (0~255) that holds the character in binary

Similar to the storage of integers

Output as a character or integer

printf ("%c", ch1);//output in character form

printf ("%d", ch1);//output in digital form

String constants

A string constant is a sequence of characters enclosed in double quotation marks

Valid string constants:

"How does you do." "," China "," a "

You can output a string, such as

printf ("How Does");

   Attention:

You cannot assign a string constant to a character variable

There is no string variable in the C language, only a character array is used to hold the string.

C rule: Add a "string End flag" at the end of each string constant so that the system can determine whether the string ends.

c specifies that the character ' + ' is used as the end-of-string flag

6. Variable assignment initial value

Use of variables: Define first, then use

Position of variable definition: usually at the beginning of a function

Variable initialization: The initial value can be assigned at the time of definition and can be used before

Remember that when used, variables are undefined and uninitialized.

Conversion of data types: implicit conversions, displaying transformations

7. Arithmetic operators and expression expressions

    

3. Data type, operator and expression 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.