Download presentation
Presentation is loading. Please wait.
Published byBlaze Little Modified over 9 years ago
1
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University h.harroud@aui.ma http://www.aui.ma/~H.Harroud/CSC1401 Spring 2009
2
Overview of C Lecture 3
3
3 Objectives Structure of simple C programs Simple data types int, double, and char. Input/output functions printf and scanf. Preprocessor directives #include and #define Comments Assignment statement along with the basic arithmetic operators Case Study Common Errors
4
4 C Language Elements Preprocessor directives Main function { }
5
5 General Form of a C program Preprocessor directives: #include, #define Main function: int main (void) Any used variable should be declared before the usage.
6
6 Variable Declarations Variables: values stored in variables can changes Variables Declarations: What kind of information will be stored in each variable How that information will be represented in memory SYNTAX: int variable_list; double variable_list; char variable_list; EXAMPLES: int count,large; double x, y, z; char first_initial; char ans;
7
7 Data Types int Range : -32767 ~ + 32767 --- in ANSI C -10500 435 +15 -25 32767 double char ‘ A ’ ‘ a ’ ‘ z ’ ‘ 2 ’ ‘ 9 ’ ‘ * ’ ‘ ? ’
8
8 Executable Statements Program in Memory Assignment Statements Input/Output Functions C function: printf C function: scanf Arithmetic Expressions
9
9 Assignment Statements Memory(a) Before and (b) After Execution of a Program
10
10 Before and After Assignment of a variable kms = KMS_PER_MILE * miles;
11
11 Before and After Assignment of a variable sum = sum + item;
12
12 Function: printf
13
13 Function: scanf scanf("%lf", &miles);
14
14 scanf scanf("%c%c%c", &letter_1, &letter_2, &letter_3 );
15
15 Arithmetic Expressions Arithmetic Operators Mixed-Type Assignment Statement Expression with Multiple Operators
16
16 Arithmetic Operators
17
17 Execution of Multiple Operators Can be expressed as an Evaluation Tree. area = PI * radius * radius;
18
18 Step by Step Expression Evaluation
19
19 Evaluation Tree (1) v = (p2 - p1) / (t2 - t1);
20
20 Evaluation Tree (2) z - (a + b / 2) + w * -y
21
21 Common Programming Errors Syntax Errors Run-Time Errors Undetected Errors Logic Errors
22
22 Summary Structure of simple C programs Simple data types int, double, and char. Input/output functions printf and scanf. Preprocessor directives #include and #define Comments Assignment statement along with the basic arithmetic operators Case Study Common Errors
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.