C language learning - data

C language data type keywords

 

int

long

short

unsigned

char

float

double

signed

void

_Bool

_Complex

_Imaginary

In the C language, use the keyword int to represent the basic integer types. long, short, unsigned, signed four keywords for providing a substantially integral type variant.

char keyword is used to specify the designated letters and other characters, in addition also represent smaller integer.

float, double, long double the number of representatives with a decimal point.

_Bool type indicates a Boolean value (true or false).

_Complex and _Imaginary denote complex numbers and imaginary numbers.

 

And data type size range

Types of

Storage size

Value range

char

1 byte

-128 to 127 or 0 to 255

unsigned char

1 byte

0 to 255

signed char

1 byte

-128 to 127

int

2 or 4 bytes

-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647

unsigned int

2 or 4 bytes

65,535 to 0 or 0 to 4,294,967,295

short

2 bytes

-32,768 to 32,767

unsigned short

2 bytes

0 to 65,535

long

4 bytes

-2,147,483,648 to 2,147,483,647

unsigned long

4 bytes

0 to 4,294,967,295

 

In printf () and scanf () format conversion specifier:

Conversion Description

Export

%a

Floating-point number, hexadecimal number notation and p- (the C99)

%A

Floating-point number, hexadecimal numbers and P- notation (C99)

%c

A character

%d

Signed decimal integer

%e

Floating-point number, e- notation

%E

Float, E- notation

%f

Float, decimal notation

%g

Different automatic selection or% f% e depending on the value. % E format index is less than -4 or greater than or equal accuracy when using

%G

Different automatic selection or% E% f depending on the value. % E format index is less than -4 or greater than or equal accuracy when using

%i

Signed decimal integer (the same as% d)

%The

Unsigned octal integer

%p

Pointer (refers to the address)

%s

String

in%

Unsigned decimal integer

%x

Hexadecimal number 0f unsigned hexadecimal integer

%X

Hexadecimal number 0F unsigned hexadecimal integer

%%

Print a percent sign

  • Declare an int
1 int ears;
2 int hog,cow,goats;

 

  • Initialize variables
 
1 int ears = 21;
2 int hog =1,cow 5,goats =31;

 

 

In short, declared as variables are created and marked storage space and assign initial values.

  • Other forms

Short(int)

Long(int)

Long long(int)

Unsigned(int)

Unsigned long(int)

Unsigned long long(int)

  • Declaration of type char

char type variable declaration the same way as other types of

1 char response;
2 char itable,latan;

 

  • Character constants and initialization
char grade 'A'

 

C-language, single character enclosed in single quotes is called a character constant. Found a compiler 'A' will be converted to the corresponding code values. Single quotes are essential.

In fact, the characters are stored in the form of a numerical value, it is also possible to use instead of the character values ​​assigned:

char grade = 65

 

  • Non-printing characters

Single quote only applies to characters, numbers, and punctuation. Some characters do not print, c language provides three methods:

  • Use ASCII code
char beep = 7

 

  • Using a special symbol sequence (escape sequence)
char nerf = ‘\n’;

 

Escape Sequences

Show

\a

Remind / (alarm)

\b

backspace

\f

Feed

\n

Wrap

\r

Enter

\t

Horizontal tab

\ v

Vertical tab

\'

apostrophe

\ "

Double quotes

\\

Backslash

\?

Text question mark

\ ooo

ASCII characters in octal notation

\x hh

ASCII characters in hexadecimal notation

  • Use hexadecimal representation character constant, backslash behind with a x or X, plus 1 to 3 hex digits
  • _Bool type

c language, with 0 representing true with 1 flase

  • float,double和long double

Floating constant consists of an integer part, a decimal point, a fractional part and exponent part. You can use decimal floating point or exponential notation to represent constants.

When expressed using decimal, integer part must contain, fractional part, or both. When expressed using the exponential form, it must contain a decimal point, index, or both. Unsigned exponent e or E is introduced.

Here are several examples of floating constants:

3.14159       /* 合法的 */
314159E-5L    /* 合法的 */
510E          /* 非法的:不完整的指数 */
210f          /* 非法的:没有小数或指数 */
.e55          /* 非法的:缺少整数或分数 */

 

计算 int, float, double 和 char 字节大小

 1 {
 2 int a;
 3 long b;
 4 long long c;
 5  
 6 double e;
 7 long double f;
 8  
 9  
10 printf("Size of int = %ld bytes \n", sizeof(a));
11 printf("Size of long = %ld bytes\n", sizeof(b));
12 printf("Size of long long = %ld bytes\n", sizeof(c));
13  
14 printf("Size of double = %ld bytes\n", sizeof(e));
15 printf("Size of long double = %ld bytes\n", sizeof(f));
16  
17 return 0;
18 }

 

 

结果

 

Size of int = 4 bytes
Size of long = 8 bytes
Size of long long = 8 bytes
Size of double = 8 bytes
Size of long double = 16 bytes

 

Guess you like

Origin www.cnblogs.com/liuyubo/p/11730201.html