Programming With C Language

  • Published on
    03-Aug-2015

  • View
    29

  • Download
    3

Embed Size (px)

Transcript

2 1. 2. 3. 2. 2.1 2.1.1 2.1.2 2.2 2.2.1 (Arithmetic Operators) 2.2.2 (Relational Operators) 2.2.3 (Logical Operators) 2.2.4 (Increment and Decrement Operation) 2.2.5 (Bit wise Operation) 2.2.6 (Assignment Operation ) 2.2.7 (Precedence) 2.3 2.3.1 printf( ),putchar( ), puts( ) 2.3.2 scanf(),getchar( ),getch( ),gets( )

2 2.1 , , , ( , ), ( 4 3 ), 2.1.1 6 1. (Integer) (Integer) 2 Short 2 32,768 +32,767 Long 4 2,147,438,648 +2,147,438,647 9, 779955, 900, -3, 0, -66, 4655 2. (Float)

3 E ( e) 3 Float, Double, Long Double 4.00, 17.55, -8.00, -1.2E, 9.7e12, 5.55555..., 7.77777... 3. (Octal) 8 0-7 8 9 125, 759, 552 8 1738, 5228, 5778 (0) 0123, 0597, 0102, 09 2 4. (Hexadecimal) 16 0-15 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F 10-15 A-F 987, 999, 259, A (10), B (11) 16 A516 , 9B916 , 9E116 X 0X99, 0X05, 0X22 5. (Character) 1 byte 1 128 +127 (Unsigned) AZ ,a-z ,0-9 { , \n , # (Single Quote) C, {, \n, #, @ 1

4 6. (String) 1 (Double quote) Program C , Technology , Computer 1.(Variable) (RAM) 1 name May May name name May number 9 9 number number 9 2. (Constant) # define # define Max 99 2.1.2 2 (Scalar) 1 num 9 1 9 (Array) 1 Array[5] 1, 2, 3, 4 5 1 Array[5] 5 1, 2, 3, 4 5 2

5 4 ANSI 2-1 ANSI (bits) -128 127 char 8 ( ASCII) 8 bits (1 byte ) unsigned char 8 0 255 -32,768 int 16 32,767 16 bits (2 bytes) unsigned int 16 0 65,535 short 8 -128 127 8 bits (1 bytes) unsigned short 8 0 255 2-1 ANSI () (bits) -2,147,483,648 long 32 32 bits (4 bytes) 2,147,483,649 0 unsigned long 32 4,294,967,296 3.4*10-38 float 32 32 bits (4 bytes ) 3.4*1038 6 3.4*10-308 double 64 64 bits (8 bytes ) 3.4*10308 12

6 3.4*10-4032 3.4*104032 128 bits (16 bytes ) 24

long double

128

(Variables Declaring ) (Variables Declaring) Type Variable ; Type = Variable = char ch; ----> ch int num; ----> num float y; ----> y long u; ----> u Character, Integer Type Variable = Value

7

Type = Variable = Value = char ch = @; ----> ch @ int start = 0x55; ----> start 55 0x long million = 999999; ----> million 999999 1. A-Z a-z _ (Underscore) 2. A-Z a-z 0-9 _ 3. 2 4. Name name 2 5. (Reserved Word)

8

Auto break case char continue default

do double else entry enum extern

float for goto if int long

register return shot size of static struct

switch typedef union unsigned void while

business -----------------> number75 -----------------> sanook_com -----------------> SYSTEM -----------------> A5A5A -----------------> bc-computer -----------------> goto -----------------> _man men -----------------> 597compute -----------------> Variable Local, Global (Variable) 5 2 Local Variable Global Variable 1) Local Variable Automatic Local Local 5

9 2) Global Variable External Global Variable Global Variable Local Variable Global Variable 5 2.2 (Operator) (Operator) 2 2.2.1 (Arithmetic Operators) (Arithmetic Operators) + (Addition) (Subtraction) * (Multiplication) / (Division) % (Modulus) + A+B 4+2 = 6 4 2 6 A-B 4-2 = 2 4 2 2 * A*B 4*2 = 8 4 2 8 / A/B 4/2 = 1 4 2 2 1 1 % A%B 4%2 = 2 4 2 2 1 2

10 2.2.2 (Relational Operators) (Relational Operators) 2 2 (True) (False) == (Equal) != (Not Equal) > (Greater than) < (Less than) >= (Greater than and Equal) A>B (4+2) > (4-2) True < A= A >= B (4+2) >= (4-2) False B && C < D 4 > 2 && 4 < 2 True && False || A > B || C < D 4 > 2 || 4 < 2 True || False Not Not Not !(4 > 2) True False !(4 < 2) False True And 2 And 1 2 And True True True True False False False True False False False False True False True12 Or False 2 Or 1 2 Or True True True True False True False True True False False False 2.2.4 (Increment and Decrement Operation) ++ (Increment) - (Decrement) ++ ++A -AA A = A+1 ---A -AA A = A-1 2.2.5 (Bit wise Operation) & (And) | (Inclusive OR) ^ (Exclusive OR) ~ (Complement) > (Left Shift)13 & A&B A AND B | A|B A OR B ^ A^B A XOR B ~ ~A Complement A >4 4 2.2.6 (Assignment Operation) Property Object Property Object (Expression) = += -= *= /= %= &= (Inclusive OR) |= (Exclusive OR) ^= (Complement) = (Left Shift)14 = A=B += A += B A = A+B -= A -= B A = A-B *= A *= B A = A*B /= A /= B A = A/B %= A %= B A = A%B &= A &= B A = A&B |= A|=B A=A|B ^= A ^= B A=A^B Enter your message : Nice to meet you! Enter message is Nice to meet you29