Professional Documents
Culture Documents
Review Chapter 2
Introduction to C Langauge
Tool Dangerous
Examples of C Programs
Program Structure
Outline
Variable Names
Operators
Arithmetic Operators
Assignment Operators
Function Calls
Mahmoud El-Gayyar / Advanced Programming 3
Outline
Types
Constants Declarations
Variable Names
Operators
Arithmetic Operators
Assignment Operators
Function Calls
Mahmoud El-Gayyar / Advanced Programming 4
Types
Type
char int long int float double
No. Of bits
8 16/32 32/64 32 64
Outline
Types Constants
Declarations
Variable Names
Operators
Function Calls
Mahmoud El-Gayyar / Advanced Programming 6
Constants
Integers
3.14, 10., .01, 123e4, 123.456e7 (e) is the power of 10 Double by default
a, $, 1, hello
\hi\\t\\\man\
Mahmoud El-Gayyar / Advanced Programming 7
User-defined Constants
#define PI 3.14156 #define MYNAME "JOHN DOE" #define LIMIT 10
Outline
Variable Names
Operators
Function Calls
Delcarations
value.
int i=10;
theSum, the_sum
Mahmoud El-Gayyar / Advanced Programming 11
Outline
Variable Names
Operators
Function Calls
12
Arithmetic Operators
Arithmetic Operator % / * + Unary Binary Binary Binary Binary Binary Operands Function (negate Sign number) Modulus (remainder) Division Multiplication Subtraction Addition a
13
1/2
5/2
1 / 2.0 1 % 10 11 % 3 1+2*3 (1 + 2) * 3 1.5 + 2 / 3 + 2.0
2
0.5 1 2 1 + (2*3) 9 1.5+(2 / 3)+2.0
3.5
14
Assignment Operators
15
Outline
Variable Names
Operators
Function Calls
16
Function Calls
Built-in Functions: piece of code written by someone else to perform some useful
task.
Examples:
printf("Hello, world!\n")
printf("%d\n", i)
sqrt(144) printf("sum = %d\n", a + b + c) c = sqrt(a * a + b * b) // paramters can be expressions
17
Summary
18