You are on page 1of 14

6

http://www2.binghamton.edu/images/creativewriting.jpg

6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9

1.
2.
3.
4.

-2-

6.1


1 (run) 2 (object code)


3 (compile) ANSI C

(source code)


0 1

6.2

1) (Source file) .c .cpp
(Editor)
()
2) (C Compiler)
(Object file) .obj (
)
3) (Linker)
(C Library)
.exe (
)

(machine code)

-3C Compiler

Source file

Computer

Linker

Object file

Computer

Library

Execute file

6.3
(C Language) (B Language)
(Dennis Ritchie) (Bell Laboratories) .. 1972
(UNIX Operating System)

Comments (1)
Preprocessor directives (2)
Global declaration (3)
main ( ) . (4)
{
declaration statement;
assignment statement;
user-defined function call( ); . (5)
}

2
1) (Comments)


// /* */
// .

/*
. .
..*/

-4-

2) (Preprocessor directives)

(#)

#include (compiler)

#include<filename> #includefilename

#include<dos.h>
dos.h
#includesample.h
sample.h

o <>
Option directory

o
(Header Files) .h
1
stdio.h printf main()
process clrscr() conio.h include
conio.h

#include
Include text from a file
#define
Define a macro
#undef
Undefined a macro
#if
Test if a compile-time condition holed.
#ifdef
Test if a symbol is defined
#ifndef
Test if a symbol is not defined
#else
Indicate alternative if a test file fail.
#line
Give a line number for compiler message.

-5-

#define

#define ()

#define TEN 10
TEN 10
#define PI 3.141592654 PI 3.141592654

3) (Global Declaration)

#include<stdio.h>
int x;
void main(){
x = 7;
printf(%d,x);
}

//global declaration

4) (main program)
main
semi colon (;)
#include<stdio.h>
void main(){
int a,b;
scanf(%d,&a);
scanf(%d,&b);
printf(%d,a+b);
}

// main program

-6-

5) (User defined function call)


#include<stdio.h>
int sum(int a,int b){
return(a+b);
}
void main(){
printf(%d,sum(5,9));
}

// user defined function call

6.4


auto
default
float
register struct
volatile
break
do
far
return
switch
while
case
double
goto
short
typedef char
else
if
signed
union
const
enum
int
sizeof
unsigned
continue
extern
long
static
void

6.5
5
1) char (1 )
2) int (2 )
3) float (4 )

char
Int
float
double
void

4) double (8 )
5) void (0 )

(bytes)
(range)

1
-128 127

2
-32,768 32,767
()
4
3.4E + 38 (7 )
2
8
1.7E + 308 (15 )

0

1 C

-7-

1 4

(signed) (unsigned), (long) (short) 2

char
int
short
short int
long

(bytes)
1
2
2
2
4

long int

Unsigned Char
unsigned
unsigned int
Unsigned short
Unsigned Long
signed Char
signed
signed int
signed short
signed Long

1
2
2
2
4
1
2
2
2
4

(range)
-128 127
-32,768 32,767
-32,768 32,767
-32,768 32,767
-2,147,483,648
2,147,483,647
-2,147,483,648
2,147,483,647
0 255
0 65,535
0 65,535
0 65,535
0 4,294,967,295
-128 127
-32,768 32,767
-32,768 32,767
-32,768 32,767
-2,147,483,648
2,147,483,647

2 : C

6.6
(Variables) 2
1) Global Variable
0 ( )
2) Local Variable

-8-

[,];

1. underscore ( _ )
2. underscore ( _ )
3. underscore
4. 1 32 (
)
5. (Reserved word)
6.
count, COUNT, Count 3

Count
Num12
m_mum

1count
num !
mmun

2

int
float

6.7
(Constant)


const = ;

const float Pi = 3.1415; Pi float 3.1415

-9-


1)
(integer constant) 0
3
(decimal integer constant)
( 0 9 ) 0
const int price = 1000;
const int WeekDay = 7;
(octal integer constant)
(0 7) 0
const int Oct1 = 01000;
const int Oct2 =03 7;
(hexadecimal integer constant)
( 0 9 A F) 0X 0x
const int Hex1 = 0xF78;
const int Hex2 =0xFF;
2)
(floating point constant)
2
0 9

const float Pi = 3.1415;


const float InterestRate =0.65;
2 float
E ( e)

const float A = 1.0E2; // 1.0 * 102 = 100.0


const float A = 1E+3; // 1 * 103
= 1000.0
-2
= 0.01
const float A = 1E-2; // 1 * 10

- 10 -

3)
(character constant)
( )
const char A = a;
const char B =b;
char ASCII
A = 65, B = 66
(escape sequence)
\ ( ) \n , \t
3

\a
\b
\f
\n
\r
\t
\\
\
\
\?

Alarm bell
()
Backspace

Formfeed

Newline

Return

Tab

Backslash
\\
Single quote
\
Double quote

Question mark
?
3

6.8
(Operator) 3
1) (arithmetic operators)
2) (relational operators)
3) ( logical operators)

- 11 -

1) (arithmetic operators)
4

XY
+

X+Y
*

X*Y
/

X/Y
%

11%3 = 3 2 2
- 1
X- - - -X X=X-1
++
1
X+ + + +X X=X+1
4 C
(modulas)
4 C (+)
(=) (+=) (-) (=) (-=) 5

y = x + a ++;
y = x + ++ a;
y += x ;
y += x ++ ;
y -= 9 ;
y *= 7 * x++ ;

1.
2.
1.
2.
1.

y = x+a
a = a+1
a = a+1
y = x+a
y=y+x

1. y = y + x
2. x = x + 1
1. y = y - 9

y /= x ;

1. y = y * 7 * x
2. x = x + 1
1. y = y / x

y %= x ;

1. y = y % x
5 C

- 12 -

C

(Operator)
6

()
+ + - - unary
* / %
+ += -= *= = /= %=

1 ()
2
3
4
5 ()

6

7

5+6*2
2 * 3 14 / 7 + 5

* +
5
* /

2) (relational operators)
1 0 8

>

A > B (A B)
>=

A >= B (A B)
<

A < B (A B)
<=

A <= B (A B)
==

A = = B (A B)
!=

A ! = B (A B)
8

- 13 -

3) ( logical operators)
2 1
0 C
&& (AND) 2
X
Y
X && Y
0
0
0
0
1
0
1
0
0
1
1
1
| | (OR) 2
X
Y
X||Y
0
0
0
0
1
1
1
0
1
1
1
1
! (NOT)
X
!X
0
1
1
0

6.9
(Expression)
C
1) XY 1
2) C



int long C long
int double C double

- 14 -

2X2

2*(X*X)

10X + 3XY + 10Y2

10*X-3*X*Y+10*Y*Y

9 C

1) (Arithmetic Expression)

10
C
3*X + 5*Y
3X + 5Y
X*X - Y*Y
X2 - Y2
10
2) (Logical Expression)

1 0
11
I 3 J 5 A 3
I==J

(0)

I==A

(1)

I > J*5

(0)

I+3 > J 2 && a*2 > 10

(0)

11

4 4-6
2544

You might also like