Kenneth Lane Thompson Dennis Ritchie PCoriented programs Word

  • Slides: 48
Download presentation

Kenneth Lane Thompson Dennis Ritchie

Kenneth Lane Thompson Dennis Ritchie

�������� • • PC-oriented programs Word processors Drawing programs Spreadsheets Databases Complex simulations Real-time

�������� • • PC-oriented programs Word processors Drawing programs Spreadsheets Databases Complex simulations Real-time digital signal processing

Source code Library file Object code . c Compile source file. obj Link object

Source code Library file Object code . c Compile source file. obj Link object file Ex e pr cu og t a ra b l e m . exe

main’s header Predefined function main’s body

main’s header Predefined function main’s body

C Fundamentals ���������� • C Character set • Identifiers and keywords • Data types

C Fundamentals ���������� • C Character set • Identifiers and keywords • Data types • Constants • Variables and array • Declarations • Expressions and statements

score_45 %score ������ 45_score ���� ��� score-45 main score 45% x+y

score_45 %score ������ 45_score ���� ��� score-45 main score 45% x+y

Data types int ����� 2 -4 bytes char ������ 1 byte float ����� 4

Data types int ����� 2 -4 bytes char ������ 1 byte float ����� 4 byte (1 word) ���������� 8 byte (2 word) ����� double

Data type qualifiers ����� ����� �� � short int 2 long short long int

Data type qualifiers ����� ����� �� � short int 2 long short long int short int 4 2 int 4 long int 4 32768 -��� +32767 ���� data type ���������

Data type qualifiers ������� ��� � short int 2 unsigned short int 2 0

Data type qualifiers ������� ��� � short int 2 unsigned short int 2 0 ��� 65, 535 int 4 -2147483648 ��� +2147483647 unsigned int 4 0 ��� 4294967295 long int 4 -2147483648 ��� +2147483647 unsigned long int 4 0 ��� 4294967295 char 1 -128 +127 unsigned char 1 0 ��� 255 32768 -��� +32767

������ (Data types( ��������� �� single-precision floating-point double-precision floating-point float 4 double 8 1.

������ (Data types( ��������� �� single-precision floating-point double-precision floating-point float 4 double 8 1. 2 E-38 ��� 3. 4 E 38 2. 2 E-308 ��� 1. 8 E 308

constants �� 4 ���� 1. integer constant 2. floating-point constant 3. character constant 4.

constants �� 4 ���� 1. integer constant 2. floating-point constant 3. character constant 4. string constant

Integer constant • ������ 10 (decimal) 0 54 37895 • ������ 8 (octal) ������

Integer constant • ������ 10 (decimal) 0 54 37895 • ������ 8 (octal) ������ 0 0 054 037895 • ������ 16 (hexadecimal) ����� 0 x ���� 0 X 0 x 0 x 54 0 x. ABC 0 x 35895

Unsigned integer constant • • (1234 U (1234 L (1234 UL (01234 U (0

Unsigned integer constant • • (1234 U (1234 L (1234 UL (01234 U (0 x 12 AFUL decimal (unsigned decimal (long decimal (unsigned long octal (unsigned hexadecimal (unsigned long U L : Either upper or lowercase

Floating-point constant 0. 543. 2. 123 e 4 1. 23 e+4 1. 1000. 1

Floating-point constant 0. 543. 2. 123 e 4 1. 23 e+4 1. 1000. 1 E-3 0. 5 12. 3 0. 00 e-4

Escape Sequences � null a Bell (alert) b Backspace f Formfeed n New line

Escape Sequences null a Bell (alert) b Backspace f Formfeed n New line r Carriage return t Horizontal tab v Vertical tab ' Single quotation mark " Double quotation mark \ Backslash ? Literal question mark ooo ASCII character in octal notation x hh ASCII character in hexadecimal notation x hhhh Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal. For example, WCHAR f = L'x 4 e 00' or WCHAR b[] = L"The Chinese character for one is x 4 e 00".

������� int count; int m, n; ���������� short x, y, z; long number; ��������

������� int count; int m, n; ���������� short x, y, z; long number; �������� float percent, total; �� ���������� int no = 10; float sum = 0; double = 2. 75 e-8 char = ‘*’; char text[ ] = “bangkok”; chat text[8] = “bangkok”; text[0] = ‘b’, text[1] = ‘a’, … , text[8] =

������� int no = 10; int no; no = 10; int num; num =

������� int no = 10; int no; no = 10; int num; num = 010; 108 int num; num = 0 x 10; 1016

������ (Expression) • ������� �������� �������� 10 a x[5 [ • ������� Addition operator

������ (Expression) • ������� �������� �������� 10 a x[5 [ • ������� Addition operator Assignmentoperator Relational operator �������� a+b c=a c<d c=a+b c <= e c == f Unary operator ++a

������ (statement( • ����������� • ����� 3 ���� – Expression statement – Compound statement

������ (statement( • ����������� • ����� 3 ���� – Expression statement – Compound statement – Control statement

������� Expression statement ������� ���� ; a = 5; b = a + 5;

������� Expression statement ������� ���� ; a = 5; b = a + 5; c = b – a; ++k; printf (“Score = %f”, score); (printf function) ; (null statement)

������� Symbolic constants #define symbolicname text #define VAT 0. 07 #define PI 3. 141593

������� Symbolic constants #define symbolicname text #define VAT 0. 07 #define PI 3. 141593 #define TRUE 1 #define FALSE 0 #define TEACHER ‘A. Pat’ Symbolicname ������� Uppercase

������� Symbolic constants #define PI 3. 141593 … area = PI * radius; #define

������� Symbolic constants #define PI 3. 141593 … area = PI * radius; #define VAT 0. 07 …. price = 200; tax = price * 0. 07; netprice = price + tax;