You are on page 1of 52

Computer Programming

ECE201
Lecture 1
Omar M. Saad
C LANGUAGE.

Why Learn C?
 It is one of the most popular programming language in the
world.

 If you know C, you will have no problem to learn other


popular programming languages such as Java, C++, C#,
etc, as the syntax is similar.

 C is very fast, compared to other programming languages,


like Java.

 It can be used in both applications and technologies.

February 23, 2022 2 ECE201-Lec1


C LANGUAGE.

Difference between C and C++?

 C++ was developed as an extension of C, and both


languages have almost the same syntax.

 The main difference between C and C++ is that C++


support classes and objects, while C does not

February 23, 2022 3 ECE201-Lec1


TOOLS.

 dev c++.

February 23, 2022 4 ECE201-Lec1


SYNTAX.

Line 1: #include <stdio.h> is a header file library that lets us work with input and output
functions, such as printf() (used in line 4).

Line 2: A blank line. C ignores white space. But we use it to make the code more readable.

Line 3: Another thing that always appear in a C program, is main(). This is called a function.
Any code inside its curly brackets {} will be executed.

Line 4: printf() is a function used to output/print text to the screen. In our example it will
output "Hello World".

Note that: Every C statement ends with a semicolon ;


Note: The body of int main() could also been written as:
int main(){printf("Hello World!");return 0;}

February 23, 2022 5 ECE201-Lec1


SYNTAX.

Remember: The compiler ignores white spaces. However, multiple lines makes the code more
readable.

Line 5: return 0 ends the main() function.

Line 6: Do not forget to add the closing curly bracket } to actually end the main function.

February 23, 2022 6 ECE201-Lec1


DATA TYPE.

February 23, 2022 7 ECE201-Lec1


SYNTAX.

February 23, 2022 8 ECE201-Lec1


DATA TYPE.

February 23, 2022 9 ECE201-Lec1


DATA TYPE.

C Identifiers
 Identifier refers to name given to entities such as variables, functions,
structures etc.
 Identifiers must be unique. They are created to give a unique name to an
entity to identify it during the execution of the program. For example:

February 23, 2022 10 ECE201-Lec1


DATA TYPE.

February 23, 2022 11 ECE201-Lec1


DATA TYPE.

 Here, the type of number variable is int. You cannot assign a floating-point (decimal)
value 5.5 to this variable.

 Also, you cannot redefine the data type of the variable to double.

 By the way, to store the decimal values in C, you need to declare its type to
either double or float.

February 23, 2022 12 ECE201-Lec1


DATA TYPE.

February 23, 2022 13 ECE201-Lec1


DATA TYPE.

February 23, 2022 14 ECE201-Lec1


DATA TYPE.

February 23, 2022 15 ECE201-Lec1


DATA TYPE.

February 23, 2022 16 ECE201-Lec1


DATA TYPE.

February 23, 2022 17 ECE201-Lec1


DATA TYPE.

February 23, 2022 18 ECE201-Lec1


DATA TYPE.

February 23, 2022 19 ECE201-Lec1


DATA TYPE.

February 23, 2022 20 ECE201-Lec1


DATA TYPE.

February 23, 2022 21 ECE201-Lec1


DATA TYPE.

February 23, 2022 22 ECE201-Lec1


DATA TYPE.

February 23, 2022 23 ECE201-Lec1


OPERATORS.

February 23, 2022 24 ECE201-Lec1


OPERATORS.

February 23, 2022 25 ECE201-Lec1


OPERATORS.

February 23, 2022 26 ECE201-Lec1


OPERATORS.

February 23, 2022 27 ECE201-Lec1


OPERATORS.

February 23, 2022 28 ECE201-Lec1


OPERATORS.

February 23, 2022 29 ECE201-Lec1


OPERATORS.

February 23, 2022 30 ECE201-Lec1


IF STATEMENT.

February 23, 2022 31 ECE201-Lec1


IF STATEMENT.

February 23, 2022 32 ECE201-Lec1


IF STATEMENT.

February 23, 2022 33 ECE201-Lec1


IF STATEMENT.

February 23, 2022 34 ECE201-Lec1


IF STATEMENT.

February 23, 2022 35 ECE201-Lec1


IF STATEMENT.

February 23, 2022 36 ECE201-Lec1


IF STATEMENT. (ASSIGNMENTS)

February 23, 2022 37 ECE201-Lec1


IF STATEMENT.

February 23, 2022 38 ECE201-Lec1


FOR LOOP.

February 23, 2022 39 ECE201-Lec1


FOR LOOP.

February 23, 2022 40 ECE201-Lec1


WHILE LOOP.

February 23, 2022 41 ECE201-Lec1


DO WHILE LOOP.

February 23, 2022 42 ECE201-Lec1


DO WHILE LOOP.

February 23, 2022 43 ECE201-Lec1


BREAK LOOP.

February 23, 2022 44 ECE201-Lec1


BREAK LOOP.

February 23, 2022 45 ECE201-Lec1


BREAK LOOP.

February 23, 2022 46 ECE201-Lec1


SWITCH CASE.

February 23, 2022 47 ECE201-Lec1


SWITCH CASE.

February 23, 2022 48 ECE201-Lec1


SWITCH CASE.

February 23, 2022 49 ECE201-Lec1


SWITCH CASE.

February 23, 2022 50 ECE201-Lec1


Goto.

February 23, 2022 51 ECE201-Lec1


Goto.

February 23, 2022 52 ECE201-Lec1

You might also like