SlideShare uma empresa Scribd logo
1 de 59
Baixar para ler offline
C_Programming
Part 7
ENG. KEROLES SHENOUDA
1
Macros Vs Functions
No Macro Function
1 Macro is Preprocessed Function is Compiled
2 No Type Checking Type Checking is Done
3 Code Length Increases Code Length remains Same
–
5 Speed of Execution is
Faster
Speed of Execution is Slower
6 Before Compilation macro name
is replaced by macro value
During function call , Transfer
of Control takes place
7 Useful where small code
appears many time
Useful where large code
appears many time
8 Generally Macros do not extend
beyond one line
Function can be of any number
of lines
2
ANSI C
 ANSI C, ISO C and Standard C refer to the successive standards for the C programming
language published by the American National Standards Institute (ANSI) and
the International Organization for Standardization (ISO). Historically, the names referred
specifically to the original and best-supported version of the standard (known as C89 or C90).
Software developers writing in C are encouraged to conform to the standards, as doing so
aids portability between compilers.
 C89
 C90
 C95
 C99
3
Preprocessor Test for C95 compatibility 4
Constant in C
 constant can be used to represent as fixed values in a C program
 Constants refers to the fixed values that do not change during the execution
of a program
5
1.const float pie =3.147;
2.const int radius =4;
3.const char c = 'A';
4.const char name[] = “C Course";
Constant using const keyword C
programming:
 When declaring a const variable, it is possible to put const either before or
after the type: that is, both
int const a= 15;
Or
const int x= 15;
6
Declare constant
 const keyword are used for declare a constant.
7
gives error
you can't modify const
8
Structure in C
 Structure is a user defined data type which hold or store heterogeneous data item
or element in a singe variable. It is a Combination of primitive and derived data
type.
 Why Use Structure in C
 In C language array is also a user defined data type but array hold or store only similar
type of data, If we want to store different-different type of data in then we need to
defined separate variable for each type of data.
 Example: Suppose we want to store Student record, then we need to store....
 Student Name
 Roll number
 Class
 Address
9
Why Use Structure in C Example [without Structure] 10
It is clear that code size is
huge with respect to the
problem complexity.
Also the storage of
the single employee
information in different
arrays complicates
many operations like
entering, sorting and
printing
 Structures are used to collect related variables in one place. In this example all employee
information can gathered in one place. This will simplify any further operation over the
collected data, because all information items are treated as a single entity, called a
Structure.
Following format is used to define an employee structure, which is used to collect all
employee information in one place.
11
Structure 12
Structure is a complex data type consisting of a set of members/attributes. Each attribute
can have any data type. It can be int, float, short…its. It can be single value or array. It can
be const or variable. Also, structures may hold another structure (nested structure).
Programmers are free to define as many structures as the program required. Each structure
must be labeled with a unique label called Structure Name.
Structure Name can be used as a new data type, it can be used to define variables, it can be used to define
arrays and it can be passed to a functions.
Defining and Using Structure Variables 13
In above example a variable X is defined from the data type
(SEmployee). (X) variable
contains the following members (m_Name,
m_BirthDateYear,
m_BirthDateMonth, m_BirthDateDay, m_Salary).
In this example a values is
assigned to each member of (X) variable, then all members‟
values is printed.
Copying Structure Variable Contents to
another Variable
14
Employee Sort with Structures
Sort with Ages
15
Employee
Sort with
Structures
Sort with
Ages
16
The code
(SEmployee
employees[
100]) means
that defining
an array of 100
variable
of type
(struct
SEmployee)
Employee Sort with Structures
Sort with Ages
17
Employee Sort with Structures
Sort with Ages
18
With Structure Vs without Structure 19
Initializing Structure Variables 20
Nested Structure Definition
As mentioned before, it is applicable to define structure members with any data type, even
other structures type.
Structure
21
Nested Structure
Nested Structure 22
Employee Sort with Nested Structures 23
Employee
Sort with
Nested
Structures
24
Employee Sort with Nested Structures 25
Employee Sort with Nested Structures 26
Using Structures with Functions
Read and Print Employee and Date Values using Functions
27
Using
Structures
with
Functions
Read and Print
Employee and
Date Values
using Functions
28
Using
Structures
with
Functions
Read and Print
Employee and
Date Values
using Functions
29
Write A program Adding Two Complex
Numbers using Structure And Function
30
31
32
33
enum
 An enumeration is a user-defined data type that consists of integral constants.
To define an enumeration, keyword enum is used.
34
Here, name of the enumeration is flag.
And, const1, const2,...., constN are values of type flag.
By default, const1 is 0, const2 is 1 and so on. You can change default values of enum elements
during declaration (if necessary).
Enumerated Type Declaration
 When you create an enumerated type, only blueprint for the variable is
created. Here's how you can create variables of enum type.
 Here, a variable check of type enum boolean is created.
 Here is another way to declare same check variable using different syntax.
35
Example: Enumeration Type 36
output
Why enums are used in C programming?
 1. Enum variable takes only one value out of many possible
values. Example to demonstrate it,
37
It's because the size of an integer is 4 bytes.
This makes enum a good choice to work with flags.
You can accomplish the same task using structures.
However, working with enums gives you efficiency along
with flexibility.
Why enums are used in C programming?
 More readable Here, we have added italics to our design. Note,
only code for italics is written inside if statement.
38
You can accomplish
almost anything in C
programming
without using
enumerations.
However, they can
be pretty handy in
certain situations.
That's what
differentiates good
programmers from
great programmers.
Example: Personal Data using Enum 39
Unions 40
Using Union
41
 Following example illustrates how to combine the three data types (int, float, double) in one
overlapped data type. Programmer is responsible on supplying and retrieving the data
correctly. If integer data is supplied, integer data must be retrieved.
42
43
44
Difference between union and structure 45
Difference
between
union and
structure
The primary
difference can be
demonstrated by
this example:
46
Difference between union and structure
The primary difference can be demonstrated by this example:
 1. More memory is allocated to structures than union
 The amount of memory required to store a structure variable is the sum of memory
size of all members.
 But, the memory required to store a union variable is the memory required for the
largest element of an union.
2. Only one union member can be accessed at a time
47
Scope/Lifetime
 Variable “scope” refers to part of the program
that may access the variable
▫ Local, global, etc…
• Variable “lifetime” refers to time in which a
variable occupies memory
• Both determined by how and where variable is
defined
48
Storage classes
 In C language, each variable has a storage class which decides scope, visibility
and lifetime of that variable. The following storage classes are most oftenly
used in C programming,
 Automatic variables
 External variables
 Static variables
 Register variables

49
Automatic variables
 A variable declared inside a function without any storage class specification, is by
default an automatic variable. They are created when a function is called and are
destroyed automatically when the function exits. Automatic variables can also be
called local variables because they are local to a function. By default they are
assigned garbage value by the compiler.
50
External or Global variable
 A variable that is declared outside any function is a Global
variable. Global variables remain available throughout the entire program.
One important thing to remember about global variable is that their values
can be changed by any function in the program.
51
Here the global variable number is available to all three
functions.
extern keyword
The extern keyword is used before a variable to inform the compiler that this
variable is declared somewhere else.
The extern declaration does not allocate storage for variables.
52
Problem when extern is not used 53
Example Using extern in same file 54
Static variables
 A static variable tells the compiler to persist the variable until the end of
program. Instead of creating and destroying a variable every time when it
comes into and goes out of scope, static is initialized only once and remains
into existence till the end of program. A static variable can either be internal or
external depending upon the place of declaraction. Scope of internal
static variable remains inside the function in which it is defined. External
static variables remain restricted to scope of file in each they are declared.
 They are assigned 0 (zero) as default value by the compiler.
55
Static variables 56
Register variable
 Register variable inform the compiler to store the variable in register instead
of memory. Register variable has faster access than normal variable.
Frequently used variables are kept in register. Only few variables can be
placed inside register.
 NOTE : We can never get the address of such variables.
 Syntax :
57
Volatile Type Qualifier 58
References 59
 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
 C programming expert.
 fresh2refresh.com/c-programming
 C programming Interview questions and answers
 C – Preprocessor directives

Mais conteúdo relacionado

Mais procurados

Mais procurados (18)

Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 
Embedded c
Embedded cEmbedded c
Embedded c
 
C programming part2
C programming part2C programming part2
C programming part2
 
Notes part 8
Notes part 8Notes part 8
Notes part 8
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
First session quiz
First session quizFirst session quiz
First session quiz
 
C language
C languageC language
C language
 
Fortran introduction
Fortran introductionFortran introduction
Fortran introduction
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Fortran 95
Fortran 95Fortran 95
Fortran 95
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
C language (Collected By Dushmanta)
C language  (Collected By Dushmanta)C language  (Collected By Dushmanta)
C language (Collected By Dushmanta)
 
Fortran 90 Basics
Fortran 90 BasicsFortran 90 Basics
Fortran 90 Basics
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
programming fortran 77 Slide01
programming fortran 77 Slide01programming fortran 77 Slide01
programming fortran 77 Slide01
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 

Destaque (20)

Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
K vector embedded_linux_workshop
K vector embedded_linux_workshopK vector embedded_linux_workshop
K vector embedded_linux_workshop
 
Automative basics v3
Automative basics v3Automative basics v3
Automative basics v3
 
C programming part4
C programming part4C programming part4
C programming part4
 
Microcontroller part 5
Microcontroller part 5Microcontroller part 5
Microcontroller part 5
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part4
C programming part4C programming part4
C programming part4
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
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
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
Microcontroller part 8_v1
Microcontroller part 8_v1Microcontroller part 8_v1
Microcontroller part 8_v1
 
Microcontroller part 9_v1
Microcontroller part 9_v1Microcontroller part 9_v1
Microcontroller part 9_v1
 
Microcontroller part 6_v1
Microcontroller part 6_v1Microcontroller part 6_v1
Microcontroller part 6_v1
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 

Semelhante a C programming session7

C basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaC basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaManoj Kumar kothagulla
 
Library management system
Library management systemLibrary management system
Library management systemSHARDA SHARAN
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE jatin batra
 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...Rowank2
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDFSuraj Das
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language Rowank2
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Introduction to c
Introduction to cIntroduction to c
Introduction to cAjeet Kumar
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++TemplatesGanesh Samarthyam
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diarySHARDA SHARAN
 

Semelhante a C programming session7 (20)

Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
C basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaC basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kella
 
Library management system
Library management systemLibrary management system
Library management system
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
Unit 1
Unit  1Unit  1
Unit 1
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
Pc module1
Pc module1Pc module1
Pc module1
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
C Language
C LanguageC Language
C Language
 
Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 

Mais de Keroles karam khalil

Mais de Keroles karam khalil (20)

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
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
 
C programming session7
C programming  session7C programming  session7
C programming session7
 

Último

Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
(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
 
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
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
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 to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
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
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 

Último (20)

Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
(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...
 
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
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
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 to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
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...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 

C programming session7

  • 2. Macros Vs Functions No Macro Function 1 Macro is Preprocessed Function is Compiled 2 No Type Checking Type Checking is Done 3 Code Length Increases Code Length remains Same – 5 Speed of Execution is Faster Speed of Execution is Slower 6 Before Compilation macro name is replaced by macro value During function call , Transfer of Control takes place 7 Useful where small code appears many time Useful where large code appears many time 8 Generally Macros do not extend beyond one line Function can be of any number of lines 2
  • 3. ANSI C  ANSI C, ISO C and Standard C refer to the successive standards for the C programming language published by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO). Historically, the names referred specifically to the original and best-supported version of the standard (known as C89 or C90). Software developers writing in C are encouraged to conform to the standards, as doing so aids portability between compilers.  C89  C90  C95  C99 3
  • 4. Preprocessor Test for C95 compatibility 4
  • 5. Constant in C  constant can be used to represent as fixed values in a C program  Constants refers to the fixed values that do not change during the execution of a program 5 1.const float pie =3.147; 2.const int radius =4; 3.const char c = 'A'; 4.const char name[] = “C Course";
  • 6. Constant using const keyword C programming:  When declaring a const variable, it is possible to put const either before or after the type: that is, both int const a= 15; Or const int x= 15; 6
  • 7. Declare constant  const keyword are used for declare a constant. 7 gives error you can't modify const
  • 8. 8
  • 9. Structure in C  Structure is a user defined data type which hold or store heterogeneous data item or element in a singe variable. It is a Combination of primitive and derived data type.  Why Use Structure in C  In C language array is also a user defined data type but array hold or store only similar type of data, If we want to store different-different type of data in then we need to defined separate variable for each type of data.  Example: Suppose we want to store Student record, then we need to store....  Student Name  Roll number  Class  Address 9
  • 10. Why Use Structure in C Example [without Structure] 10 It is clear that code size is huge with respect to the problem complexity. Also the storage of the single employee information in different arrays complicates many operations like entering, sorting and printing
  • 11.  Structures are used to collect related variables in one place. In this example all employee information can gathered in one place. This will simplify any further operation over the collected data, because all information items are treated as a single entity, called a Structure. Following format is used to define an employee structure, which is used to collect all employee information in one place. 11
  • 12. Structure 12 Structure is a complex data type consisting of a set of members/attributes. Each attribute can have any data type. It can be int, float, short…its. It can be single value or array. It can be const or variable. Also, structures may hold another structure (nested structure). Programmers are free to define as many structures as the program required. Each structure must be labeled with a unique label called Structure Name. Structure Name can be used as a new data type, it can be used to define variables, it can be used to define arrays and it can be passed to a functions.
  • 13. Defining and Using Structure Variables 13 In above example a variable X is defined from the data type (SEmployee). (X) variable contains the following members (m_Name, m_BirthDateYear, m_BirthDateMonth, m_BirthDateDay, m_Salary). In this example a values is assigned to each member of (X) variable, then all members‟ values is printed.
  • 14. Copying Structure Variable Contents to another Variable 14
  • 15. Employee Sort with Structures Sort with Ages 15
  • 16. Employee Sort with Structures Sort with Ages 16 The code (SEmployee employees[ 100]) means that defining an array of 100 variable of type (struct SEmployee)
  • 17. Employee Sort with Structures Sort with Ages 17
  • 18. Employee Sort with Structures Sort with Ages 18
  • 19. With Structure Vs without Structure 19
  • 21. Nested Structure Definition As mentioned before, it is applicable to define structure members with any data type, even other structures type. Structure 21 Nested Structure
  • 23. Employee Sort with Nested Structures 23
  • 25. Employee Sort with Nested Structures 25
  • 26. Employee Sort with Nested Structures 26
  • 27. Using Structures with Functions Read and Print Employee and Date Values using Functions 27
  • 28. Using Structures with Functions Read and Print Employee and Date Values using Functions 28
  • 29. Using Structures with Functions Read and Print Employee and Date Values using Functions 29
  • 30. Write A program Adding Two Complex Numbers using Structure And Function 30
  • 31. 31
  • 32. 32
  • 33. 33
  • 34. enum  An enumeration is a user-defined data type that consists of integral constants. To define an enumeration, keyword enum is used. 34 Here, name of the enumeration is flag. And, const1, const2,...., constN are values of type flag. By default, const1 is 0, const2 is 1 and so on. You can change default values of enum elements during declaration (if necessary).
  • 35. Enumerated Type Declaration  When you create an enumerated type, only blueprint for the variable is created. Here's how you can create variables of enum type.  Here, a variable check of type enum boolean is created.  Here is another way to declare same check variable using different syntax. 35
  • 37. Why enums are used in C programming?  1. Enum variable takes only one value out of many possible values. Example to demonstrate it, 37 It's because the size of an integer is 4 bytes. This makes enum a good choice to work with flags. You can accomplish the same task using structures. However, working with enums gives you efficiency along with flexibility.
  • 38. Why enums are used in C programming?  More readable Here, we have added italics to our design. Note, only code for italics is written inside if statement. 38 You can accomplish almost anything in C programming without using enumerations. However, they can be pretty handy in certain situations. That's what differentiates good programmers from great programmers.
  • 39. Example: Personal Data using Enum 39
  • 41. Using Union 41  Following example illustrates how to combine the three data types (int, float, double) in one overlapped data type. Programmer is responsible on supplying and retrieving the data correctly. If integer data is supplied, integer data must be retrieved.
  • 42. 42
  • 43. 43
  • 44. 44
  • 45. Difference between union and structure 45
  • 46. Difference between union and structure The primary difference can be demonstrated by this example: 46
  • 47. Difference between union and structure The primary difference can be demonstrated by this example:  1. More memory is allocated to structures than union  The amount of memory required to store a structure variable is the sum of memory size of all members.  But, the memory required to store a union variable is the memory required for the largest element of an union. 2. Only one union member can be accessed at a time 47
  • 48. Scope/Lifetime  Variable “scope” refers to part of the program that may access the variable ▫ Local, global, etc… • Variable “lifetime” refers to time in which a variable occupies memory • Both determined by how and where variable is defined 48
  • 49. Storage classes  In C language, each variable has a storage class which decides scope, visibility and lifetime of that variable. The following storage classes are most oftenly used in C programming,  Automatic variables  External variables  Static variables  Register variables  49
  • 50. Automatic variables  A variable declared inside a function without any storage class specification, is by default an automatic variable. They are created when a function is called and are destroyed automatically when the function exits. Automatic variables can also be called local variables because they are local to a function. By default they are assigned garbage value by the compiler. 50
  • 51. External or Global variable  A variable that is declared outside any function is a Global variable. Global variables remain available throughout the entire program. One important thing to remember about global variable is that their values can be changed by any function in the program. 51 Here the global variable number is available to all three functions.
  • 52. extern keyword The extern keyword is used before a variable to inform the compiler that this variable is declared somewhere else. The extern declaration does not allocate storage for variables. 52
  • 53. Problem when extern is not used 53
  • 54. Example Using extern in same file 54
  • 55. Static variables  A static variable tells the compiler to persist the variable until the end of program. Instead of creating and destroying a variable every time when it comes into and goes out of scope, static is initialized only once and remains into existence till the end of program. A static variable can either be internal or external depending upon the place of declaraction. Scope of internal static variable remains inside the function in which it is defined. External static variables remain restricted to scope of file in each they are declared.  They are assigned 0 (zero) as default value by the compiler. 55
  • 57. Register variable  Register variable inform the compiler to store the variable in register instead of memory. Register variable has faster access than normal variable. Frequently used variables are kept in register. Only few variables can be placed inside register.  NOTE : We can never get the address of such variables.  Syntax : 57
  • 59. References 59  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  C programming expert.  fresh2refresh.com/c-programming  C programming Interview questions and answers  C – Preprocessor directives