SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
C_Programming
Part 2
ENG. KEROLES SHENOUDA
1
2
Features of C
- Simple, versatile, general purpose language
- Programs are fast and efficient
- Has got rich set of operators
- more general and has no restrictions
- can easily manipulates with bits, bytes and addresses
- Varieties of data types are available
- separate compilation of functions is possible and such functions can be called
by any C program
- block-structured language
- Can be applied in System programming areas like operating systems, compilers
& Interpreters, Assemblers etc.,
3
Variable Name 4
Comments
 Sometimes programmers need
to add some notes beside their
code. Those notes are very
important to describe the code
and to clarify complex operation.
Notes or comments can be
added in two ways as shown in
the following example.
5
Data Types 6
Primitive/Basic TypesDerived
User Defined
enum typedef
Arrays
structure union
pointer Integer ValuesReal Values
signedunsigned
Integer Values 7
long long 8 –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
unsigned long long 8 0 to 18,446,744,073,709,551,615
Unsigned Integer
0 >>> (2 -1)
size_in_bits
Signed Integer
-(2)
(size_in_bits-1)
>>> +(2 -1)
(size_in_bits-1)
For example “char” 8
For example if the Unsigned charvalue uses one byte (8 bits) to
hold the numeric value:
Another example if the Signed char value uses one byte (8 bits)
to hold the numeric
value. If Tow‟s Complement method is used to represent the
negative values:
For example “char” 9
For example if the Unsigned short value uses one byte (16 bits)
to hold the numeric value:
Another example if the Signed Integer value uses four byte (32 bits) to hold
the numeric
value. If Tow‟s Complement method is used to represent the negative values:
Note
int, this data type called the machine dependent data type, which means its
size and range
vary from a machine type to another machine type (EX: in 8 bit computers int
is 1 byte, in
16 bit computers int is 2 bytes, in 32 bit computers int is 4 bytes, in 64 bit
computers int is 8
bytes).
Know that (32 Bits computers) means the principle data unit size in those
computers are 32
bit, which mean the computer is designed and optimized to process 32 bit
values
10
Floating-Point Types
Type Storage size Value range Precision
float 4 byte 1.2E-38 to
3.4E+38
6 decimal
places
double 8 byte 2.3E-308 to
1.7E+308
15 decimal
places
long double 10 byte 3.4E-4932 to
1.1E+4932
19 decimal
places
11
IEEE-754 32-bit Single-Precision
Floating-Point Numbers
 In 32-bit single-precision floating-point representation:
 The most significant bit is the sign bit (S), with 0 for positive numbers and 1 for
negative numbers.
 The following 8 bits represent exponent (E).
 The remaining 23 bits represents fraction (F).
12
Example 1: Suppose that IEEE-754 32-bit floating-point representation
pattern is 0 10000000 110 0000 0000 0000 0000 0000.
 Sign bit S = 0 ⇒ positive number
 E = 1000 0000B = 128D (in normalized form)
 Fraction is 1.11B (with an implicit leading 1) = 1 + 1×2^-1 + 1×2^-2 = 1.75D
 The number is +1.75 × 2^(128-127) = +3.5D
13
Example 2: Suppose that IEEE-754 32-bit floating-point representation
pattern is 1 01111110 100 0000 0000 0000 0000 0000.
 Sign bit S = 1 ⇒ negative number
 E = 0111 1110B = 126D (in normalized form)
 Fraction is 1.1B (with an implicit leading 1) = 1 + 2^-1 = 1.5D
 The number is -1.5 × 2^(126-127) = -0.75D
14
2′s Complement 15
C Programming Input Output (I/O):
printf() and scanf()
 C programming has several in-built library functions to perform input and
output tasks.
 Two commonly used functions for I/O (Input/Output) are printf() and scanf().
 The scanf() function reads formatted input from standard input (keyboard)
whereas the printf() function sends formatted output to the standard output
(screen).
16
Input Output 17
Eclipse's terminal emulator issue with
scanf()
 Eclipse's terminal emulator
might be different and do
more buffering. Try calling
fflush(stdout); between the
printout and the call to
scanf().
18
C Floats Input/Output 19
int printf( const char* format, ... );%
c
s
d
i
o
x
X
u
f
F
e
E
g
G
*
%10s
%-10s
.4s
20
%
writes a single character.
writes a single character.
converts a signed integer into decimal
converts a unsigned integer into octal representation
converts an unsigned integer into hexadecimal representation
converts an unsigned integer into decimal representation
converts floating-point number to the decimal notation
converts floating-point number to the decimal “Scientific”
converts floating-point number to
"Special values
Take from , …..
Shift 10-string’s length places then print the string
Print the string then shift to 10-string’s length places
Print only 4 char from string
int printf( const char* format, ... ); 21
Quiz 22
Quiz 23
24
25
Printf
Tricks
26
Solution 27
28
Data Conversion and Type Casting 29
Data Conversion and Type Casting 30
Data Conversion and Type Casting 31
 The conversion from larger to smaller data
types may lead to some data losses. For that
reason the compiler warns you against this
type of operation. However sometimes the
conversion does not affect the data like the
second expression (b = y). Compiler is not able
to
differentiate between safe or unsafe situation,
for that reason you must use the type casting
to force the conversion if you decide that it is
safe.
Mathematical and Logical Expressions 32
Mathematical and Logical Expressions 33
Mathematical and Logical Expressions 34
Coding Convention
 Coding convention is a set of rules that enhance the readability and the
understandability of
the code. At the end of each chapter a list of standard and related coding
convention is
mentioned.
35
Coding Convention 36
Generally following roles must be obeyed to
write an arranged code.
37
Follow Chapter 2:
Controlling Program
Flow
C PROGRAMMING FOR ENGINEERS, DR. MOHAMED SOBH
38
References 39
 The Case for Learning C as Your First Programming Language
 A Tutorial on Data Representation
 std::printf, std::fprintf, std::sprintf, std::snprintf…..
 C Programming for Engineers, Dr. Mohamed Sobh

Contenu connexe

Tendances

SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...
SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...
SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...Embitel Technologies (I) PVT LTD
 
Diagnostic in Adaptive AUTOSAR
Diagnostic in Adaptive AUTOSARDiagnostic in Adaptive AUTOSAR
Diagnostic in Adaptive AUTOSARBernhard Wagner
 
Autosar fundamental
Autosar fundamentalAutosar fundamental
Autosar fundamentalOmkar Rane
 
Model based design-Hardware in loop-software in loop
Model based design-Hardware in loop-software in loopModel based design-Hardware in loop-software in loop
Model based design-Hardware in loop-software in loopMahmoud Hussein
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Keroles karam khalil
 
What is AUTOSAR MCAL? Learn about the software module architecture and device...
What is AUTOSAR MCAL? Learn about the software module architecture and device...What is AUTOSAR MCAL? Learn about the software module architecture and device...
What is AUTOSAR MCAL? Learn about the software module architecture and device...Embitel Technologies (I) PVT LTD
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Keroles karam khalil
 
Autosar basics by ARCCORE
Autosar basics by ARCCOREAutosar basics by ARCCORE
Autosar basics by ARCCOREARCCORE
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Keroles karam khalil
 
Under the Hood: Model-Based Development in the Automotive Industry by Darren ...
Under the Hood: Model-Based Development in the Automotive Industry by Darren ...Under the Hood: Model-Based Development in the Automotive Industry by Darren ...
Under the Hood: Model-Based Development in the Automotive Industry by Darren ...Jordi Cabot
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Keroles karam khalil
 

Tendances (20)

SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...
SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...
SEooC ISO 26262 | What is Safety Element Out of Context in Automotive Functio...
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Diagnostic in Adaptive AUTOSAR
Diagnostic in Adaptive AUTOSARDiagnostic in Adaptive AUTOSAR
Diagnostic in Adaptive AUTOSAR
 
UDS Protocol Stack | Manual Guide | Fact Sheet
UDS Protocol Stack | Manual Guide | Fact SheetUDS Protocol Stack | Manual Guide | Fact Sheet
UDS Protocol Stack | Manual Guide | Fact Sheet
 
Autosar fundamental
Autosar fundamentalAutosar fundamental
Autosar fundamental
 
Model based design-Hardware in loop-software in loop
Model based design-Hardware in loop-software in loopModel based design-Hardware in loop-software in loop
Model based design-Hardware in loop-software in loop
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
 
AUToSAR introduction
AUToSAR introductionAUToSAR introduction
AUToSAR introduction
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
What is AUTOSAR MCAL? Learn about the software module architecture and device...
What is AUTOSAR MCAL? Learn about the software module architecture and device...What is AUTOSAR MCAL? Learn about the software module architecture and device...
What is AUTOSAR MCAL? Learn about the software module architecture and device...
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
Autosar basics by ARCCORE
Autosar basics by ARCCOREAutosar basics by ARCCORE
Autosar basics by ARCCORE
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
 
Under the Hood: Model-Based Development in the Automotive Industry by Darren ...
Under the Hood: Model-Based Development in the Automotive Industry by Darren ...Under the Hood: Model-Based Development in the Automotive Industry by Darren ...
Under the Hood: Model-Based Development in the Automotive Industry by Darren ...
 
Autosar MCAL (Microcontroller Abstraction Layer)
Autosar MCAL (Microcontroller Abstraction Layer)Autosar MCAL (Microcontroller Abstraction Layer)
Autosar MCAL (Microcontroller Abstraction Layer)
 
Misra c
Misra cMisra c
Misra c
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Automative basics v3
Automative basics v3Automative basics v3
Automative basics v3
 

En vedette (20)

Microcontroller part 9_v1
Microcontroller part 9_v1Microcontroller part 9_v1
Microcontroller part 9_v1
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Microcontroller part 8_v1
Microcontroller part 8_v1Microcontroller part 8_v1
Microcontroller part 8_v1
 
Microcontroller part 6_v1
Microcontroller part 6_v1Microcontroller part 6_v1
Microcontroller part 6_v1
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Microcontroller part 7_v1
Microcontroller part 7_v1Microcontroller part 7_v1
Microcontroller part 7_v1
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Notes part1
Notes part1Notes part1
Notes part1
 
Microcontroller part 5
Microcontroller part 5Microcontroller part 5
Microcontroller part 5
 
C programming part2
C programming part2C programming part2
C programming part2
 
First session quiz
First session quizFirst session quiz
First session quiz
 
Homework 2
Homework 2Homework 2
Homework 2
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
K vector embedded_linux_workshop
K vector embedded_linux_workshopK vector embedded_linux_workshop
K vector embedded_linux_workshop
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
C programming session3
C programming  session3C programming  session3
C programming session3
 

Similaire à C programming part2

Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Lcdf4 chap 03_p2
Lcdf4 chap 03_p2Lcdf4 chap 03_p2
Lcdf4 chap 03_p2ozgur_can
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Development of a static code analyzer for detecting errors of porting program...
Development of a static code analyzer for detecting errors of porting program...Development of a static code analyzer for detecting errors of porting program...
Development of a static code analyzer for detecting errors of porting program...PVS-Studio
 
Ch12- instruction sets- char & funct.pdf
Ch12- instruction sets- char & funct.pdfCh12- instruction sets- char & funct.pdf
Ch12- instruction sets- char & funct.pdfsaimawarsi
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuEstelaJeffery653
 
DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...
DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...
DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...jmicro
 
Introduction to computer architecture .pptx
Introduction to computer architecture .pptxIntroduction to computer architecture .pptx
Introduction to computer architecture .pptxFatma Sayed Ibrahim
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
DOUBLE PRECISION FLOATING POINT CORE IN VERILOG
DOUBLE PRECISION FLOATING POINT CORE IN VERILOGDOUBLE PRECISION FLOATING POINT CORE IN VERILOG
DOUBLE PRECISION FLOATING POINT CORE IN VERILOGIJCI JOURNAL
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)IJERD Editor
 

Similaire à C programming part2 (20)

Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Lcdf4 chap 03_p2
Lcdf4 chap 03_p2Lcdf4 chap 03_p2
Lcdf4 chap 03_p2
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C programming language
C programming languageC programming language
C programming language
 
Development of a static code analyzer for detecting errors of porting program...
Development of a static code analyzer for detecting errors of porting program...Development of a static code analyzer for detecting errors of porting program...
Development of a static code analyzer for detecting errors of porting program...
 
Theory1&2
Theory1&2Theory1&2
Theory1&2
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
Ch12- instruction sets- char & funct.pdf
Ch12- instruction sets- char & funct.pdfCh12- instruction sets- char & funct.pdf
Ch12- instruction sets- char & funct.pdf
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
 
DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...
DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...
DESIGN OF DOUBLE PRECISION FLOATING POINT MULTIPLICATION ALGORITHM WITH VECTO...
 
Introduction to computer architecture .pptx
Introduction to computer architecture .pptxIntroduction to computer architecture .pptx
Introduction to computer architecture .pptx
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
DOUBLE PRECISION FLOATING POINT CORE IN VERILOG
DOUBLE PRECISION FLOATING POINT CORE IN VERILOGDOUBLE PRECISION FLOATING POINT CORE IN VERILOG
DOUBLE PRECISION FLOATING POINT CORE IN VERILOG
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)International Journal of Engineering Research and Development (IJERD)
International Journal of Engineering Research and Development (IJERD)
 
C material
C materialC material
C material
 

Plus de Keroles karam khalil (16)

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
Notes part7
Notes part7Notes part7
Notes part7
 
Homework 5
Homework 5Homework 5
Homework 5
 
Notes part6
Notes part6Notes part6
Notes part6
 
Homework 4 solution
Homework 4 solutionHomework 4 solution
Homework 4 solution
 
Notes part5
Notes part5Notes part5
Notes part5
 
Homework 4
Homework 4Homework 4
Homework 4
 
Homework 3 solution
Homework 3 solutionHomework 3 solution
Homework 3 solution
 
C programming session5
C programming  session5C programming  session5
C programming session5
 

Dernier

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Dernier (20)

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

C programming part2

  • 2. 2
  • 3. Features of C - Simple, versatile, general purpose language - Programs are fast and efficient - Has got rich set of operators - more general and has no restrictions - can easily manipulates with bits, bytes and addresses - Varieties of data types are available - separate compilation of functions is possible and such functions can be called by any C program - block-structured language - Can be applied in System programming areas like operating systems, compilers & Interpreters, Assemblers etc., 3
  • 5. Comments  Sometimes programmers need to add some notes beside their code. Those notes are very important to describe the code and to clarify complex operation. Notes or comments can be added in two ways as shown in the following example. 5
  • 6. Data Types 6 Primitive/Basic TypesDerived User Defined enum typedef Arrays structure union pointer Integer ValuesReal Values signedunsigned
  • 7. Integer Values 7 long long 8 –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 unsigned long long 8 0 to 18,446,744,073,709,551,615 Unsigned Integer 0 >>> (2 -1) size_in_bits Signed Integer -(2) (size_in_bits-1) >>> +(2 -1) (size_in_bits-1)
  • 8. For example “char” 8 For example if the Unsigned charvalue uses one byte (8 bits) to hold the numeric value: Another example if the Signed char value uses one byte (8 bits) to hold the numeric value. If Tow‟s Complement method is used to represent the negative values:
  • 9. For example “char” 9 For example if the Unsigned short value uses one byte (16 bits) to hold the numeric value: Another example if the Signed Integer value uses four byte (32 bits) to hold the numeric value. If Tow‟s Complement method is used to represent the negative values:
  • 10. Note int, this data type called the machine dependent data type, which means its size and range vary from a machine type to another machine type (EX: in 8 bit computers int is 1 byte, in 16 bit computers int is 2 bytes, in 32 bit computers int is 4 bytes, in 64 bit computers int is 8 bytes). Know that (32 Bits computers) means the principle data unit size in those computers are 32 bit, which mean the computer is designed and optimized to process 32 bit values 10
  • 11. Floating-Point Types Type Storage size Value range Precision float 4 byte 1.2E-38 to 3.4E+38 6 decimal places double 8 byte 2.3E-308 to 1.7E+308 15 decimal places long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places 11
  • 12. IEEE-754 32-bit Single-Precision Floating-Point Numbers  In 32-bit single-precision floating-point representation:  The most significant bit is the sign bit (S), with 0 for positive numbers and 1 for negative numbers.  The following 8 bits represent exponent (E).  The remaining 23 bits represents fraction (F). 12
  • 13. Example 1: Suppose that IEEE-754 32-bit floating-point representation pattern is 0 10000000 110 0000 0000 0000 0000 0000.  Sign bit S = 0 ⇒ positive number  E = 1000 0000B = 128D (in normalized form)  Fraction is 1.11B (with an implicit leading 1) = 1 + 1×2^-1 + 1×2^-2 = 1.75D  The number is +1.75 × 2^(128-127) = +3.5D 13
  • 14. Example 2: Suppose that IEEE-754 32-bit floating-point representation pattern is 1 01111110 100 0000 0000 0000 0000 0000.  Sign bit S = 1 ⇒ negative number  E = 0111 1110B = 126D (in normalized form)  Fraction is 1.1B (with an implicit leading 1) = 1 + 2^-1 = 1.5D  The number is -1.5 × 2^(126-127) = -0.75D 14
  • 16. C Programming Input Output (I/O): printf() and scanf()  C programming has several in-built library functions to perform input and output tasks.  Two commonly used functions for I/O (Input/Output) are printf() and scanf().  The scanf() function reads formatted input from standard input (keyboard) whereas the printf() function sends formatted output to the standard output (screen). 16
  • 18. Eclipse's terminal emulator issue with scanf()  Eclipse's terminal emulator might be different and do more buffering. Try calling fflush(stdout); between the printout and the call to scanf(). 18
  • 20. int printf( const char* format, ... );% c s d i o x X u f F e E g G * %10s %-10s .4s 20 % writes a single character. writes a single character. converts a signed integer into decimal converts a unsigned integer into octal representation converts an unsigned integer into hexadecimal representation converts an unsigned integer into decimal representation converts floating-point number to the decimal notation converts floating-point number to the decimal “Scientific” converts floating-point number to "Special values Take from , ….. Shift 10-string’s length places then print the string Print the string then shift to 10-string’s length places Print only 4 char from string
  • 21. int printf( const char* format, ... ); 21
  • 24. 24
  • 25. 25
  • 28. 28
  • 29. Data Conversion and Type Casting 29
  • 30. Data Conversion and Type Casting 30
  • 31. Data Conversion and Type Casting 31  The conversion from larger to smaller data types may lead to some data losses. For that reason the compiler warns you against this type of operation. However sometimes the conversion does not affect the data like the second expression (b = y). Compiler is not able to differentiate between safe or unsafe situation, for that reason you must use the type casting to force the conversion if you decide that it is safe.
  • 32. Mathematical and Logical Expressions 32
  • 33. Mathematical and Logical Expressions 33
  • 34. Mathematical and Logical Expressions 34
  • 35. Coding Convention  Coding convention is a set of rules that enhance the readability and the understandability of the code. At the end of each chapter a list of standard and related coding convention is mentioned. 35
  • 37. Generally following roles must be obeyed to write an arranged code. 37
  • 38. Follow Chapter 2: Controlling Program Flow C PROGRAMMING FOR ENGINEERS, DR. MOHAMED SOBH 38
  • 39. References 39  The Case for Learning C as Your First Programming Language  A Tutorial on Data Representation  std::printf, std::fprintf, std::sprintf, std::snprintf…..  C Programming for Engineers, Dr. Mohamed Sobh