0% found this document useful (0 votes)
34 views

Computer Programming I: Spring 2015

This document summarizes a lecture on the basics of C programming, including: the structure of C programs with preprocessor directives and main functions; simple data types like int, double, and char; input/output functions printf and scanf; assignment statements and arithmetic operators; and common programming errors. It provides examples of variable declarations, data types, functions, and arithmetic expressions. The objectives are to understand the structure of simple C programs and basic C language elements.

Uploaded by

JNB Games
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Computer Programming I: Spring 2015

This document summarizes a lecture on the basics of C programming, including: the structure of C programs with preprocessor directives and main functions; simple data types like int, double, and char; input/output functions printf and scanf; assignment statements and arithmetic operators; and common programming errors. It provides examples of variable declarations, data types, functions, and arithmetic expressions. The objectives are to understand the structure of simple C programs and basic C language elements.

Uploaded by

JNB Games
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

CSC 1401

Computer Programming I
Hamid Harroud
School of Science and Engineering,
Al Akhawayn University in Ifrane
[email protected]

Spring 2015
Lecture 3

Overview of C
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

3
C Language Elements

Preprocessor
directives

Main function

4
General Form of a C program

• Preprocessor directives: #include, #define


• Main function: int main (void)
• Any used variable should be declared before its
usage.
5
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: EXAMPLES:
int variable_list; int count,large;
double variable_list; double x, y, z;
char variable_list; char first_initial;
char ans;

6
Data Types
• int
– Range : -32767 ~ + 32767 --- in ANSI C
– -10500 435 +15 -25 32767
• double

• char
– ‘A’ ‘a’ ‘z’ ‘2’ ‘9’ ‘*’ ‘?’

7
Executable Statements
• Program in Memory
• Assignment Statements
• Input/Output Functions
– C function: printf
– C function: scanf
• Arithmetic Expressions

8
Assignment Statements

Memory(a) Before and (b) After Execution of a Program


9
Before and After Assignment of
a variable
kms = KMS_PER_MILE * miles;

10
Before and After Assignment of
a variable
sum = sum + item;

11
Function: scanf

scanf("%lf", &miles);

12
scanf

scanf("%c%c%c", &letter_1, &letter_2, &letter_3 );

13
Function: printf

14
Arithmetic Expressions
• Arithmetic Operators
• Mixed-Type Assignment Statement
• Expression with Multiple Operators

15
Arithmetic Operators

16
Execution of Multiple Operators
• Can be expressed as an Evaluation Tree.

area = PI * radius * radius;

17
Step by Step Expression
Evaluation

18
Operator Precedence
• An operator’s precedence determines
its order of evaluation.

- x – y * z

z-(a + b/2)+ w * -y

19
Evaluation Tree (1)

v = (p2 - p1) / (t2 - t1);

20
Evaluation Tree (2)

z - (a + b / 2) + w * -y

21
Common Programming Errors
• Syntax Errors
• Run-Time Errors
• Logic Errors

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

23

You might also like