Glossa Programmatismou C 1 Eisagogi

  • View
    28

  • Download
    5

Embed Size (px)

Transcript

C ( 1 - ) C C Dennis Ritchie Bell Labs 1972 Ken Thompson Unix. C Ken Thompson BCPL . C . , 1983 Ansi C.

C (high level languages), Cobol Pascal (low level languages), Assembly. , . . , . Pascal, , , Basic . Clipper Cobol .

C, , hardware, . , , .

C C . , . , C . , . , . , C , , ' . . , C , . . . , C , . , Unix C. , (compilers) (interpreters) . C (assembly language). , C ,

eB

oo

ks

4G

re

ek

s.g

r

. C (bits) . C , Pascal . , . C () . , , , . , C .

C C , . , C, . , C , , . , C. C , .

C , C , (functions). , . , C , main(). C main(), . --- (top-down programming).

, . , --- (bottom-up programming). --- , .

Assembly C , Assembly Assembly . Assembly , , , . C Assembly. , C Assembly, .

(compiler) C (source program), . C, (object program) (linker) (executable file). C .c. , (start-up code) (library code) . . , ' .

Turbo-C Turbo-C tc Dos. , : File : ' , , , Turbo-C, . Edit : . Run : , . Compile : . Project : . Options : . Debug : .

C/* prog01.c C */ #include main() { int num; /* num */

num = 10 ; /* num */ printf(" C.\n"); /* printf() */ printf(" %d.\n", num);

} , : C. 10.

/* */ (comments), . . (include) stdio.h, C. C , C. main(). main() . { }. { } begin end Pascal. num num (integer). 10 num. (" "). \n ( ). num ( 10) " ". %d num. }.

#include

stdio.h C , printf(), . standard input/output header. C . #include stdio.h , . , C. # (preprocessor) C, . main() C main(). , main() . main() . , () . , , (), . , , , . , /* */ C , . , , { } , begin end Pascal. C. , .. . int - C, .

. C.

C () : , , , .. , , (_). , , . . , . C . ;. printf() ' . () main() printf(). printf() " " . . , , . \n, , . \n , . .

. \t tab \b (backspace). , , %d; . C . , #include, . { } , ;. , .

. . , C . . .

C/* prog02.c */ #include main() { int cm, metres;

metres = 2; cm = 100 * metres;

printf(" %d %d . \n", cm, metres);

} , . , , . , * printf(). , : 200 2 .

. /* prog03.c */ #include main() { printf(" .\n"); florina(); printf(" .\n"); }

florina() { printf(" .\n"); } : .

. . florina) , main(), . . florina() , main(). main(), main() .

C . C . { } , . , . , , , , . . C , , . , .. , . . . -. printf() , . printf() . ,

. (debuggers) .

- ANSI C - (reserved words) C . : auto continue enum if short switch volatile break default extern int signed typedef while case do float long sizeof union char double for register static unsigned const else goto return struct void

, , .

C. /* prog04.c */ #include main() { float draxmes, euro; char beep; /* 2 */ /* */

beep = \007

/* */

printf(" ;\n"); printf(" \n"); printf(" .\n"); scanf("%f", &euro); /* */ draxmes = 340.75 * euro; */ /* 340.75

printf("%c %.2f%c. \n", beep, draxmes, beep); } , : ; . 100.00 34075.00

' , (float) (char) . %f %c printf() . .2 , . scanf(). %f &euro scanf() euro. & . printf() scanf() , scanf() printf()

. beep .

. C - : int, long, short, unsigned, char, float double. int long, short unsigned . char float, double long double . - , . , . , , . , 7 0.71, 0.7 101 = 7. ' , .

int , . , . (bytes) -32768 +32767. - int . , , , . , ' . scanf().

. C , (=) , : int a=10; int b, cs=20; C . 0 () 0x 0X . , 16 020 0x10 0X10. ' . %d , int, int , int. : /* prog05.c printf() */ #include main() { int ten = 10; printf("%d %d %d\n", ten, 2, ten-2); } : 10 2 8 , , %o %x. : /* prog06.c 100 */ #include main()

{ int x = 100; printf(" = %d; = %o; = %x\n", x, x, x); } : = 100; = 144; = 64 0 0x .

C - : unsigned, long short. short int short , ' , int . long int long ' , int . unsigned 0 65535 -32768 +32767. , unsigned , ' . long , int. , , long , . short . long, l L . unsigned %u, long %ld l o x. , %h short.

, char , . , . ASCII 65 . char : char name, city; C char -128 +127 C char 0 255. char : char grade = 65; char grade = 'A'; /* */ /* ASCII */

' ' C , " " , .

ASCII , (backspace), enter (beep). C . ASCII , : char beep = 7; ASCII, ASCII \ , : beep = '\007'; , 0. ANSI C , \ x X 1 3 . , Control-P '\x10' '\X010'.

, (escape sequence) : \a \b \f \n \r \t \v \\ \' \" - beep (ANSI C) ( ) (enter) (tab) (ANSI C) (\) (') (") (ANSI C)

: next = '\n'; next . printf() %c . , char, . %c printf() . : /* prog07.c - */ #include main() { char ch; printf(" : \n"); scanf("%c", &ch);

printf(" %c %d. \n", ch, ch); } : : C C 67. printf() ch , ( %c) ( %d). printf() .

float double C float real Pascal. , , . double ( ) long double. : float a=10.25e-3; double b; long double c; f F ANSI C float, .. 2.3f 9.11E9F, l L long double, .. 54.31l 4.32e4L. printf() %f float double %e . long double %Lf %Le.

sizeof

C , sizeof, bytes. : /* prog08.c */ #include main() { printf(" int %d bytes. \n", sizeof(int)); printf(" char %d bytes. \n", sizeof(char)); printf(" long %d bytes. \n", sizeof(long)); printf(" double %d bytes. \n", sizeof(double)); } : int 2 bytes. char 1 bytes. long 4 bytes. double 8 bytes.

. /* prog09.c */ #include main() { float weight; int size, letters; char name[40];

printf(" ! ; \n"); scanf("%s", name); printf("%s, ; \n", name); scanf("%f", &weight); size = sizeof name; letters = strlen(name); printf(" , %s, %2.2f . \n", name, volume); printf(", %d , \n", letters); printf(" %d bytes .\n", size); } , : ! ; , ; 100 , , 100,00 . , 6 , 40 bytes . : 1. . 2. %s . name, weight, & scanf(). 4. C strlen() . , , ;

, : " 1993". , . C char . C \0 . 0,