SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
functions in C and types
Mubashir Farooq
1405(BScs)
GOVT Municipal Degree College FSD
Definition
A Function is a self-contained block of statement
that perform a task of some kind.
OR
Function is a set of instruction to carryout a
particular task.
Function after its execution returns a single value
when we call it in our program.
Functions in C
1.Built-in-Functions
• The built-in-function are
also called library function
or Standard Function. These
functions are
provided by programmer.
• printf(); and scanf(); are
Some common types of
built-in-Functions.
2.User-Defined Fun.
• Defined by user at the
time of writing the
program. User set these
program for her own
uses.
• Add(); Max(); etc are
some kinds of user-
defined functions.
Functions in C
Need of functions
• Enabling code reuse
• Better readability
• Improved debugging and testing
• Improved maintainability
• Reduce lines of code
Functions in C
Steps of User-Defined-F.
There are three steps of working with user
Defined functions:
1. Function Declaration, also known as function
prototype
2. Function Dentition means body of function.
3. Function use, also known as function call.
Functions in C
Programs.
• Simple program by Function :-
#include<stdio.h>
void massage();/*Function prototype declaration*/
void main()
{
void massage();/*function call*/
}
void massage()/*function definition*/
{
printf(“This is a simple program");
}
start
Function call
Void massag
Output
end
Out put :-
This is simple program
To find area and circumference of
circle.
#include<stdio.h>
#define PI 3.14159
float carea(float);
float ccir(float);
void main()
{ float radius;
printf("Enter floater Radius:");
scanf("%f",&radius);
carea(radius);
ccir(radius);
getch();
} float carea(float radius)
{ float area;
area=PI*radius*radius;
printf("Area= %fn",area);}
float ccir(float radius)
{ float ccir;
cir=2*PI*radius;
printf("Circumference= %f",cir);}
• Flo.
Programs.
start
Input radius
Function call
Float carea,crim
area=PI*radius*radius
cir=2*PI* radius
Output
Area,Cri
end
Enter floater Radius _5.0
Area=78.53975
Circumference=31.4159
To find area and circumference of
cube.
#include<stdio.h>
#define PI 3.14159
float carea(float);
float ccir(float);
void main()
{ float radius;
printf("Enter floater Radius:");
scanf("%f",&radius);
carea(radius);
ccir(radius);
getch();
} float carea(float radius)
{ float area;
area=4*PI*radius*radius;
printf("Area= %fn",area);}
float ccir(float radius)
{ float ccir;
cir=4/3*PI*radius*radius*radius*;
printf("Circumferernce= %f",cir);}
Programs. start
Input radius
Function call
Float carea,crim
area=4*PI*radius*radius
cir=4/3*PI* radius* radius*radius
Output
Area,Cir
end
Enter floater Radius _5.0
Area=1570.795
Circumference=523.59833335
To Exchange Values of 2 variables.
include<stdio.h>
void swap(int *x, int *y);
void main() {
int x, y;
printf("nEnter First number : ");
scanf("%d", &x);
printf("nEnter Second number : ");
scanf("%d", &y);
printf("nBefore Swaping x = %d and y = %d", x, y);
swap(&x, &y);
printf("nAfter Swaping x = %d and y = %d", x, y);
getch();}
void swap(int *x, int *y) {
int temp;
temp = *x;
*x = *y;
*y = temp;}
Programs. start
Input x,y
Output
Values of x and y
end
Function call
Void swap
Temp=*x
*x=*y
Y=*temp
Enter First number_4
Enter Second number_8
Before Swaping x=4 and y=8
After Swaping x=8 and y=4
If No
Question.???
by MF Malik

Contenu connexe

Tendances (20)

structure and union
structure and unionstructure and union
structure and union
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C pointer
C pointerC pointer
C pointer
 
C Pointers
C PointersC Pointers
C Pointers
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
String in c
String in cString in c
String in c
 
String in c programming
String in c programmingString in c programming
String in c programming
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Functions in c
Functions in cFunctions in c
Functions in c
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
 
Python strings
Python stringsPython strings
Python strings
 
C string
C stringC string
C string
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 

Similaire à functions in C and types

Similaire à functions in C and types (20)

5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
C structure
C structureC structure
C structure
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
visiblity and scope.pptx
visiblity and scope.pptxvisiblity and scope.pptx
visiblity and scope.pptx
 
Functions
FunctionsFunctions
Functions
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
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
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptxChapter 1_C Fundamentals_HS_Tech Yourself C.pptx
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 

Dernier

Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements SolutionsIQBG inc
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
Building Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to startBuilding Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to startMaxim Salnikov
 
Steps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic DevelopersSteps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic Developersmichealwillson701
 
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...Maxim Salnikov
 
8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.Ritesh Kanjee
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfMind IT Systems
 
BATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data MeshBATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data MeshBATbern
 
renewable energy renewable energy renewable energy renewable energy
renewable energy renewable energy renewable energy  renewable energyrenewable energy renewable energy renewable energy  renewable energy
renewable energy renewable energy renewable energy renewable energyjeyasrig
 
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeUser Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeKaylee Miller
 
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...MyFAA
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdfOffsiteNOC
 
Mobile App Development company Houston
Mobile  App  Development  company HoustonMobile  App  Development  company Houston
Mobile App Development company Houstonjennysmithusa549
 
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxCYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxBarakaMuyengi
 
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptxBusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptxAGATSoftware
 
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial FrontiersUnlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI: Navigating Open Source vs. Commercial FrontiersRaphaël Semeteys
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...jackiepotts6
 
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurMinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurPriyadarshini T
 
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevLeveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevpmgdscunsri
 
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...telebusocialmarketin
 

Dernier (20)

Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements Solutions
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Building Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to startBuilding Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to start
 
Steps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic DevelopersSteps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic Developers
 
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
 
8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
 
BATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data MeshBATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data Mesh
 
renewable energy renewable energy renewable energy renewable energy
renewable energy renewable energy renewable energy  renewable energyrenewable energy renewable energy renewable energy  renewable energy
renewable energy renewable energy renewable energy renewable energy
 
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeUser Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller Resume
 
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
Take Advantage of Mx Tracking Flight Scheduling Solutions to Streamline Your ...
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf
 
Mobile App Development company Houston
Mobile  App  Development  company HoustonMobile  App  Development  company Houston
Mobile App Development company Houston
 
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxCYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
 
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptxBusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
 
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial FrontiersUnlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
 
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurMinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
 
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevLeveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
 
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
 

functions in C and types

  • 3. Definition A Function is a self-contained block of statement that perform a task of some kind. OR Function is a set of instruction to carryout a particular task. Function after its execution returns a single value when we call it in our program. Functions in C
  • 4. 1.Built-in-Functions • The built-in-function are also called library function or Standard Function. These functions are provided by programmer. • printf(); and scanf(); are Some common types of built-in-Functions. 2.User-Defined Fun. • Defined by user at the time of writing the program. User set these program for her own uses. • Add(); Max(); etc are some kinds of user- defined functions. Functions in C
  • 5. Need of functions • Enabling code reuse • Better readability • Improved debugging and testing • Improved maintainability • Reduce lines of code Functions in C
  • 6. Steps of User-Defined-F. There are three steps of working with user Defined functions: 1. Function Declaration, also known as function prototype 2. Function Dentition means body of function. 3. Function use, also known as function call. Functions in C
  • 7. Programs. • Simple program by Function :- #include<stdio.h> void massage();/*Function prototype declaration*/ void main() { void massage();/*function call*/ } void massage()/*function definition*/ { printf(“This is a simple program"); } start Function call Void massag Output end Out put :- This is simple program
  • 8. To find area and circumference of circle. #include<stdio.h> #define PI 3.14159 float carea(float); float ccir(float); void main() { float radius; printf("Enter floater Radius:"); scanf("%f",&radius); carea(radius); ccir(radius); getch(); } float carea(float radius) { float area; area=PI*radius*radius; printf("Area= %fn",area);} float ccir(float radius) { float ccir; cir=2*PI*radius; printf("Circumference= %f",cir);} • Flo. Programs. start Input radius Function call Float carea,crim area=PI*radius*radius cir=2*PI* radius Output Area,Cri end Enter floater Radius _5.0 Area=78.53975 Circumference=31.4159
  • 9. To find area and circumference of cube. #include<stdio.h> #define PI 3.14159 float carea(float); float ccir(float); void main() { float radius; printf("Enter floater Radius:"); scanf("%f",&radius); carea(radius); ccir(radius); getch(); } float carea(float radius) { float area; area=4*PI*radius*radius; printf("Area= %fn",area);} float ccir(float radius) { float ccir; cir=4/3*PI*radius*radius*radius*; printf("Circumferernce= %f",cir);} Programs. start Input radius Function call Float carea,crim area=4*PI*radius*radius cir=4/3*PI* radius* radius*radius Output Area,Cir end Enter floater Radius _5.0 Area=1570.795 Circumference=523.59833335
  • 10. To Exchange Values of 2 variables. include<stdio.h> void swap(int *x, int *y); void main() { int x, y; printf("nEnter First number : "); scanf("%d", &x); printf("nEnter Second number : "); scanf("%d", &y); printf("nBefore Swaping x = %d and y = %d", x, y); swap(&x, &y); printf("nAfter Swaping x = %d and y = %d", x, y); getch();} void swap(int *x, int *y) { int temp; temp = *x; *x = *y; *y = temp;} Programs. start Input x,y Output Values of x and y end Function call Void swap Temp=*x *x=*y Y=*temp Enter First number_4 Enter Second number_8 Before Swaping x=4 and y=8 After Swaping x=8 and y=4