SlideShare a Scribd company logo
Function
Khandana ali khan
Date: 25, April 2019
Function
• A large C program is divided into basic building blocks called C
function.
• Modules in C are called functions.
• A function is a group of statements that together perform a task.
• Every C program has at least one function, which is main()
• 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 is such that each function performs a specific task.
• Reduce the complexity
• Reusability
Hierarchical function
Types of Function
• In C Programming there are two types of c functions
1. Standard function
• A function which is predefined in c programming is called a standard
function. main() , printf (), scanf() functions are standard function
2. User-defined function
• User-defined function are the functions which are defined by the user
C FUNCTION DECLARATION, FUNCTION CALL AND
FUNCTION DEFINITION
• There are 3 aspects in each C function.
1. Function declaration or prototype
– This informs compiler about the function name, function parameters
and return value’s data type.
2. Function call
– This calls the actual function
3. Function definition
– This contains all the statements to be executed.
C function Syntax
C functions aspects Syntax
function definition Return_type function_name (arguments list)
{ Body of function; }
function call function_name (arguments list);
function declaration return_type function_name (argument list);
Parameters
1. Actual parameter
– This is the argument which is used in function call.
2. Formal parameter
• – This is the argument which is used in function definition
Function program
• #include <stdio.h>
• int square( int y ); // function prototype
• int main()
• {
• int x; // counter
• // loop 10 times and calculate and output square of x each time
• for ( x = 1; x <= 10; ++x )
• {
• printf( "%d ", square( x )
• ); // function call
• } // end for
• printf( "" );
}
• // square function definition returns the square of its parameter
• int square( int y ) // y is a copy of the argument to the function
• {
• return y * y; // returns the square of y as an int
• } // end function square
Types of Function / C Argument, return value
• C function with arguments (parameters) and with return value.
• C function with arguments (parameters) and without return value.
• C function without arguments (parameters) and without return value.
• C function without arguments (parameters) and with return value
HOW TO CALL C FUNCTIONS IN A PROGRAM?
• There are two ways that a C function can be called from a program. They are,
1. CALL BY VALUE:
• In call by value method, the value of the variable is passed to the function as parameter.
• The value of the actual parameter can not be modified by formal parameter.
• Different Memory is allocated for both actual and formal parameters. Because, value of actual parameter is
copied to formal parameter.
2.CALL BY REFERENCE:
• In call by reference method, the address of the variable is passed to the function as parameter.
• The value of the actual parameter can be modified by formal parameter.
• Same memory is used for both actual and formal parameters since only address is used by both
parameters.
Call by Value
• #include <stdio.h>
• void swap(int x, int y); /* function declaration */
• int main () {
• int a = 100; /* local variable definition */
• int b = 200;
• printf("Before swap, value of a : %dn", a );
• printf("Before swap, value of b : %dn", b );
• /* calling a function to swap the values */
• swap(a, b);
• printf("After swap, value of a : %dn", a );
• printf("After swap, value of b : %dn", b );
• return 0; }
• /* function definition to swap the values */
• void swap(int x, int y) {
• int temp;
• temp = x; /* save the value of x */
• x = y; /* put y into x */
• y = temp; /* put temp into y */
• return; }
Call by Reference
• #include <stdio.h>
• void swap(int *x, int *y); /* function declaration */
• int main (){
• int a = 100; /* local variable definition */
• int b = 200;
• printf("Before swap, value of a : %dn", a );
• printf("Before swap, value of b : %dn", b );
• /* calling a function to swap the values.
• * &a indicates pointer to a i.e. address of variable a and
• * &b indicates pointer to b i.e. address of variable b.
• */
• swap(&a, &b);
• printf("After swap, value of a : %dn", a );
• printf("After swap, value of b : %dn", b );
• return 0;
• }/* function definition to swap the values */
• void swap(int *x, int *y)
• {
• int temp;
• temp = *x; /* save the value at address x */
• *x = *y; /* put y into x */
• *y = temp; /* put temp into y */
• Return;
• }
• /* function definition to swap the values */
• void swap(int x, int y)
• {
• int temp;
• temp = x; /* save the value of x */
• x = y; /* put y into x */
• y = temp; /* put temp into y */
• return;
• }
• #include <stdio.h>
• /* function declaration */
• void swap(int x, int y);
• int main ()
• {
• /* local variable definition */
• int a = 100;
• int b = 200;
• printf("Before swap, value of a : %dn", a );
• printf("Before swap, value of b : %dn", b );
• /* calling a function to swap the values */
• swap(a, b);
• printf("After swap, value of a : %dn", a );
• printf("After swap, value of b : %dn", b );
• return 0;
• }

More Related Content

What's hot (20)

Call by value
Call by valueCall by value
Call by value
Dharani G
 
lets play with "c"..!!! :):)
lets play with "c"..!!! :):)lets play with "c"..!!! :):)
lets play with "c"..!!! :):)
Rupendra Choudhary
 
Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++Lecture#7 Call by value and reference in c++
Lecture#7 Call by value and reference in c++
NUST Stuff
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
NUST Stuff
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
Ritika Sharma
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
kavitha muneeshwaran
 
Function C++
Function C++ Function C++
Function C++
Shahzad Afridi
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Function & Recursion in C
Function & Recursion in CFunction & Recursion in C
Function & Recursion in C
Aditya Nihal Kumar Singh
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
Vishalini Mugunen
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
 
Function
FunctionFunction
Function
jayesh30sikchi
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
sunila tharagaturi
 
Function in c
Function in cFunction in c
Function in c
CGC Technical campus,Mohali
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 

Similar to Function (rule in programming) (20)

Detailed concept of function in c programming
Detailed concept of function  in c programmingDetailed concept of function  in c programming
Detailed concept of function in c programming
anjanasharma77573
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
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
 
C functions by ranjan call by value and reference.pptx
C functions by ranjan call by value and reference.pptxC functions by ranjan call by value and reference.pptx
C functions by ranjan call by value and reference.pptx
ranjan317165
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
programlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jgprogramlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
MKalpanaDevi
 
C functions
C functionsC functions
C functions
University of Potsdam
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
Venkatesh Goud
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
vekariyakashyap
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
JVenkateshGoud
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
Amarjith C K
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
SandipPradhan23
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
RAJ KUMAR
 
Principals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdfPrincipals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
 
c-Functions power point presentation on c functions
c-Functions power point presentation on c functionsc-Functions power point presentation on c functions
c-Functions power point presentation on c functions
10300PEDDIKISHOR
 
Detailed concept of function in c programming
Detailed concept of function  in c programmingDetailed concept of function  in c programming
Detailed concept of function in c programming
anjanasharma77573
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
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
 
C functions by ranjan call by value and reference.pptx
C functions by ranjan call by value and reference.pptxC functions by ranjan call by value and reference.pptx
C functions by ranjan call by value and reference.pptx
ranjan317165
 
programlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jgprogramlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
MKalpanaDevi
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
vekariyakashyap
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
SandipPradhan23
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
RAJ KUMAR
 
Principals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdfPrincipals of Programming in CModule -5.pdfModule-3.pdf
Principals of Programming in CModule -5.pdfModule-3.pdf
anilcsbs
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
 
c-Functions power point presentation on c functions
c-Functions power point presentation on c functionsc-Functions power point presentation on c functions
c-Functions power point presentation on c functions
10300PEDDIKISHOR
 
Ad

More from Unviersity of balochistan quetta (10)

Most difficult language presentation
Most difficult language presentationMost difficult language presentation
Most difficult language presentation
Unviersity of balochistan quetta
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
Unviersity of balochistan quetta
 
computer basics
computer basicscomputer basics
computer basics
Unviersity of balochistan quetta
 
Time management
Time managementTime management
Time management
Unviersity of balochistan quetta
 
Memory (psychology)
Memory (psychology)Memory (psychology)
Memory (psychology)
Unviersity of balochistan quetta
 
Motivation
MotivationMotivation
Motivation
Unviersity of balochistan quetta
 
Introduction to psychology
Introduction to psychologyIntroduction to psychology
Introduction to psychology
Unviersity of balochistan quetta
 
Chapter 2 seven_cs
Chapter 2 seven_csChapter 2 seven_cs
Chapter 2 seven_cs
Unviersity of balochistan quetta
 
Sensation and perception.pptm
Sensation and perception.pptmSensation and perception.pptm
Sensation and perception.pptm
Unviersity of balochistan quetta
 
Data type
Data typeData type
Data type
Unviersity of balochistan quetta
 
Ad

Recently uploaded (20)

প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Writing Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research CommunityWriting Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research Community
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT PatnaSwachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Swachata Quiz - Prelims - 01.10.24 - Quiz Club IIT Patna
Quiz Club, Indian Institute of Technology, Patna
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Types of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo SlidesTypes of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo Slides
Celine George
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANASTUDENT LOAN TRUST FUND DEFAULTERS GHANA
STUDENT LOAN TRUST FUND DEFAULTERS GHANA
Kweku Zurek
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...Stewart Butler - OECD - How to design and deliver higher technical education ...
Stewart Butler - OECD - How to design and deliver higher technical education ...
EduSkills OECD
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
Odoo 18 Point of Sale PWA - Odoo Slides
Odoo 18 Point of Sale PWA  - Odoo  SlidesOdoo 18 Point of Sale PWA  - Odoo  Slides
Odoo 18 Point of Sale PWA - Odoo Slides
Celine George
 
Types of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo SlidesTypes of Actions in Odoo 18 - Odoo Slides
Types of Actions in Odoo 18 - Odoo Slides
Celine George
 
How to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo SlidesHow to Use Owl Slots in Odoo 17 - Odoo Slides
How to Use Owl Slots in Odoo 17 - Odoo Slides
Celine George
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
"Orthoptera: Grasshoppers, Crickets, and Katydids pptx
Arshad Shaikh
 
Order Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptxOrder Lepidoptera: Butterflies and Moths.pptx
Order Lepidoptera: Butterflies and Moths.pptx
Arshad Shaikh
 

Function (rule in programming)

  • 2. Function • A large C program is divided into basic building blocks called C function. • Modules in C are called functions. • A function is a group of statements that together perform a task. • Every C program has at least one function, which is main() • 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 is such that each function performs a specific task. • Reduce the complexity • Reusability
  • 4. Types of Function • In C Programming there are two types of c functions 1. Standard function • A function which is predefined in c programming is called a standard function. main() , printf (), scanf() functions are standard function 2. User-defined function • User-defined function are the functions which are defined by the user
  • 5. C FUNCTION DECLARATION, FUNCTION CALL AND FUNCTION DEFINITION • There are 3 aspects in each C function. 1. Function declaration or prototype – This informs compiler about the function name, function parameters and return value’s data type. 2. Function call – This calls the actual function 3. Function definition – This contains all the statements to be executed.
  • 6. C function Syntax C functions aspects Syntax function definition Return_type function_name (arguments list) { Body of function; } function call function_name (arguments list); function declaration return_type function_name (argument list);
  • 7. Parameters 1. Actual parameter – This is the argument which is used in function call. 2. Formal parameter • – This is the argument which is used in function definition
  • 8. Function program • #include <stdio.h> • int square( int y ); // function prototype • int main() • { • int x; // counter • // loop 10 times and calculate and output square of x each time • for ( x = 1; x <= 10; ++x ) • { • printf( "%d ", square( x ) • ); // function call • } // end for • printf( "" ); } • // square function definition returns the square of its parameter • int square( int y ) // y is a copy of the argument to the function • { • return y * y; // returns the square of y as an int • } // end function square
  • 9. Types of Function / C Argument, return value • C function with arguments (parameters) and with return value. • C function with arguments (parameters) and without return value. • C function without arguments (parameters) and without return value. • C function without arguments (parameters) and with return value
  • 10. HOW TO CALL C FUNCTIONS IN A PROGRAM? • There are two ways that a C function can be called from a program. They are, 1. CALL BY VALUE: • In call by value method, the value of the variable is passed to the function as parameter. • The value of the actual parameter can not be modified by formal parameter. • Different Memory is allocated for both actual and formal parameters. Because, value of actual parameter is copied to formal parameter. 2.CALL BY REFERENCE: • In call by reference method, the address of the variable is passed to the function as parameter. • The value of the actual parameter can be modified by formal parameter. • Same memory is used for both actual and formal parameters since only address is used by both parameters.
  • 11. Call by Value • #include <stdio.h> • void swap(int x, int y); /* function declaration */ • int main () { • int a = 100; /* local variable definition */ • int b = 200; • printf("Before swap, value of a : %dn", a ); • printf("Before swap, value of b : %dn", b ); • /* calling a function to swap the values */ • swap(a, b); • printf("After swap, value of a : %dn", a ); • printf("After swap, value of b : %dn", b ); • return 0; } • /* function definition to swap the values */ • void swap(int x, int y) { • int temp; • temp = x; /* save the value of x */ • x = y; /* put y into x */ • y = temp; /* put temp into y */ • return; }
  • 12. Call by Reference • #include <stdio.h> • void swap(int *x, int *y); /* function declaration */ • int main (){ • int a = 100; /* local variable definition */ • int b = 200; • printf("Before swap, value of a : %dn", a ); • printf("Before swap, value of b : %dn", b ); • /* calling a function to swap the values. • * &a indicates pointer to a i.e. address of variable a and • * &b indicates pointer to b i.e. address of variable b. • */ • swap(&a, &b); • printf("After swap, value of a : %dn", a ); • printf("After swap, value of b : %dn", b ); • return 0; • }/* function definition to swap the values */ • void swap(int *x, int *y) • { • int temp; • temp = *x; /* save the value at address x */ • *x = *y; /* put y into x */ • *y = temp; /* put temp into y */ • Return; • }
  • 13. • /* function definition to swap the values */ • void swap(int x, int y) • { • int temp; • temp = x; /* save the value of x */ • x = y; /* put y into x */ • y = temp; /* put temp into y */ • return; • } • #include <stdio.h> • /* function declaration */ • void swap(int x, int y); • int main () • { • /* local variable definition */ • int a = 100; • int b = 200; • printf("Before swap, value of a : %dn", a ); • printf("Before swap, value of b : %dn", b ); • /* calling a function to swap the values */ • swap(a, b); • printf("After swap, value of a : %dn", a ); • printf("After swap, value of b : %dn", b ); • return 0; • }