This presentation is the property of its rightful owner.
Sponsored Links
1 / 53

第 2 章 C 语言的基本知识 PowerPoint PPT Presentation


  • 112 Views
  • Uploaded on
  • Presentation posted in: General

第 2 章 C 语言的基本知识. 2.1 字符集和标识符 2.1.1 字符集 字符集是高级语言的编译系统所能识别的字母、数字和特殊符号。 C 语言的字符集包括: ( 1 )大小写英文字母; ( 2 )数字; ( 3 )运算符: + - * / % > < = & | ? ^ ~ ( 4 )括号 : ( ) { } [ ] ( 5 )标点符号:’ “ : ; ( 6 )特殊符号: _ $ # ( 7 )空白符:空格符、换行符、制表符. 2.1.2 标识符.

Download Presentation

第 2 章 C 语言的基本知识

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


2 c

2 C

2.1

2.1.1

C

1

2

3+ - * / % > < = & | ? ^ ~

4: ( ) { } [ ]

5 : ;

6\ _ $ #

7


2 1 2

2.1.2

C

C

includedefine


2 c

1

: _sum, sum, student_name, price

2

3,

8 : student_ namestudent_ number

41l0o

5


2 c

2.2

2.2.1

    • name/xmsalary/gz

    • lI, o0

  • :

  • sum Sum M.D.John day Date 3days

  • student_name #33 lotus_1_2_3

  • char a>b _above $123

M.D.John

3days

#33

char

a>b

$123


2 c

  • ()()

:


2 c

C, ,

: int student

student=30;

student=30, ,

,

,

: a % b ab,a,b


2 c

2.2.2

20

15.8

'a'


2 c

: #define

2.1: #define PRICE 30

main ( )

{

int num, total;

num=10;

total=num*PRICE;

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

}


2 c

#define PRICE 30

(,)

: =3.1415629

#define PAI 3.1415629


2 c

2.3 C

2.3.1


2 c


2 c

. C

1.

2.


2 c

2.4

2.4.1

C

: 256, 308, 120


2 c

0

0235, 0146 012.

0235=28238515710

014618248610210

012(1821010

"0x"

0x16 0x28


2 c

2.4.2

1.

"int"

2.

"short int" "short"

3.

"long " "long int "


2 c

4.

.

1unsigned intunsigned

2unsigned short

3unsigned long


2 c

2-1

C


2 c

1.:

int a, b, c;

2.

short int short a, b, c;

3.

long int long a, b, c;


2 c

4.

unsigned a, b, c;

unsigned short a, b, c;

unsigned long a, b, c;

2-2: main ( )

{int a, b, c, d; /*a, b, c, d*/

unsigned u; /*u*/

a=12; b= 24; u=10;


2 c

c=a+u; d=b+u;

printf("a+u=%d, b+u=%d\n",c,d);

}

a+u=22, b+u= 14

:


2 c

, ()

1.() 32768~32767,int, long int

2.,2147483648~2147483647, long int


2 c

3.int, short int ,

4.<32768 unsigned int

5. 'l','L',. 123l.


2 c

cint327671?

2-3:

main()

{

int a, b;

a=32767;

b=a+1;

printf("%d%d, a, b);

}

32767-32768


2 c

2.4.3 printf

  • printf

  • %doxu

    %d

    %o

    %x

    %u


2 c

2.4.3 printf

2-4

#include stdio.h

void main()

{

int x,y,z;

x=129,y=0127,z=0x128;

printf(%d,%d,%d\n,x,y,z);

printf(%o,%o,%o\n,x,y,z);

printf(%x,%x,%x\n,x,y,z);

}

12987296

201127450

8157128


2 c

2.4.3 printf

1d

  • %d

  • mdm

    m

    m

  • ld


2 c

2.4.3 printf

2-5d

#include stdio.h

void main()

{

int a=123,b=12345;

printf(%4d,%4d \n,a,b);

long c=135870;

printf(%ld,c);

printf(%8ld,c);

}


2 c

2.4.3 printf

2o

3x

4uunsignedint

5


2 c

2.4.3 printf

2-6oxu

  • #include "stdio.h"

  • void main()

  • {

  • int a=-1;

  • printf("%x,%o,%d \n",a,a,a);

  • unsigned int b=65535;

  • int c=-2;

  • printf("%d,%o,%x,%u \n",b,b,b,b);

  • printf("%d,%o,%x,%u \n",c,c,c,c);

  • /* printf("%d",8*sizeof(int)); */

  • }


2 c

2.4.4 scanf

scanf

  • scanf

&

2-7scanf

main()

{ int a,b,c;

scanf(%d,%d,&a,&b);

printf(a=%d,b=%d,a,b);

1015

a=10,b=15

a

10

b

15


2 c

2.4.4 scanf

  • scanf

  • tab


2 c

  • int a,b,c;

  • scanf(%d%d%d,&a,&b,&c);

  • 10 17 181

  • int a,b,c;

  • scanf(%d,%d,%d\n,&a,&b,&c);

  • 101112

scanf(a=%3db=%3oc=%x,&a,&b,&c);

a=123b=456c=10


2 c

2.5

2.5.1

1.

: 0.126, 523.64

2.

,

0.0000126 1.26E 5

1260000 1.26E+6 1.26E6

' E ', 'e ' .

eE

3.5E-5 2e3

E2 3.6e3.5 .e6 e


2 c

2.5.2

.

float x, y, z; ()

double a, b, c; ()

long double

: 4;

8.


2 c

:

: pc, 7, 15

: float a;

a=123456.789

a123456.7

: 1038~1038

: 10308~10308


2 c

2.5.3 %f

(1) %f ,

6

floatdouble

float x=123456.123;

printf(%f,x);

123456.125000

%lf

double y=12345678.98765432

printf(%lf,y);

12345678.987654


2 c

main()

{ double x,y;

x=1111111111111.111111111;

y=1111111111111.111111111;

printf(%f,x+y);

}

2222222222222.222170


2 c

float f=123.456;

printf(%10.2f ,%-10.2f,f);

123.46,123.46

(2) %m.nf m,n

m

(3)%m.nf %m.nf


2 c

2.5.3 %e

(1) %e

printf(%e,123.456);

: 1.234560e+002

6

3

13

(2) % m.ne %m.ne: mn

n()


2 c

f=123.468

printf(%f , %e , %g, f , f, f);

:

123.468000 , 1.234680e+002 , 123.468

f=123.468

printf(%f , %e , %g, f , f, f);

:

123.468000 , 1.234680e+002 , 123.468

10

10

13

%g,,fe()


2 c

\t

\n

\b

\v

\r

\f

\a

\\

\

\

<

216

\ddd

38

\xhh

2.6

2.6.1

ab

ASCII.

:

main()

{

printf("How are you \n");

printf("\\C Program\\\n");

printf("Turbo \'C\'");

}

a A ? \n \101

A65 a97

048 , \n10

()

How are you

\C Program\

Turbo C

\101 -----------A \012 -----------\n

\376 ----------- \x61 -----------a

\60 -----------0 \483 ----------()

:

A-------\101-------\x41--------65


2 c

2.6.2

.

char c1, c2;

c1=' a ';

c2= ' b ';

ASCII,ASCII

: ,,


2 c

:

1: main ( )

{ char c1, c2;

c1=97;

c2=98;

printf ("%c %c", c1, c2)

}

%c

a b


2 c

2: main ( )

{ char c1, c2;

c1= ' a ';

c2=' b ';

c1=c1 32; c2=c2 32;

printf ("%c %c", c1, c2)

}

A B


2 c

3: main ( )

{ int i;

char c;

i= ' a ';

c=97;

printf ("%c, %d \n", c, c);

printf ("%c, %d \n", i, i);

}

,0~255,ASCII

: a , 97

a , 97


2 c

2.6.3 scanf

%cscanftab

scanf(%d%c,&i,&m

29 wmw

scanf(%d %c,&i,&m


1 getchar

#includestdio.h

void main()

{ char c;

c=getchar();

printf(%c,c);

}

1. getchar

2.6.4 getcharputchar

getchar( )

#include <stdio.h>


2 c

2. putchar

putchar( )

    • #include <stdio.h>

    • void main( )

    • {

    • char a,b,c;

    • a=B; b=O; c=Y;

    • putchar(a);

    • putchar(b);

    • putchar(c);

    • putchar(\);

    • }

: BOY


2 c

  • getchar()putchar()ASCII

  • #includestdio.h

  • void main()

  • { int c,i;

  • c=getchar();

  • i=putchar(c);

  • printf("%d",i);

  • }


2 c

2.6.5

: "Good Morning! "

'A' "A"

,"/ 0"

:

Good Morning ! /0


2 c

"A "

A /0

'A'

A

:

1.=+1,\0.

printf (" Good Morning! ")

/0

2.

: char c;

c= " a ";


2 c

2.6.6 %s

(1) %s

printf(%s,CHINA)

CHINA

(2) %ms m

mm

m

(3) %ms mm


2 c

printf(%3s,%7.2s,%.4s,%-5.3s\n,

CHINA, CHINA ,CHINA, CHINA);

CHINA, CH,CHIN, CHI

(4) %m.ns m

n

n>m,n

(5) %m.ns , mnn

m


  • Login