0% found this document useful (0 votes)
11 views50 pages

Lecture 1

Uploaded by

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

Lecture 1

Uploaded by

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

‫كلية تكنولوجيا الصناعة والطاقة‬

PEARSON BTEC International Standards Verifier


ICT Program
q
Programming Essentials in C (ICT121)
Dr. Ghada Maher
Lec. 1 Introduction to C Programming November 2023
Aim ‫كلية تكنولوجيا الصناعة والطاقة‬

The aim of the course is to:


● familiarize the student with the universal concepts of
computer programming,
● present the syntax, semantics and basic data types of
the C language.
● discuss the customs and vocabulary of the C
language, including the most common library functions
and the usage of the pre-processor
Learning Outcomes ‫كلية تكنولوجيا الصناعة والطاقة‬

By the end of this unit students will be able to:


• Understanding foundation concepts of programming and
information processing in computer systems.
• Applying the C programming fundamentals, and flow
control.
• Implement C programs using function, pointers, arrays,
and structures for problem-solving.
‫كلية تكنولوجيا الصناعة والطاقة‬

Lo1 Understanding foundation concepts of programming


and information processing in computer systems.

▪ Introduction to compiling and software development


▪ Apply Basic scalar data types and their operators.
▪ Understand the main concepts and the significant advantage of digitization
▪ Develop an Algorithm, Pseudocode , and flowchart of program to solve a problem.
▪ Understand main concepts of programming
Outline ‫كلية تكنولوجيا الصناعة والطاقة‬

In this Lecture, you’ll learn


■To write simple computer programs in C.
■To use simple input and output statements.
■To use the fundamental data types.
■Computer memory concepts.
■To use arithmetic operators.
■The precedence of arithmetic operators.
■To write simple decision-making statements.
‫كلية تكنولوجيا الصناعة والطاقة‬

1.1 Introduction

The C language facilitates a structured and disciplined


approach to computer program design. In this chapter
we introduce C programming and present several
examples that illustrate many important features of C.
‫كلية تكنولوجيا الصناعة والطاقة‬
C – A Middle Level Language
In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the
publication of The C Programming Language by Kernighan &
Ritchie caused a revolution in the computing world
1.2 Why use C? ‫كلية تكنولوجيا الصناعة والطاقة‬

• Mainly because it produces code that runs nearly as fast


as code written in assembly language. Some examples
of the use of C might be:
• Operating Systems
• Language Compilers
• Assemblers
• Text Editors
• Data Bases
• Language Interpreters
1.3 Terminologies of ‘C’ ‫كلية تكنولوجيا الصناعة والطاقة‬

1. Keywords
2. Identifiers
3. Variables
4. Constants
5. Special Symbols
6. Character & String
7. Operators
1.3.1 Keywords ‫كلية تكنولوجيا الصناعة والطاقة‬

• Keywords are the reserved words whose meaning has


already been explained to the C compiler.
• C has 32 keywords.
• These keywords combined with a formal syntax form a C
programming language.
• Rules to be followed for all programs written in C:
• All keywords are lower-cased.
• C is case sensitive, do-while is different from DO WHILE.
• Keywords cannot be used as a variable or function name.
‫كلية تكنولوجيا الصناعة والطاقة‬
‫‪C’s keywords.‬‬
1.3.2 Identifiers ‫كلية تكنولوجيا الصناعة والطاقة‬

• Identifiers refer to the name of variables, functions and


arrays.
• These are user-defined names and consist of sequence
of letters and digits, with a letter as a first character.
• Both uppercase and lowercase letters are permitted,
although lowercase letters are commonly used.
• The underscore character is also permitted in identifiers.
It is usually used as a link between two words in long
identifiers.
‫كلية تكنولوجيا الصناعة والطاقة‬
1.3.2 Identifier Names

Some correct identifier names are -


arena, s_count
marks40
class_one

Some erroneous identifier names are -


1stsst
oh!god
start….end

The number of characters in the variable that are


X
recognized differs from compiler to compiler
An identifier cannot be the same as a C keyword
1.3.3 Variables ‫كلية تكنولوجيا الصناعة والطاقة‬

• Variables are named locations in memory that are used to hold a


value that may be modified by the program.
• Unlike constants that remain unchanged during the execution of
a program.
• A variable may take different values at different times during
execution.
• The syntax for declaring a variable is –
DataType IdentifierName ;
• Example- int num;
long int sum , a;
‫كلية تكنولوجيا الصناعة والطاقة‬

1.3.3 Variables
Fundamental Data
Types
‫كلية تكنولوجيا الصناعة والطاقة‬

Memory location showing the name and value of a variable.


Whenever a value is placed in a memory location, the value
replaces the previous value in that location; thus, placing a new
value into a memory location is said to be destructive.
1.3.4 Constants ‫كلية تكنولوجيا‬
‫الصناعة والطاقة‬
• Constants are the fixed values that do not change during
the execution of a program.
• C supports several types of constants.
• Numeric Constants
• Integer constants
• Real constants
• Character Constants
• Single character constant
• String Constants
‫كلية تكنولوجيا الصناعة والطاقة‬

1.3.5. Special Symbols


• ! , @, #, $ , & , * , ….. These all symbols that can be find on
Keyboard, are called Special Symbols.

• Every symbol has its special meaning in different respect at


different place that’s why it is called Special Symbols.
1.3.6. Character & String ‫كلية تكنولوجيا الصناعة والطاقة‬

• The Characters that can be used to form words, numbers and


expressions depend upon the computer on which the program is
running.
• The characters in C are grouped into the following categories :
• Letters
• Digits
• Special characters
• White Spaces
• Remember that a character ‘a’ is not equivalent to the string “a”.
‫كلية تكنولوجيا الصناعة والطاقة‬

1.2 A Simple C Program: Printing a Line of Text C

Outputs
‫كلية تكنولوجيا الصناعة والطاقة‬

Program Development Life Cycle


‫كلية تكنولوجيا الصناعة والطاقة‬

Typical C
Program
Development
Environment

C systems
generally consist
of several parts
‫كلية تكنولوجيا الصناعة والطاقة‬

‫‪Outputs‬‬
‫كلية تكنولوجيا الصناعة والطاقة‬
‫‪Outputs‬‬
Simple input and output statements ‫كلية تكنولوجيا الصناعة والطاقة‬
‫كلية تكنولوجيا الصناعة والطاقة‬
1.3.7. Operators
• Operator is a symbol that operates on one or more operands and
produces output.

Example - z=x+y;

• In the above Example the symbols + and = are operators that operate
on operands x, y , and z .
‫كلية تكنولوجيا الصناعة والطاقة‬
1.3.7. Operators
An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions. C language is rich in built-in operators
and provides the
• following types of operators:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Misc Operators
• We will, in this chapter, look into the way each operator works.
Arithmetic Operators: ‫كلية تكنولوجيا الصناعة والطاقة‬
Precedence of arithmetic operators.
‫كلية تكنولوجيا الصناعة والطاقة‬

‫‪Outputs‬‬
Arithmetic Operators: Example ‫كلية تكنولوجيا الصناعة والطاقة‬

outputs
‫كلية تكنولوجيا الصناعة والطاقة‬
Suppose variables a, b, c
and x in the preceding
second-degree
polynomial are
initialized as follows:
a=2, b=3, c=7 and x=5

Evaluate
Relational Operators ‫كلية تكنولوجيا الصناعة والطاقة‬
The following table shows all the relational operators supported
by C. Assume variable A holds 10 and variable B holds 20, then:
Logical Operators ‫كلية تكنولوجيا الصناعة والطاقة‬

Following table shows all the logical operators supported by C


language. Assume variable A holds 1 and variable B holds 0,
then:
‫‪Bitwise Operators‬‬ ‫كلية تكنولوجيا الصناعة والطاقة‬
‫كلية تكنولوجيا الصناعة والطاقة‬
• Assume A = 60 and B = 13; in binary format,
they will be as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
‫كلية تكنولوجيا الصناعة والطاقة‬

The following table lists


the bitwise operators
supported by C. Assume
variable ‘A’ holds 60 and
variable ‘B’ holds 13,
then:
‫كلية تكنولوجيا الصناعة والطاقة‬
‫كلية تكنولوجيا الصناعة والطاقة‬
‫‪Assignment‬‬
‫كلية تكنولوجيا الصناعة والطاقة‬
‫‪Operators‬‬
‫كلية تكنولوجيا الصناعة والطاقة‬
‫كلية تكنولوجيا الصناعة والطاقة‬
‫‪Misc Operators‬‬ ‫كلية تكنولوجيا الصناعة والطاقة‬
Execution Process of a Program ‫كلية تكنولوجيا الصناعة والطاقة‬

PROCESS SHORT CUT FILE NAME

Save F2 abc.c
Compile Alt + F9 abc.obj

Execute Ctrl + F9 abc.exe

Back up Again F2 abc.bak


‫كلية تكنولوجيا الصناعة والطاقة‬

Some of Escape Sequence

\n new line
\t tab
\\ backslash
\” double quote
‫كلية تكنولوجيا الصناعة والطاقة‬
Simple decision-making statements
Syntax of Conditional/Ternary Operator in C
variable = Expression1 ? Expression2 : Expression3;
Or the syntax can also be in this form
variable = (condition) ? Expression2 : Expression3;
Or syntax can also be in this form
(condition) ? (variable = Expression2) : (variable = Expression3);
‫كلية تكنولوجيا الصناعة والطاقة‬
Working of Conditional/Ternary Operator in C
The working of the conditional operator in C is as follows:
•Step 1: Expression1 is the condition to be evaluated.
•Step 2A: If the condition(Expression1) is True
then Expression2 will be executed.
•Step 2B: If the condition(Expression1) is false
then Expression3 will be executed.
•Step 3: Results will be returned.
Example : C Program to Store the greatest of the two ‫كلية تكنولوجيا الصناعة والطاقة‬

Numbers using the ternary operator

Output:
m is greater than n that is 5 > 4
‫كلية تكنولوجيا الصناعة والطاقة‬
Classroom Assignment
Write a program to evaluate the following equation.

Assign a=5, x=2.

Equation1 = 𝑎𝑥 2 + 6
Equation2 = 𝑎 ∗ 𝑥 + 𝑎/𝑥 2 + 6
Online C Compiler ‫كلية تكنولوجيا الصناعة والطاقة‬

https://www.onlinegdb.com/online_c_compiler
https://www.tutorialspoint.com/compile_c_online.php
https://onecompiler.com/c
https://www.jdoodle.com/c-online-compiler/
‫كلية تكنولوجيا الصناعة والطاقة‬

‫‪Thank‬‬
‫‪q‬‬
‫‪you‬‬

You might also like