SlideShare a Scribd company logo
C ProgrammingLanguage WorkingwithFunctions1
Agenda:
What is a Functions?
A function is a named, independent section of C code that performs a specific task and optionally returns a value
to the callingprogram
A function is named. Each function has a unique name. By usingthat name in another partof the program, you
can execute the statements contained in the function.This is known as callingthefunction. A function can be
called fromwithin another function.
A function is independent. A function can perform its task without interference from or interferingwith other
parts of the program.
A function performs a specific task. This is the easy partof the definition.A task is a discretejob that your
program must perform as partof its overall operation,such as sendinga lineof text to a printer, sortingan array
into numerical order,or calculatinga cuberoot.
function can return a value to the calling program. When your program callsa function,the statements it
contains areexecuted. If you want them to, these statements can pass information back to the callingprogram.
Benefits of the functions
program
Function Terminology
Function prototype: A function's prototype contains the name of the function,return type, a lis tof variables that
must be passed to it, and the type of variableitreturns, if any..
Function Definition: The function itself is called the function definition.The definition contains the code that will
be executed.
C ProgrammingLanguage WorkingwithFunctions2
Function header: The function header is atthe startof a function,and itgives the function's name. The header
also gives the function's return type and describes its arguments.Note that the function header is identical to the
function prototype (minus the semicolon).
Function Body: The statements written within function arecalled function body. Statements are enclosed in
braces.These statements are executed when the function is called.
Arguments: When a function is called,the program can send the function information in the form of one or more
arguments. An argument is programdata needed by the function to perform its task.Arguments are enclosed in
parentheses followingthe function's name.
Return statement: If the function return type is anythingother than void, a return statement should be included,
returning a valuematching the return type.
/* Demonstrates a simple function */
#include<stdio.h>
longcube(long x);
longinput, answer;
main()
{
printf("Enter an integer value: ");
scanf("%d", &input);
answer = cube(input); /*here input is actual argument.
/* Note: %ld is the conversion specifier for */
/* a long integer */
printf("nThe cube of %ld is %ld.n", input, answer);
return 0;
}
/* Function: cube() - Calculates thecubed valueof a variable*/
longcube(long x) /*here x is formal argument*/
{
longx_cubed;
x_cubed = x * x * x;
return x_cubed;
}
How does a Function Works
program.
C ProgrammingLanguage WorkingwithFunctions3
m of one or more arguments.
An argument is programdata needed by the function to perform its task.The statements in the function then
execute, performing whatever task each was designed to do.
sses back to the same location in the program that
called the function. Functions can send information back to the program in the form of a return value.
xecution passes
back to the placefrom which the function was called.A function can be called as many times as needed, and
functions can be called in any order.
#include<stdio.h>
void printline(char ch,intn);
int add(inta,intb,int c);
main()
{
int result;
printline('#',70);
result=add(10,3,4);
printf("n resultis %d",result);
getch();
return 0;
}
void printline(char ch,intn)
{
int i;
for(i=0;i<n;i++)
printf("%c",ch);
}
int add(inta,intb,int c)
{ C ProgrammingLanguage WorkingwithFunctions4
return a+b+c;
} /* Program to check the given value is vowel */
#include<stdio.h>
void main()
{
char ch;
printf("nEnter any character …');
ch=getch();
if(checkvowel(ch)==1)
printf("n It is a vowel");
else
printf("n try again");
}
int checkvowel(char ch)
{
if(ch=='a'||ch=='c'||ch=='i'||ch=='o'||ch=='u'||ch='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
return (1);
else
return (0);
}

More Related Content

What's hot (20)

User defined functions
User defined functionsUser defined functions
User defined functions
Rokonuzzaman Rony
 
user defined function
user defined functionuser defined function
user defined function
King Kavin Patel
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
Sampath Kumar
 
Functions
FunctionsFunctions
Functions
Online
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
Meghaj Mallick
 
Function
FunctionFunction
Function
rishabh agrawal
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
Syed Mustafa
 
Function
FunctionFunction
Function
Saniati
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
primeteacher32
 
Functions
FunctionsFunctions
Functions
PatriciaPabalan
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
baabtra.com - No. 1 supplier of quality freshers
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
Dr.Neeraj Kumar Pandey
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Maaz Hasan
 
Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Basic information of function in cpu
Basic information of function in cpuBasic information of function in cpu
Basic information of function in cpu
Dhaval Jalalpara
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
Function
FunctionFunction
Function
Rajat Patel
 

Viewers also liked (11)

South Florida Real Estate 2017 Outlook Survey
South Florida Real Estate 2017 Outlook SurveySouth Florida Real Estate 2017 Outlook Survey
South Florida Real Estate 2017 Outlook Survey
cutmytaxes
 
A non residents guide to buying property in florida
A non residents guide to buying property in  floridaA non residents guide to buying property in  florida
A non residents guide to buying property in florida
James Lavigne
 
Make It Happen Homes Listing Presentation for North Texas Real Estate
Make It Happen Homes Listing Presentation for North Texas Real EstateMake It Happen Homes Listing Presentation for North Texas Real Estate
Make It Happen Homes Listing Presentation for North Texas Real Estate
Mary Lou Jaimes
 
La Jolla Agent Listing Presentation
La Jolla Agent Listing PresentationLa Jolla Agent Listing Presentation
La Jolla Agent Listing Presentation
ProFund Real Estate, Inc.
 
Listing Presentation
Listing PresentationListing Presentation
Listing Presentation
LenneaA
 
Real Estate Listing Presentation
Real Estate Listing PresentationReal Estate Listing Presentation
Real Estate Listing Presentation
The Charlotte House Hunter Group
 
Realty Elite | Listing Presentation
Realty Elite  |  Listing PresentationRealty Elite  |  Listing Presentation
Realty Elite | Listing Presentation
Realty Elite
 
Luxury Real Estate Listing Presentation
Luxury Real Estate Listing PresentationLuxury Real Estate Listing Presentation
Luxury Real Estate Listing Presentation
Gary Grimes
 
25 Real Estate Marketing Ideas The Pro's Use
25 Real Estate Marketing Ideas The Pro's Use25 Real Estate Marketing Ideas The Pro's Use
25 Real Estate Marketing Ideas The Pro's Use
Fit Small Business
 
Listing presentation Dawn Bahr
Listing presentation Dawn BahrListing presentation Dawn Bahr
Listing presentation Dawn Bahr
Dawn Bahr
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
 
South Florida Real Estate 2017 Outlook Survey
South Florida Real Estate 2017 Outlook SurveySouth Florida Real Estate 2017 Outlook Survey
South Florida Real Estate 2017 Outlook Survey
cutmytaxes
 
A non residents guide to buying property in florida
A non residents guide to buying property in  floridaA non residents guide to buying property in  florida
A non residents guide to buying property in florida
James Lavigne
 
Make It Happen Homes Listing Presentation for North Texas Real Estate
Make It Happen Homes Listing Presentation for North Texas Real EstateMake It Happen Homes Listing Presentation for North Texas Real Estate
Make It Happen Homes Listing Presentation for North Texas Real Estate
Mary Lou Jaimes
 
Listing Presentation
Listing PresentationListing Presentation
Listing Presentation
LenneaA
 
Realty Elite | Listing Presentation
Realty Elite  |  Listing PresentationRealty Elite  |  Listing Presentation
Realty Elite | Listing Presentation
Realty Elite
 
Luxury Real Estate Listing Presentation
Luxury Real Estate Listing PresentationLuxury Real Estate Listing Presentation
Luxury Real Estate Listing Presentation
Gary Grimes
 
25 Real Estate Marketing Ideas The Pro's Use
25 Real Estate Marketing Ideas The Pro's Use25 Real Estate Marketing Ideas The Pro's Use
25 Real Estate Marketing Ideas The Pro's Use
Fit Small Business
 
Listing presentation Dawn Bahr
Listing presentation Dawn BahrListing presentation Dawn Bahr
Listing presentation Dawn Bahr
Dawn Bahr
 
3 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 20173 Things Every Sales Team Needs to Be Thinking About in 2017
3 Things Every Sales Team Needs to Be Thinking About in 2017
Drift
 
Ad

Similar to C programming language working with functions 1 (20)

unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
JVenkateshGoud
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
SKUP1
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
LECO9
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
Lecture6
Lecture6Lecture6
Lecture6
Dr. Kavita Sharma
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
JAVVAJI VENKATA RAO
 
C function
C functionC function
C function
thirumalaikumar3
 
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
 
Programming in C Functions PPT Presentation.pdf
Programming in C Functions PPT Presentation.pdfProgramming in C Functions PPT Presentation.pdf
Programming in C Functions PPT Presentation.pdf
Ramesh Wadawadagi
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
Venkatesh Goud
 
C functions
C functionsC functions
C functions
University of Potsdam
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
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 on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
ziyadaslanbey
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
Ashwini Raut
 
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
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
SKUP1
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
LECO9
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
JAVVAJI VENKATA RAO
 
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
 
Programming in C Functions PPT Presentation.pdf
Programming in C Functions PPT Presentation.pdfProgramming in C Functions PPT Presentation.pdf
Programming in C Functions PPT Presentation.pdf
Ramesh Wadawadagi
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
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 on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
ziyadaslanbey
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
Ashwini Raut
 
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
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Ad

Recently uploaded (20)

Solution Elementary Describe hair and eyes
Solution Elementary Describe hair and eyesSolution Elementary Describe hair and eyes
Solution Elementary Describe hair and eyes
NguynNhn615443
 
Solution Elementary Unit 1 Family and write a profile
Solution Elementary Unit 1 Family and write a profileSolution Elementary Unit 1 Family and write a profile
Solution Elementary Unit 1 Family and write a profile
NguynNhn615443
 
PEACH Community Jobs Board - June 5, 2025
PEACH Community Jobs Board - June 5, 2025PEACH Community Jobs Board - June 5, 2025
PEACH Community Jobs Board - June 5, 2025
PEACHOrgnization
 
#5 Selection of the Human resource(1).pptx
#5 Selection of the Human resource(1).pptx#5 Selection of the Human resource(1).pptx
#5 Selection of the Human resource(1).pptx
siddharthchaturvedi0
 
New_Curricula_Translation_Presentation.ppt
New_Curricula_Translation_Presentation.pptNew_Curricula_Translation_Presentation.ppt
New_Curricula_Translation_Presentation.ppt
digitalsystems00
 
Pigion pea and seed details coming soonuob
Pigion pea and seed details coming soonuobPigion pea and seed details coming soonuob
Pigion pea and seed details coming soonuob
ajantaseedsagri
 
2025 English CV Sigve Hamilton Aspelund.docx
2025 English CV Sigve Hamilton Aspelund.docx2025 English CV Sigve Hamilton Aspelund.docx
2025 English CV Sigve Hamilton Aspelund.docx
Sigve Hamilton Aspelund
 
Vedic Fusion Tantra Practitioner Training PresentationSlide
Vedic Fusion Tantra Practitioner Training PresentationSlideVedic Fusion Tantra Practitioner Training PresentationSlide
Vedic Fusion Tantra Practitioner Training PresentationSlide
Infinite Abundance Information Systems
 
B CELL SERIES of B lymphoid lineage.pptx
B CELL SERIES of B lymphoid lineage.pptxB CELL SERIES of B lymphoid lineage.pptx
B CELL SERIES of B lymphoid lineage.pptx
lohanikritika1
 
How_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptx
How_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptxHow_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptx
How_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptx
ranjanmuktan
 
A Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdf
A Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdfA Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdf
A Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdf
TsotorvorRejoiceMaka
 
Biography and career history of James Kaminsky
Biography and career history of James KaminskyBiography and career history of James Kaminsky
Biography and career history of James Kaminsky
James Kaminsky
 
最新版英国纽曼大学毕业证(Newman毕业证书)原版定制
最新版英国纽曼大学毕业证(Newman毕业证书)原版定制最新版英国纽曼大学毕业证(Newman毕业证书)原版定制
最新版英国纽曼大学毕业证(Newman毕业证书)原版定制
Taqyea
 
4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx
4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx
4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx
IssaSAssafi
 
Garments Manufacturing, design, cutting and sewing of garments
Garments Manufacturing, design, cutting and sewing of garmentsGarments Manufacturing, design, cutting and sewing of garments
Garments Manufacturing, design, cutting and sewing of garments
NaumanRafique9
 
How to Become a CPA USA and Boost Your Career
How to Become a CPA USA and Boost Your CareerHow to Become a CPA USA and Boost Your Career
How to Become a CPA USA and Boost Your Career
ipfcadwords
 
Remote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdf
Remote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdfRemote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdf
Remote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdf
nareshsalarite
 
Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...
Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...
Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...
logosou
 
Bone Histology and benign bone tumo.pptx
Bone Histology and benign bone tumo.pptxBone Histology and benign bone tumo.pptx
Bone Histology and benign bone tumo.pptx
lohanikritika1
 
CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024
CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024
CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024
Ebuka22
 
Solution Elementary Describe hair and eyes
Solution Elementary Describe hair and eyesSolution Elementary Describe hair and eyes
Solution Elementary Describe hair and eyes
NguynNhn615443
 
Solution Elementary Unit 1 Family and write a profile
Solution Elementary Unit 1 Family and write a profileSolution Elementary Unit 1 Family and write a profile
Solution Elementary Unit 1 Family and write a profile
NguynNhn615443
 
PEACH Community Jobs Board - June 5, 2025
PEACH Community Jobs Board - June 5, 2025PEACH Community Jobs Board - June 5, 2025
PEACH Community Jobs Board - June 5, 2025
PEACHOrgnization
 
#5 Selection of the Human resource(1).pptx
#5 Selection of the Human resource(1).pptx#5 Selection of the Human resource(1).pptx
#5 Selection of the Human resource(1).pptx
siddharthchaturvedi0
 
New_Curricula_Translation_Presentation.ppt
New_Curricula_Translation_Presentation.pptNew_Curricula_Translation_Presentation.ppt
New_Curricula_Translation_Presentation.ppt
digitalsystems00
 
Pigion pea and seed details coming soonuob
Pigion pea and seed details coming soonuobPigion pea and seed details coming soonuob
Pigion pea and seed details coming soonuob
ajantaseedsagri
 
2025 English CV Sigve Hamilton Aspelund.docx
2025 English CV Sigve Hamilton Aspelund.docx2025 English CV Sigve Hamilton Aspelund.docx
2025 English CV Sigve Hamilton Aspelund.docx
Sigve Hamilton Aspelund
 
B CELL SERIES of B lymphoid lineage.pptx
B CELL SERIES of B lymphoid lineage.pptxB CELL SERIES of B lymphoid lineage.pptx
B CELL SERIES of B lymphoid lineage.pptx
lohanikritika1
 
How_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptx
How_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptxHow_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptx
How_a_hehdhdhdhdhhdhdhdhdndndjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjd_Works.pptx
ranjanmuktan
 
A Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdf
A Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdfA Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdf
A Profile of Rejoice Makafui Tsotorvor empowering through Art Education.pdf
TsotorvorRejoiceMaka
 
Biography and career history of James Kaminsky
Biography and career history of James KaminskyBiography and career history of James Kaminsky
Biography and career history of James Kaminsky
James Kaminsky
 
最新版英国纽曼大学毕业证(Newman毕业证书)原版定制
最新版英国纽曼大学毕业证(Newman毕业证书)原版定制最新版英国纽曼大学毕业证(Newman毕业证书)原版定制
最新版英国纽曼大学毕业证(Newman毕业证书)原版定制
Taqyea
 
4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx
4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx
4 Protection_of_Vulnerable_Groups_in_Armed_Conflict.pptx
IssaSAssafi
 
Garments Manufacturing, design, cutting and sewing of garments
Garments Manufacturing, design, cutting and sewing of garmentsGarments Manufacturing, design, cutting and sewing of garments
Garments Manufacturing, design, cutting and sewing of garments
NaumanRafique9
 
How to Become a CPA USA and Boost Your Career
How to Become a CPA USA and Boost Your CareerHow to Become a CPA USA and Boost Your Career
How to Become a CPA USA and Boost Your Career
ipfcadwords
 
Remote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdf
Remote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdfRemote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdf
Remote Job Portals That Help Freshers Land Private Sector Roles from Jaipur.pdf
nareshsalarite
 
Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...
Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...
Data’s Not a Dirty Word- Solutions for Stewardship, Stories, and Succession P...
logosou
 
Bone Histology and benign bone tumo.pptx
Bone Histology and benign bone tumo.pptxBone Histology and benign bone tumo.pptx
Bone Histology and benign bone tumo.pptx
lohanikritika1
 
CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024
CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024
CLIENT SERVICE 2024 REPORT FOR THE YEAR 2024
Ebuka22
 

C programming language working with functions 1

  • 1. C ProgrammingLanguage WorkingwithFunctions1 Agenda: What is a Functions? A function is a named, independent section of C code that performs a specific task and optionally returns a value to the callingprogram A function is named. Each function has a unique name. By usingthat name in another partof the program, you can execute the statements contained in the function.This is known as callingthefunction. A function can be called fromwithin another function. A function is independent. A function can perform its task without interference from or interferingwith other parts of the program. A function performs a specific task. This is the easy partof the definition.A task is a discretejob that your program must perform as partof its overall operation,such as sendinga lineof text to a printer, sortingan array into numerical order,or calculatinga cuberoot. function can return a value to the calling program. When your program callsa function,the statements it contains areexecuted. If you want them to, these statements can pass information back to the callingprogram. Benefits of the functions program Function Terminology Function prototype: A function's prototype contains the name of the function,return type, a lis tof variables that must be passed to it, and the type of variableitreturns, if any.. Function Definition: The function itself is called the function definition.The definition contains the code that will be executed. C ProgrammingLanguage WorkingwithFunctions2
  • 2. Function header: The function header is atthe startof a function,and itgives the function's name. The header also gives the function's return type and describes its arguments.Note that the function header is identical to the function prototype (minus the semicolon). Function Body: The statements written within function arecalled function body. Statements are enclosed in braces.These statements are executed when the function is called. Arguments: When a function is called,the program can send the function information in the form of one or more arguments. An argument is programdata needed by the function to perform its task.Arguments are enclosed in parentheses followingthe function's name. Return statement: If the function return type is anythingother than void, a return statement should be included, returning a valuematching the return type. /* Demonstrates a simple function */ #include<stdio.h> longcube(long x); longinput, answer; main() { printf("Enter an integer value: "); scanf("%d", &input); answer = cube(input); /*here input is actual argument. /* Note: %ld is the conversion specifier for */ /* a long integer */ printf("nThe cube of %ld is %ld.n", input, answer); return 0; } /* Function: cube() - Calculates thecubed valueof a variable*/ longcube(long x) /*here x is formal argument*/ { longx_cubed; x_cubed = x * x * x; return x_cubed; } How does a Function Works program. C ProgrammingLanguage WorkingwithFunctions3
  • 3. m of one or more arguments. An argument is programdata needed by the function to perform its task.The statements in the function then execute, performing whatever task each was designed to do. sses back to the same location in the program that called the function. Functions can send information back to the program in the form of a return value. xecution passes back to the placefrom which the function was called.A function can be called as many times as needed, and functions can be called in any order. #include<stdio.h> void printline(char ch,intn); int add(inta,intb,int c); main() { int result; printline('#',70); result=add(10,3,4); printf("n resultis %d",result); getch(); return 0; } void printline(char ch,intn) { int i; for(i=0;i<n;i++) printf("%c",ch); } int add(inta,intb,int c) { C ProgrammingLanguage WorkingwithFunctions4
  • 4. return a+b+c; } /* Program to check the given value is vowel */ #include<stdio.h> void main() { char ch; printf("nEnter any character …'); ch=getch(); if(checkvowel(ch)==1) printf("n It is a vowel"); else printf("n try again"); } int checkvowel(char ch) { if(ch=='a'||ch=='c'||ch=='i'||ch=='o'||ch=='u'||ch='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') return (1); else return (0); }