C-data and C-Data

Source: Internet
Author: User
Tags printable characters

C-data and C-Data

1. Constant and variable data

Some data is pre-set before the program is used and remains unchanged throughout the running process. It is called a constant. In addition, data may change or be assigned a value during the program running, which is called a variable.

2. Data Type keywords

For a variable, the compiler determines its type by declaring the data type specified in the statement. For a constant, the compiler identifies its type by writing it.

Data Type Keywords of C (12 ):

K & R keywords: int, long, short, unsigned, char, float, double.

C90 Keyword: signed, void.

C99 keywords: _ Bool, _ Complex, _ Imaginary.

3. C all basic data types

C basic data types are divided into two categories: integer and floating point. (Different storage methods are used on computers)

The default Integer type is signed, and the unsigned type can be modified to the unsigned type. The floating point type is signed and cannot be modified.

In the arrangement of space occupied by basic data types, the C language only specifies that the latter is not smaller than the former. For example, in 32-bit computers, int occupies 32 bits and short occupies 16 bits, long occupies 32, float occupies 32 places, and double occupies 64 places.

Int (default type of Integer constants)

Short = short int (modifier int, int can be omitted)

Long = long int

Long = long int

 

Unsigned = unsigned int

Unsigned short = unsigned short int

Unsigned long = unsigned long int

Unsigned long = unsigned long int

 

Char (technically, char is stored as an integer, while some machines are signed and some are unsigned)

Signed char/unsigned char (used to represent small integers)

_ Bool (stored by integer type, only two values 0, 1, false, true)

 

Float

Double (float type constant default type)

Long double

 

Void

 

Float_Complex)

Double_Complex

Long double_Complex

Float_Imaginary (Virtual number type; similar below)

Double_Imaginary

Long double_Imaginary

4. Bit, byte, word

Bit (B) is the basic unit of computer storage. It is the smallest storage unit and can only hold two values, 1 (high/low potential, two States)

Bytes (Byte, B). The standard definition is 1 Byte = 8 bit. This standard is usually used to measure the storage capacity, 1 kb = 1024B, 1 MB = 1024KB, 1 GB = 1024 MB, 1 TB = 1024 GB, 1 Pb = 1024 TB, 1 EB = Pb.

In C, the number of digits occupied by char data in the memory is one byte.

Word is a natural unit of storage for a given computer design. For a 32-bit server, one character is 32 characters. Generally, int data occupies the same number of digits in the memory.

5. Storage of integers and floating-point numbers

Integers are directly stored in the corresponding binary encoding format (the original code, anti-code, and complement are not considered ). The floating-point representation divides a number into the fractional part and the exponential part for separate storage (e-counting ). There are also signed characters.

Floating point is only an approximation of the actual value. In some arithmetic operations, floating point will lose more precision.

6. int

Variable declaration:

The declaration statement is used to create a variable, calibrate the bucket, and specify the initial value for it.

Int;

Int B;

Int a, B;

Variable assignment:

A = 10; (direct assignment)

Scanf ("% d", & B); (input function value assignment)

Int a = 10, B = 20; (initialization variable)

Constant:

C. Consider the number without the decimal point and index as an integer. C treats most integers as int type.

Prefix 0 indicates octal, 0X indicates hexadecimal, suffix U, unsigned, suffix L, long, suffix LL, long.

Print:

Printf ("% d, % o, % # o", a, B, B); the conversion specifiers must match the number and type of variables one by one.

Conversion instructions:

% [-] [Digit string [. digit string] letter

-Left alignment

The left numeric string (domain width), indicating the minimum output width. this parameter is left blank.

Right digit string (precision), indicating the number of digits retained after the decimal point. Multiple Digits are truncated, And the right digit is supplemented with zero.

 

% D to the signed decimal number output

% Hd

% Ld

% U unsigned decimal number output

% Lu

% O unsigned octal output

% #0 prefix for o display

% X unsigned hexadecimal number output

% # X Display 0x prefix

% C single character output

% S string output

% F [-] mmmm. nnnnnn (unordered floating point number) Output

% E [-] m. nnnnnn [+/-] kk (floating point number with level code) Output

% G % f or % g

% Indicates % itself

 

In scanf (), % letters can be added to the domain width and the Suppression value assignment operator *

Scanf ("% * 4 s % c", & a); first, read the four-character string with the domain width, then read a character and assign it to variable.

 

Integer Overflow:

The integer is too large to exceed the value range of the integer type, resulting in integer overflow. The C language specifies an unsigned integer overflow rule: overflow to the starting point. The overflow of signed integers is similar.

 

7. char

The actual storage of the char type is an integer. The computer uses a digital encoding and a specific number to indicate a specific character. ASCII and Unicode codes.

The C language defines a byte as the number of digits occupied by the char type.

Statement:

Char a, B;

Constant:

'A'. the writing of A single character is enclosed by single quotation marks.

Initialization:

Char a = 'a ';

Char a = 65;

In ASCII codes, 65 indicates 'A', but not all systems use ASCII codes. Therefore, we recommend that you use character constants instead of numerical codes.

For non-printable characters, C provides three methods: ASCII, escape, octal, and hexadecimal ASCII (\ 0oo octal value, \ xhhh hexadecimal value)

Note the differences between numbers and numbers.

Escape characters:

\ A alarm

\ B Return

\ F paper

\ N line feed

\ R press ENTER

\ T horizontal Tab

\ V vertical Tab

\ Backslash \

\ 'Single quota'

\ ''Double quotation marks''

\? Question mark?

\ 0oo octal value

\ Xhhh hexadecimal value

 

Print:

Char a = 'a ';

Printf ("% d, % c", );

Note: The char type is actually stored by int type. The % d Conversion specifier outputs 65, that is, the value corresponding to 'A' in the ASCII code table, and the % c Conversion character outputs 'A '.

 

8. _ Bool

The _ Bool type is essentially an integer. In C, 0 indicates false, and non-0 indicates true.

 

9. float, double, long double

Floating-point counting method: decimal, index (e-counting, 10 index)

A float usually occupies one character, and a floating point constant is of the double type by default.

Statement:

Float;

Doubel B;

Long double c;

Constant:

0.6;. 6; 6.0; 6.; 8E-5;. 8e4

There can be no decimal point or no index. The exponent part must be an integer. Suffix F, L, LL.

Print:

% F, % e

Floating Point overflow:

If the value is too large, it cannot be expressed as overflow. If the value is too small, it can be reduced to precision or overflow;

C. The floating point value that loses the type precision is called "lower than normal ".

 

10. C derived from the basic data type other types: array, pointer, struct, enumeration, union.

11. Operator sizeof (int)

The built-in operator sizeof of C provides the type size in bytes. The char type must be 1 byte, because C defines the placeholder length of the char type as one byte. (Here, 1 byte is not necessarily 8 bits)

12. automatic conversion

The integer constant defaults to int, and the floating point constant defaults to double.

In the expression, the compiler will unify the type, perform operations, and then convert the result to the left value type.

Automatic conversion generally takes a short value. Short value assignment may cause problems. For example, if a floating point value is assigned to an integer variable, it will directly cut the end and simply discard the fractional part without rounding it. If the value of double to float is lost, float can only ensure that the first six digits are accurate.

A systematic naming rule that allows a variable name to represent its type.

13. Refresh the output

The printf () function transmits the output to an intermediate storage area called the buffer zone, and the content in the buffer zone is continuously transmitted to the screen.

Standard C stipulates that in the next 3 cases, the buffer content will be transmitted to the screen: fflush () function when the buffer is full and the linefeed \ n is required.

The buffer content is passed to the screen or file called the refresh buffer.

 

Related Article

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.