SlideShare a Scribd company logo
M E H W I S H M E H M O O D
• A function is a group of statements that together perform
a task. Every C program has at least one function, which
is main(), and all the most trivial programs can define
additional functions.
• You can divide up your code into separate functions.
How you divide up your code among different functions
is up to you, but logically the division usually is so each
function performs a specific task.
A function in C can have a value, a side
effect, or both
• The side effect occurs before the value is returned.
• The function’s value is the value of the expression in the
return statement.
• A function can be called for its value, its side effect, or both.
• The general syntax of a function in C is :
• The type_specifier specifies the data type of the value, which
the function will return.
• A valid function name is to be assigned to identify the
function
• Arguments appearing in parentheses are also termed as
formal parameters.
//Prototype declaration
void greeting();
int main()
{
greeting();
return 0;
} // main
Void greeting()
{
printf(“HELLO WORLD”);
return ;
} //greeting()
Declaration
is coded
first
Definition is
after the call
Call is in the
statement
sections
The type of the expression in the return
statement must match the return type in the
function header.
. Only one value can be returned by a
function
• Formal parameters are variables that are declared in the header of
the function definition.
• Actual parameters are the expressions in the calling statement.
• The formal and actual parameters must match exactly in type, order,
and number. Their names, however, do not need to be the same.
int square(int x);
Int main()
{
Int I
For(i=1;i<10; i++)
{
printf(“n square of %d is %d:”, i, square(i));
}
int square(int x)
{
int j;
j=x*x;
return(j);
}
Actual
argument
Formal
argument
• Scope Rules - Rules that govern whether one piece of
code knows about or has access to another piece of
code or data
• The code within a function is private or local to that
function
• Two functions have different scopes
• One function cannot be defined within another function
 Call by value
 Call by reference
 When arguments are
passed to the called
function, the values
are passed through
temporary variables
• In call by
reference, the
function is
allowed access
to the actual
memory
location of the
argument and
therefore can
change the
value of the
arguments of
the calling
routine
main()
{
.
.
palindrome();
.
.
}
palindrome()
{
.
.
getstr();
reverse();
cmp();
.
.
}
• A pointer variable can be passed as a parameter to a function
either by value or by reference.
• In the function pointer Parameters, both p and q are pointers.
The parameter p is a reference parameter; the parameter q is
a value parameter.
• Furthermore, the function pointer Parameters can change the
value of *q, but not the value of q. However, the function
pointer Parameters can change the value of both p and *p.
functions in C
functions in C

More Related Content

What's hot

C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
Dharma Kshetri
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
khush_boo31
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functionsvinay arora
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
 
C# programs
C# programsC# programs
C# programs
Syed Mustafa
 
Pointers in C language
Pointers  in  C languagePointers  in  C language
Pointers in C language
Infinity Tech Solutions
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
HNDE Labuduwa Galle
 
Function overloading
Function overloadingFunction overloading
Function overloading
Sudeshna Biswas
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
Md. Imran Hossain Showrov
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operatorSAFFI Ud Din Ahmad
 
Header files in c
Header files in cHeader files in c
Header files in c
HoneyChintal
 
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C ProgrammingLecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
Md. Imran Hossain Showrov
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
Md. Imran Hossain Showrov
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
Mohammed Saleh
 

What's hot (20)

C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
 
Functions
FunctionsFunctions
Functions
 
This pointer
This pointerThis pointer
This pointer
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
C Prog - Functions
C Prog - FunctionsC Prog - Functions
C Prog - Functions
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
C# programs
C# programsC# programs
C# programs
 
Pointers in C language
Pointers  in  C languagePointers  in  C language
Pointers in C language
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 
18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator18 dec pointers and scope resolution operator
18 dec pointers and scope resolution operator
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C ProgrammingLecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 

Viewers also liked

Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
Mehwish Mehmood
 
Functions in c
Functions in cFunctions in c
Functions in c
Innovative
 
Intro to cprogramming
Intro to cprogrammingIntro to cprogramming
Intro to cprogramming
skashwin98
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
Mahmoud Masih Tehrani
 
GO programming language
GO programming languageGO programming language
GO programming language
tung vu
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
sgpraju
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
Dilum Bandara
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
2014 Mitsubishi Lancer in Baltimore, Maryland
2014 Mitsubishi Lancer in Baltimore, Maryland2014 Mitsubishi Lancer in Baltimore, Maryland
2014 Mitsubishi Lancer in Baltimore, Maryland
Jerry's Mitsubishi
 
Presentation onc in roman 1
Presentation onc in roman 1Presentation onc in roman 1
Presentation onc in roman 1Jose Duarte
 
Noosagoals elevator pitch
Noosagoals   elevator pitchNoosagoals   elevator pitch
Noosagoals elevator pitch
noosagoals
 
SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components
Patrick Sheridan
 
2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland
2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland
2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, MarylandJerry's Mitsubishi
 
Work in progress
Work in progressWork in progress
Work in progressPaolo Casti
 

Viewers also liked (19)

Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Intro to cprogramming
Intro to cprogrammingIntro to cprogramming
Intro to cprogramming
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
GO programming language
GO programming languageGO programming language
GO programming language
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
2014 Mitsubishi Lancer in Baltimore, Maryland
2014 Mitsubishi Lancer in Baltimore, Maryland2014 Mitsubishi Lancer in Baltimore, Maryland
2014 Mitsubishi Lancer in Baltimore, Maryland
 
Risiko
RisikoRisiko
Risiko
 
BRIC
BRICBRIC
BRIC
 
Presentation onc in roman 1
Presentation onc in roman 1Presentation onc in roman 1
Presentation onc in roman 1
 
Noosagoals elevator pitch
Noosagoals   elevator pitchNoosagoals   elevator pitch
Noosagoals elevator pitch
 
SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components SenchaCon: Sencha Touch Custom Components
SenchaCon: Sencha Touch Custom Components
 
2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland
2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland
2012 Mitsubishi Eclipse at Jerry's Mitsubishi in Baltimore, Maryland
 
Work in progress
Work in progressWork in progress
Work in progress
 
Passécom
PassécomPassécom
Passécom
 
Rvrsit
RvrsitRvrsit
Rvrsit
 
HTML5 and Sencha Touch
HTML5 and Sencha TouchHTML5 and Sencha Touch
HTML5 and Sencha Touch
 

Similar to functions in C

358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
sumitbardhan
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
Functions
FunctionsFunctions
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
ManiMala75
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
LadallaRajKumar
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
GebruGetachew2
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
RAJ KUMAR
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
Function
FunctionFunction
Function
Saniati
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
Bharath904863
 
Function
Function Function
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
Functions
Functions Functions
Functions
Dr.Subha Krishna
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
NirmalaShinde3
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
Ashim Lamichhane
 
C functions list
C functions listC functions list

Similar to functions in C (20)

358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Functions
FunctionsFunctions
Functions
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Function
FunctionFunction
Function
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Function
Function Function
Function
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
Functions
Functions Functions
Functions
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
C functions list
C functions listC functions list
C functions list
 

Recently uploaded

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

functions in C

  • 1. M E H W I S H M E H M O O D
  • 2. • A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. • You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is so each function performs a specific task.
  • 3. A function in C can have a value, a side effect, or both • The side effect occurs before the value is returned. • The function’s value is the value of the expression in the return statement. • A function can be called for its value, its side effect, or both.
  • 4.
  • 5. • The general syntax of a function in C is : • The type_specifier specifies the data type of the value, which the function will return. • A valid function name is to be assigned to identify the function • Arguments appearing in parentheses are also termed as formal parameters.
  • 6. //Prototype declaration void greeting(); int main() { greeting(); return 0; } // main Void greeting() { printf(“HELLO WORLD”); return ; } //greeting() Declaration is coded first Definition is after the call Call is in the statement sections
  • 7.
  • 8. The type of the expression in the return statement must match the return type in the function header. . Only one value can be returned by a function
  • 9. • Formal parameters are variables that are declared in the header of the function definition. • Actual parameters are the expressions in the calling statement. • The formal and actual parameters must match exactly in type, order, and number. Their names, however, do not need to be the same.
  • 10. int square(int x); Int main() { Int I For(i=1;i<10; i++) { printf(“n square of %d is %d:”, i, square(i)); } int square(int x) { int j; j=x*x; return(j); } Actual argument Formal argument
  • 11. • Scope Rules - Rules that govern whether one piece of code knows about or has access to another piece of code or data • The code within a function is private or local to that function • Two functions have different scopes • One function cannot be defined within another function
  • 12.  Call by value  Call by reference
  • 13.  When arguments are passed to the called function, the values are passed through temporary variables
  • 14. • In call by reference, the function is allowed access to the actual memory location of the argument and therefore can change the value of the arguments of the calling routine
  • 15.
  • 17.
  • 18. • A pointer variable can be passed as a parameter to a function either by value or by reference. • In the function pointer Parameters, both p and q are pointers. The parameter p is a reference parameter; the parameter q is a value parameter. • Furthermore, the function pointer Parameters can change the value of *q, but not the value of q. However, the function pointer Parameters can change the value of both p and *p.