Data types of C language study notes

Among the C language types, common ones are: int, short, long, char, float, double, etc.

Data Common Types Classification Table
type of data Occupied bytes printf function format scanf function format Replenish

int

(integer)

4

printf("%d\n",a)

%d signed decimal print

%u unsigned decimal print

%o unsigned octal print

%x lowercase hexadecimal printing 

      ( 0xbb)

%X uppercase hexadecimal printing

     (0xBB)

scanf("%d",&a) int, short, and long are all integer types, but the data length must follow: short<int<long

short

(short integer)

2 printf("%hd",b); scanf("%hd",b); ditto

long

(long integer)

4

(under window)

printf("%ld",c); scanf("%ld",c); ditto

char

(character)

1

char d='D'

char ch="abc"(string)

printf("%d",d) is to print the corresponding ASCLL code value

printf("%c",d) is to print the corresponding string

scanf("%c",d);

ASCLL code value of null character = 32

Then: lowercase to uppercase

printf("%c",'a'-' ')

uppercase to lowercase

printf("%c",'A'+' ')

Common ASCLL code values:

0->48

A->65

a->97

float

(single precision floating point)

4

Assignment method:

float a=3.14f;

or a=3.2e3f(3.2*1000)

a=3.2e-2f(3.2*0.01)

printf("%f",a);

scanf("%f",a);

%f 默认保留小数点后六位

%.2f 保留小数点后两位而且会四舍五入

double

(双精度浮点型)

8

double b=3.14;

printf("%lf\n",b);

scanf("%lf",b);

以上是学习的笔记,跟着B站的黑马程序员进行学习的,为了C语言计算机二级考试。

一字一敲,有错误,谢谢大佬的指点!

Guess you like

Origin blog.csdn.net/qq_60043905/article/details/126278846