SlideShare a Scribd company logo
With/Mohamed Fawzy
Quick Review for C basics
1 Day #1
2
Lecture Notes:
 Set your phone to vibration mode.
 Ask any time.
 During labs feel free to check any materials or internet.
3
Contents
 History of C programming language.
 Introduction to C programming language.
 Variables and data types.
 Expressions and operators.
 Decision making.
 Hands ON.
4
Contents
4
 History of C programming language.
 Introduction to C programming language.
 Variables and data types.
 Expressions and operators.
 Decision making.
 Hands ON.
C Programming History:
 In 1969, Dennis Ritchie and Ken Thompson at “AT&T”
labs (Bell Labs).
 C came into being in the years 1969-1973, in parallel
with the early development of the Unix operating
system.
 To make UNIX operating system portable.
5
Why C in Embedded Systems?
6
Next program structure.
 C is very close to assembly programming and it allows very easy access
to underlying hardware. A huge number of high quality compilers and
debugging tools are available for the C language.
 Though C++ is theoretically more efficient than C, but some of its
compilers have bugs due to the huge size of the language. These
compilers may cause a buggy execution.
 C language can definitely claim to have more mature compilers C++. Now
in order to avail the extra benefits of C++ and plus to avoid buggy
execution, experts are doing efforts to identify a subset of C++ that can be
used in embedded systems and this subset is called Embedded C++
7
8
C program Structure.
/**information about the file*/
/**includes files and libraries*/
#include <stdio.h>
#include <stdlib.h>
/**functions prototypes*/
void main();
void function1();
int main(){
//main code of the program
return 0;
}
void function1(){
//function1 code
}
NextComments.
9
Comments.
/*
……………
……………
Multi-line comment
……………..
……………..
*/
// single row comment
• Ignored by compiler.
• Can place any where.
Next#include macro.
.
10
#include macro.
•It is used to include header files in our project.
•It may include constants, functions , declarations.
•#include reads the content of header file.
•#include <header.h> searches for a header file in the include
path.
•#include “header.h” searches for a header file in the current
directory for main project.
Next Variables in C.
.
Variables in C.
 Variable names are names given to locations in memory.
 Rules for Constructing Variable Names:
oA variable name is any combination of 1 to 31 alphabets ”compiler based”
oThe first character in the variable name must be an alphabet or
underscore.
oNo commas or blanks are allowed within a variable name.
oNo special symbol other than an underscore.
Examples:
int student_num;
char _student_num;
int 22student-num;
char student,num;
int student@num;
11
Practical Advice:
It is a good practice to exploit
this enormous choice in naming
variables by using meaningful
variable names.
Next declare a variable in C.
.
How to declare a variable in C?
<Data Type> <variable name>;
<Data Type> <variable name> = <initial value>;
Examples:
//variable declaration with no initialization.
int student_num;
//variable declaration with intiial value.
char student_num=15;
//multiple variable declaration.
int num,student,id;
12
Note:
If you don't initiate the variable it will take garbage value.
Next Variables in C.
.
13
C data types:
Note:
You can use sizeof() function to
know the default size of variable.
EX:
Printf(“%d”,sizeof(int));
Practical Advice:
In E.S you should take care for
choosing the best suitable to
avoid wasting memory.
14
C data type Modifiers:
Note:
Signed modifier is the default modifier for any data type.
EX:
Signed char x=char x;
15
Type Casting.
Type casting is to put variable in different type during run time.
Example:
int main ()
{
char x;
int y;
X=(char)y;
}
Note:
Some C compilers my give warning if assigned large data types values to small
data types values without using casting.
int main ()
{
char x;
int y=40000;
x=(char)y;
printf(“%d”,y);
printf(“%d”,x);
}
Try this !!!!!!
16
printf.
To print constants :
printf(“Hello World !”);
To print variables:
Int x=50;
Float y=5.6;
Printf(“x is equal %d”,x);
Printf(“x is equal %d and y is equal %f”,x,y);
Format Specifiers:
17
scanf.
To receive an input from user:
int x;
printf(“plz enter x value”);
scanf(“%d”,&x);
Hands ON
Write a C program to print “Hello World!”
Declare to variables and ask user to assign their values.
18
Operators & Expressions.
Expression: it is a statement which an operator links identifiers.
Operators: they are some symbols that indicate to the compiler which type of
Operator is to be performed using its surrounding identifiers.
 Arithmetic Operators.
 Relational Operators.
 Logical Operators.
 Bitwise Operators.
 Assignment Operators.
19
Arithmetic Operators.
Note:
• (%) is used only with integers.
• (++) and (- -) increment or decrement by one not add or subtract one   .
Assume variable A holds 10 and variable B holds 20.
20
Example:
#include <stdio.h>
main()
{
int a = 21;
int b = 10;
int c ;
c = a + b;
printf("Line 1 - Value of c is %dn", c );
c = a - b;
printf("Line 2 - Value of c is %dn", c );
c = a * b;
printf("Line 2 - Value of c is %dn", c );
c = a % b;
printf("Line 2 - Value of c is %dn", c );
c = a++;
printf("Line 2 - Value of c is %dn", c );
printf("Line 2 - Value of c is %dn", a++);
21
Relational Operators.
Relational operators are used in decision making and loops in C programming.
Note:
• If the relation is true, it returns value 1 and if the relation is false, it returns value 0.
• Don't be confused between (=) and (==).
22
Examples:
#include <stdio.h>
main()
{
int a = 21;
int b = 10;
int c ;
if( a == b )
{
printf("Line 1 - a is equal to bn" );
}
else
{
printf("Line 2 - a is not equal to bn" );
}
}
23
Logical Operators.
Note:
Don't be confused between (&&) and (&) or (||) and (|).
24
Examples:
int a=5;
int b=6;
if (a && b) printf(“true”);
if (a || b) printf(“true”);
int x=0;
int y=5;
if(x && y++)
{
printf (“falsen”);
printf(“%d”,y);
}
Take Care!!
int x=0;
int y=5;
if(y || x++)
{
printf (“truen”);
printf(“%d”,x);
}
25
Bitwise Operators.
Bitwise operator works on bits and perform bit-by-bit operation.
26
Control single bit in Register or Byte:
 Reset one bit.
REG &=~(1<<bit_no)
PORTA &=~(1<<5)
 Toggle one bit.
REG ^=(1<<bit_no)
PORTA ^=(1<<5)
 Set one bit.
REG |=(1<<bit_no)
PORTA |=(1<<5)
Examples:
 Check one bit.
REG &=(1<<bit_no)
PORTA &=(1<<5)
27
Decision Making.
 If statement.
if (condition)
{
}
else if (condition)
{
}
else
{
}
28
Decision Making.
Switch (var)
{
Case 1:
statement;
break;
Case 1:
statement;
break;
Case 1:
statement;
break;
default:
statement;
break;
}
29
Hands ON
Email: mo7amed.fawzy33@gmail.com
Phone: 01006032792
Facebook: mo7amed_fawzy33@yahoo.com
Contact me:
30
31

More Related Content

PDF
Hands-on Introduction to the C Programming Language
PDF
C programming language
PDF
Reduce course notes class xii
ODP
C prog ppt
ODP
OpenGurukul : Language : C Programming
PDF
C Programming Tutorial - www.infomtec.com
PPTX
C programmimng basic.ppt
PPTX
C Programming Language Step by Step Part 1
Hands-on Introduction to the C Programming Language
C programming language
Reduce course notes class xii
C prog ppt
OpenGurukul : Language : C Programming
C Programming Tutorial - www.infomtec.com
C programmimng basic.ppt
C Programming Language Step by Step Part 1

What's hot (19)

PPT
C program
PPT
Introduction to c programming
PDF
Advanced C Language for Engineering
PPTX
C programming-apurbo datta
PPT
C language introduction
DOCX
Programming in c
PPSX
Complete C programming Language Course
PPT
2. data, operators, io
DOCX
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
PPTX
C Language (All Concept)
PPTX
Introduction to C Programming
DOC
Basic c
PPT
Chapter3
DOC
C notes diploma-ee-3rd-sem
PPT
C language
PPTX
Introduction to c programming language
PDF
C Programming
PDF
VTU PCD Model Question Paper - Programming in C
PPT
C program
Introduction to c programming
Advanced C Language for Engineering
C programming-apurbo datta
C language introduction
Programming in c
Complete C programming Language Course
2. data, operators, io
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C Language (All Concept)
Introduction to C Programming
Basic c
Chapter3
C notes diploma-ee-3rd-sem
C language
Introduction to c programming language
C Programming
VTU PCD Model Question Paper - Programming in C
Ad

Viewers also liked (8)

PPT
PPT
Google Summer Of Code
PPT
c-programming
PPT
computer programming C++
PPT
Lecture03
PPT
Xhtml 2010
PPT
Dynamic HTML Event Model
PDF
Project L.A.B Report
Google Summer Of Code
c-programming
computer programming C++
Lecture03
Xhtml 2010
Dynamic HTML Event Model
Project L.A.B Report
Ad

Similar to C programming day#1 (20)

PPTX
Fundamentals of Data Structures Unit 1.pptx
PPTX
Fundamental programming Nota Topic 2.pptx
DOCX
Let's us c language (sabeel Bugti)
PPTX
Programming Fundamentals
PDF
Basic Information About C language PDF
PPT
C material
PDF
C programming language tutorial for beginers.pdf
PDF
The New Yorker cartoon premium membership of the
PPTX
Each n Every topic of C Programming.pptx
PPT
C programming
PPTX
C Programming Unit-1
PDF
UNIT1 PPS of C language for first year first semester
PPTX
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
PDF
Getting Started with C Programming: A Beginner’s Guide to Syntax, Variables, ...
PPT
Lecture 01 2017
PDF
EC2311-Data Structures and C Programming
PPTX
Introduction to c
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
PDF
Learn c language Important topics ( Easy & Logical, & smart way of learning)
PPTX
presentation_c_basics_1589366177_381682.pptx
Fundamentals of Data Structures Unit 1.pptx
Fundamental programming Nota Topic 2.pptx
Let's us c language (sabeel Bugti)
Programming Fundamentals
Basic Information About C language PDF
C material
C programming language tutorial for beginers.pdf
The New Yorker cartoon premium membership of the
Each n Every topic of C Programming.pptx
C programming
C Programming Unit-1
UNIT1 PPS of C language for first year first semester
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
Getting Started with C Programming: A Beginner’s Guide to Syntax, Variables, ...
Lecture 01 2017
EC2311-Data Structures and C Programming
Introduction to c
Esoft Metro Campus - Certificate in c / c++ programming
Learn c language Important topics ( Easy & Logical, & smart way of learning)
presentation_c_basics_1589366177_381682.pptx

More from Mohamed Fawzy (12)

PDF
07 Analogue to Digital Converter(ADC).2016
PDF
06 Interfacing Keypad 4x4.2016
PDF
05 EEPROM memory.2016
PDF
04 Interfacing LCD Displays.2016
PDF
02 Interfacing High Power Devices.2016
PDF
01 GPIO||General Purpose Input Output.2016
PDF
00 let us get started.2016
PPTX
أزاى تروح فى داهيه !!!
PPTX
Ce from a to z
PDF
PDF
C programming day#2.
PDF
C programming day#3.
07 Analogue to Digital Converter(ADC).2016
06 Interfacing Keypad 4x4.2016
05 EEPROM memory.2016
04 Interfacing LCD Displays.2016
02 Interfacing High Power Devices.2016
01 GPIO||General Purpose Input Output.2016
00 let us get started.2016
أزاى تروح فى داهيه !!!
Ce from a to z
C programming day#2.
C programming day#3.

Recently uploaded (20)

PDF
737-MAX_SRG.pdf student reference guides
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
DOCX
573137875-Attendance-Management-System-original
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
Project quality management in manufacturing
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Construction Project Organization Group 2.pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Geodesy 1.pptx...............................................
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Well-logging-methods_new................
737-MAX_SRG.pdf student reference guides
Foundation to blockchain - A guide to Blockchain Tech
Model Code of Practice - Construction Work - 21102022 .pdf
Internet of Things (IOT) - A guide to understanding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
573137875-Attendance-Management-System-original
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Project quality management in manufacturing
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Construction Project Organization Group 2.pptx
III.4.1.2_The_Space_Environment.p pdffdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Geodesy 1.pptx...............................................
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
UNIT 4 Total Quality Management .pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Well-logging-methods_new................

C programming day#1

  • 1. With/Mohamed Fawzy Quick Review for C basics 1 Day #1
  • 2. 2 Lecture Notes:  Set your phone to vibration mode.  Ask any time.  During labs feel free to check any materials or internet.
  • 3. 3 Contents  History of C programming language.  Introduction to C programming language.  Variables and data types.  Expressions and operators.  Decision making.  Hands ON.
  • 4. 4 Contents 4  History of C programming language.  Introduction to C programming language.  Variables and data types.  Expressions and operators.  Decision making.  Hands ON.
  • 5. C Programming History:  In 1969, Dennis Ritchie and Ken Thompson at “AT&T” labs (Bell Labs).  C came into being in the years 1969-1973, in parallel with the early development of the Unix operating system.  To make UNIX operating system portable. 5
  • 6. Why C in Embedded Systems? 6 Next program structure.  C is very close to assembly programming and it allows very easy access to underlying hardware. A huge number of high quality compilers and debugging tools are available for the C language.  Though C++ is theoretically more efficient than C, but some of its compilers have bugs due to the huge size of the language. These compilers may cause a buggy execution.  C language can definitely claim to have more mature compilers C++. Now in order to avail the extra benefits of C++ and plus to avoid buggy execution, experts are doing efforts to identify a subset of C++ that can be used in embedded systems and this subset is called Embedded C++
  • 7. 7
  • 8. 8 C program Structure. /**information about the file*/ /**includes files and libraries*/ #include <stdio.h> #include <stdlib.h> /**functions prototypes*/ void main(); void function1(); int main(){ //main code of the program return 0; } void function1(){ //function1 code } NextComments.
  • 9. 9 Comments. /* …………… …………… Multi-line comment …………….. …………….. */ // single row comment • Ignored by compiler. • Can place any where. Next#include macro. .
  • 10. 10 #include macro. •It is used to include header files in our project. •It may include constants, functions , declarations. •#include reads the content of header file. •#include <header.h> searches for a header file in the include path. •#include “header.h” searches for a header file in the current directory for main project. Next Variables in C. .
  • 11. Variables in C.  Variable names are names given to locations in memory.  Rules for Constructing Variable Names: oA variable name is any combination of 1 to 31 alphabets ”compiler based” oThe first character in the variable name must be an alphabet or underscore. oNo commas or blanks are allowed within a variable name. oNo special symbol other than an underscore. Examples: int student_num; char _student_num; int 22student-num; char student,num; int student@num; 11 Practical Advice: It is a good practice to exploit this enormous choice in naming variables by using meaningful variable names. Next declare a variable in C. .
  • 12. How to declare a variable in C? <Data Type> <variable name>; <Data Type> <variable name> = <initial value>; Examples: //variable declaration with no initialization. int student_num; //variable declaration with intiial value. char student_num=15; //multiple variable declaration. int num,student,id; 12 Note: If you don't initiate the variable it will take garbage value. Next Variables in C. .
  • 13. 13 C data types: Note: You can use sizeof() function to know the default size of variable. EX: Printf(“%d”,sizeof(int)); Practical Advice: In E.S you should take care for choosing the best suitable to avoid wasting memory.
  • 14. 14 C data type Modifiers: Note: Signed modifier is the default modifier for any data type. EX: Signed char x=char x;
  • 15. 15 Type Casting. Type casting is to put variable in different type during run time. Example: int main () { char x; int y; X=(char)y; } Note: Some C compilers my give warning if assigned large data types values to small data types values without using casting. int main () { char x; int y=40000; x=(char)y; printf(“%d”,y); printf(“%d”,x); } Try this !!!!!!
  • 16. 16 printf. To print constants : printf(“Hello World !”); To print variables: Int x=50; Float y=5.6; Printf(“x is equal %d”,x); Printf(“x is equal %d and y is equal %f”,x,y); Format Specifiers:
  • 17. 17 scanf. To receive an input from user: int x; printf(“plz enter x value”); scanf(“%d”,&x); Hands ON Write a C program to print “Hello World!” Declare to variables and ask user to assign their values.
  • 18. 18 Operators & Expressions. Expression: it is a statement which an operator links identifiers. Operators: they are some symbols that indicate to the compiler which type of Operator is to be performed using its surrounding identifiers.  Arithmetic Operators.  Relational Operators.  Logical Operators.  Bitwise Operators.  Assignment Operators.
  • 19. 19 Arithmetic Operators. Note: • (%) is used only with integers. • (++) and (- -) increment or decrement by one not add or subtract one   . Assume variable A holds 10 and variable B holds 20.
  • 20. 20 Example: #include <stdio.h> main() { int a = 21; int b = 10; int c ; c = a + b; printf("Line 1 - Value of c is %dn", c ); c = a - b; printf("Line 2 - Value of c is %dn", c ); c = a * b; printf("Line 2 - Value of c is %dn", c ); c = a % b; printf("Line 2 - Value of c is %dn", c ); c = a++; printf("Line 2 - Value of c is %dn", c ); printf("Line 2 - Value of c is %dn", a++);
  • 21. 21 Relational Operators. Relational operators are used in decision making and loops in C programming. Note: • If the relation is true, it returns value 1 and if the relation is false, it returns value 0. • Don't be confused between (=) and (==).
  • 22. 22 Examples: #include <stdio.h> main() { int a = 21; int b = 10; int c ; if( a == b ) { printf("Line 1 - a is equal to bn" ); } else { printf("Line 2 - a is not equal to bn" ); } }
  • 23. 23 Logical Operators. Note: Don't be confused between (&&) and (&) or (||) and (|).
  • 24. 24 Examples: int a=5; int b=6; if (a && b) printf(“true”); if (a || b) printf(“true”); int x=0; int y=5; if(x && y++) { printf (“falsen”); printf(“%d”,y); } Take Care!! int x=0; int y=5; if(y || x++) { printf (“truen”); printf(“%d”,x); }
  • 25. 25 Bitwise Operators. Bitwise operator works on bits and perform bit-by-bit operation.
  • 26. 26 Control single bit in Register or Byte:  Reset one bit. REG &=~(1<<bit_no) PORTA &=~(1<<5)  Toggle one bit. REG ^=(1<<bit_no) PORTA ^=(1<<5)  Set one bit. REG |=(1<<bit_no) PORTA |=(1<<5) Examples:  Check one bit. REG &=(1<<bit_no) PORTA &=(1<<5)
  • 27. 27 Decision Making.  If statement. if (condition) { } else if (condition) { } else { }
  • 28. 28 Decision Making. Switch (var) { Case 1: statement; break; Case 1: statement; break; Case 1: statement; break; default: statement; break; }
  • 31. 31