C function

C function
A large program in c can be divided to many subprogram
The subprogram posses a self contain components and have well define purpose.
The subprogram is called as a function
Basically a job of function is to do something
C program contain at least one function which is main().
Classification of
Function
Library
function
User define
function
- main() -printf()
-scanf()
-pow()
-ceil()
It is much easier to write a structured program where a large program can be divided
into a smaller, simpler task.
Allowing the code to be called many times
Easier to read and update
It is easier to debug a structured program where there error is easy to find and fix
1: #include <stdio.h>
2:
3: long cube(long x);
4:
5: long input, answer;
6:
7: int main( void )
8: {
9: printf(“Enter an integer value: ”);
10: scanf(“%d”, &input);
11: answer = cube(input);
12: printf(“nThe cube of %ld is %ld.n”, input,
answer);
13:
14: return 0;
15: }
16:
17: long cube(long x)
18: {
19: long x_cubed;
20:
21: x_cubed = x * x * x;
22: return x_cubed;
23: }
 Function names is cube
 Variable that are requires is
long
 The variable to be passed
on is X(has single
arguments)—value can be
passed to function so it can
perform the specific task. It
is called
Output
Enter an integer
value:4
The cube of 4 is 64.
Return data type
Arguments/formal parameter
Actual parameters
C program doesn't execute the statement in function until the function is called.
When function is called the program can send the function information in the form
of one or more argument.
When the function is used it is referred to as the called function
Functions often use data that is passed to them from the calling function
Data is passed from the calling function to a called function by specifying the
variables in a argument list.
Argument list cannot be used to send data. Its only copy data/value/variable that
pass from the calling function.
The called function then performs its operation using the copies.
Provides the compiler with the description of functions that will be used later in the
program
Its define the function before it been used/called
Function prototypes need to be written at the beginning of the program.
The function prototype must have :
A return type indicating the variable that the function will be return
Syntax for Function Prototype
return-type function_name( arg-type name-1,...,arg-type name-n);
Function Prototype Examples
 double squared( double number );
 void print_report( int report_number );
 int get_menu_choice( void);
It is the actual function that contains the code that will be execute.
Should be identical to the function prototype.
Syntax of Function Definition
return-type function_name( arg-type name-1,...,arg-type name-n) ---- Function header
{
declarations;
statements;
return(expression);
}
Function Body
Function Definition Examples
float conversion (float celsius)
{
float fahrenheit;
fahrenheit = celcius*33.8
return fahrenheit;
}
The function name’s is conversion
This function accepts arguments celcius of the type float. The function return a float
value.
So, when this function is called in the program, it will perform its task which is to convert
fahrenheit by multiply celcius with 33.8 and return the result of the summation.
Note that if the function is returning a value, it needs to use the keyword return.
Can be any of C’s data type:
char
int
float
long………
Examples:
int func1(...) /* Returns a type int. */
float func2(...) /* Returns a type float. */
void func3(...) /* Returns nothing. */
Function can be divided into 4 categories:
A function with no arguments and no return value
A function with no arguments and a return value
A function with an argument or arguments and returning no value
A function with arguments and returning a values
A function with no arguments and no return
value
Called function does not have any arguments
Not able to get any value from the calling function
Not returning any value
There is no data transfer between the calling function and called
function.
#include<stdio.h>
#include<conio.h>
void printline();
void main()
{
printf("Welcome to function in
C");
printline();
printf("Function easy to learn.");
printline();
getch();
}
void printline()
{
int i;
printf("n");
for(i=0;i<30;i++)
{ printf("-"); }
printf("n");
}
A function with no arguments and a return value
Does not get any value from the calling function
Can give a return value to calling program
#include <stdio.h>
#include <conio.h>
int send();
void main()
{
int z;
z=send();
printf("nYou entered : %d.",z);
getch();
}
int send()
{
int no1;
printf("Enter a no: ");
scanf("%d",&no1);
return(no1);
}
Enter a no: 46
You entered : 46.
A function with an argument or arguments and returning
no value
A function has argument/s
A calling function can pass values to function called , but calling function not
receive any value
Data is transferred from calling function to the called function but no data is
transferred from the called function to the calling function
Generally Output is printed in the Called function
A function that does not return any value cannot be used in an expression it can
be used only as independent statement.
#include<stdio.h>
#include<conio.h>
void add(int x, int y);
void main()
{
add(30,15);
add(63,49);
add(952,321);
getch();
}
void add(int x, int y)
{
int result;
result = x+y;
printf("Sum of %d and %d is
%d.nn",x,y,result);
}
A function with arguments and returning a values
Argument are passed by calling function to the called function
Called function return value to the calling function
Mostly used in programming because it can two way communication
Data returned by the function can be used later in our program for further
calculation.
Result 85.
Result 1273.
#include <stdio.h>
#include <conio.h>
int add(int x,int y);
void main()
{
int z;
z=add(952,321);
printf("Result %d. nn",add(30,55));
printf("Result %d.nn",z);
getch();
}
int add(int x,int y)
{
int result;
result = x + y;
return(result);
}
Send 2 integer value x and y to add()
Function add the two values and send
back the result to the calling function
int is the return type of function
Return statement is a keyword and in
bracket we can give values which we
want to return.
Variable that declared occupies a memory according to it size
It has address for the location so it can be referred later by CPU for manipulation
The ‘*’ and ‘&’ Operator
Int x= 10
x
10
76858
Memory location name
Value at memory location
Memory location address
We can use the address which also point the same value.
#include <stdio.h>
#include <conio.h>
void main()
{
int i=9;
printf("Value of i : %dn",i);
printf("Adress of i %dn", &i);
getch();
}
& show the address of the variable
#include <stdio.h>
#include <conio.h>
void main()
{
int i=9;
printf("Value of i : %dn",i);
printf("Address of i %dn", &i);
printf("Value at address of i: %d", *(&i));
getch();
}
* Symbols called the value at the addres
CALL BY VALUE & REFERENCE
Call By value:
 Value of actual arguments are passed to
formal arguments.
 The operation is done on formal operations.
Call By Reference:
 It is passing values, address are passed.
 The function operates on address rather then
values.
EXAMPLE PGM’S
CALL BY VALUE
main()
{
int x,y,change(int,int);
clrscr();
printf(“Enter the values of X & Y:”);
scanf(“%d%d”,&x,&y);
change(x,y);
printf(“In main() X=%d Y=%d”,x,y);
return 0;
}
change(int a,int b)
{
int k;
k=a;
a=b;
b=k;
printf(“In Change() X=%d
y=%d”,a,b);
}
CALL BY REFERENCE
main()
{
int x,y,change(int*,int*);
clrscr();
printf(“Enter the values of X & Y:”);
scanf(“%d%d”,&x,&y);
change(x,y);
printf(“In main() X=%d Y=%d”,x,y);
return 0;
}
change(int *a,int *b)
{
int *k;
*k=*a;
*a=*b;
*b=*k;
printf(“InChange()X=%dy=%d”,*a,*b)
;
}7
OUTPUT
CALL BY VALUE:
Enter the value of X & Y: 5 4
In Change X=4 Y=5
In main() X=5 Y=4
CALL BY REFERENCE:
Enter the value of X & Y: 5 4
In Change X=4 Y=5
In main() X=4 Y=5
RECURSION
 It function is called repetitively by itself.
 Recursion can be used directly and indirectly.
 Directly recursion function calls itself for
condition true.
 Indirectly recursion function is called another
function calls
EXAMPLE
int x=1,s=0;
void main(int);
void main(x)
{
s=s+x;
printf(“n x=%d s=%d”,x,s);
if(x==5)
exit(0);
main(++x);
}
OUTPUT
x=1 s=1
x=2 s=3
x=3 s=6
x=4 s=10
x=5 s=15
C function
1 de 26

Recomendados

Function in C program por
Function in C programFunction in C program
Function in C programNurul Zakiah Zamri Tan
70.4K vistas23 diapositivas
C functions por
C functionsC functions
C functionsUniversity of Potsdam
9.9K vistas32 diapositivas
Function C programming por
Function C programmingFunction C programming
Function C programmingAppili Vamsi Krishna
11.6K vistas29 diapositivas
Functions in C por
Functions in CFunctions in C
Functions in CKamal Acharya
25.2K vistas22 diapositivas
Functions in c language por
Functions in c language Functions in c language
Functions in c language tanmaymodi4
2.6K vistas30 diapositivas
Pointers,virtual functions and polymorphism cpp por
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
2.4K vistas16 diapositivas

Más contenido relacionado

La actualidad más candente

Functions in C por
Functions in CFunctions in C
Functions in CShobhit Upadhyay
4.1K vistas14 diapositivas
Function por
FunctionFunction
Functionjayesh30sikchi
1.3K vistas22 diapositivas
Function in c por
Function in cFunction in c
Function in cRaj Tandukar
6.8K vistas22 diapositivas
Function in C Language por
Function in C Language Function in C Language
Function in C Language programmings guru
3.9K vistas8 diapositivas
Function in c por
Function in cFunction in c
Function in csavitamhaske
1.3K vistas18 diapositivas
OOPS Basics With Example por
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With ExampleThooyavan Venkatachalam
2.5K vistas46 diapositivas

La actualidad más candente(20)

Functions in c language por Tanmay Modi
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi602 vistas
Data types in C por Tarun Sharma
Data types in CData types in C
Data types in C
Tarun Sharma33.9K vistas
basics of C and c++ by eteaching por eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching2.4K vistas
C programming language tutorial por javaTpoint s
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s2.2K vistas
Call by value or call by reference in C++ por Sachin Yadav
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
Sachin Yadav3.5K vistas
Call by value por Dharani G
Call by valueCall by value
Call by value
Dharani G8.6K vistas
Object Oriented Programming Using C++ por Muhammad Waqas
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas11.1K vistas
FUNCTIONS IN c++ PPT por 03062679929
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
0306267992925.3K vistas
C programming tutorial por Mohit Saini
C programming tutorialC programming tutorial
C programming tutorial
Mohit Saini3.2K vistas
Arrays in python por moazamali28
Arrays in pythonArrays in python
Arrays in python
moazamali283.2K vistas
C programming - Pointers por Wingston
C programming - PointersC programming - Pointers
C programming - Pointers
Wingston3.7K vistas

Destacado

Coper in C por
Coper in CCoper in C
Coper in Cthirumalaikumar3
208 vistas22 diapositivas
Bespoke glasses | Cool Eyewear por
Bespoke glasses | Cool EyewearBespoke glasses | Cool Eyewear
Bespoke glasses | Cool EyewearMono Qool
66 vistas9 diapositivas
SGI. PROFILE por
SGI. PROFILESGI. PROFILE
SGI. PROFILESharad Admuthe
286 vistas15 diapositivas
The different rhinoplasty procedures por
The different rhinoplasty proceduresThe different rhinoplasty procedures
The different rhinoplasty proceduresHealth First
75 vistas6 diapositivas
The many hidden causes of hip pain por
The many hidden causes of hip painThe many hidden causes of hip pain
The many hidden causes of hip painHealth First
72 vistas7 diapositivas
exhibitions,event planning,designers,events management,companies,contractors por
exhibitions,event planning,designers,events management,companies,contractorsexhibitions,event planning,designers,events management,companies,contractors
exhibitions,event planning,designers,events management,companies,contractorsexhibithire
211 vistas15 diapositivas

Destacado(11)

Bespoke glasses | Cool Eyewear por Mono Qool
Bespoke glasses | Cool EyewearBespoke glasses | Cool Eyewear
Bespoke glasses | Cool Eyewear
Mono Qool66 vistas
The different rhinoplasty procedures por Health First
The different rhinoplasty proceduresThe different rhinoplasty procedures
The different rhinoplasty procedures
Health First75 vistas
The many hidden causes of hip pain por Health First
The many hidden causes of hip painThe many hidden causes of hip pain
The many hidden causes of hip pain
Health First72 vistas
exhibitions,event planning,designers,events management,companies,contractors por exhibithire
exhibitions,event planning,designers,events management,companies,contractorsexhibitions,event planning,designers,events management,companies,contractors
exhibitions,event planning,designers,events management,companies,contractors
exhibithire211 vistas
The 8 different sub disciplines of urology por Health First
The 8 different sub disciplines of urologyThe 8 different sub disciplines of urology
The 8 different sub disciplines of urology
Health First235 vistas
Tension fabric-printing-inspiration-guide por exhibithire
Tension fabric-printing-inspiration-guideTension fabric-printing-inspiration-guide
Tension fabric-printing-inspiration-guide
exhibithire261 vistas
VGIPM_Conference_CTA_2013_Abstracts[1] por Carlos Castilho
VGIPM_Conference_CTA_2013_Abstracts[1]VGIPM_Conference_CTA_2013_Abstracts[1]
VGIPM_Conference_CTA_2013_Abstracts[1]
Carlos Castilho219 vistas
event planning,exhibition,designers,events management,companies,contractors por exhibithire
event planning,exhibition,designers,events management,companies,contractorsevent planning,exhibition,designers,events management,companies,contractors
event planning,exhibition,designers,events management,companies,contractors
exhibithire204 vistas

Similar a C function

Function in c program por
Function in c programFunction in c program
Function in c programumesh patil
1.3K vistas23 diapositivas
Functionincprogram por
FunctionincprogramFunctionincprogram
FunctionincprogramSampath Kumar
44 vistas24 diapositivas
Function in c por
Function in cFunction in c
Function in cCGC Technical campus,Mohali
656 vistas22 diapositivas
Functions struct&union por
Functions struct&unionFunctions struct&union
Functions struct&unionUMA PARAMESWARI
115 vistas33 diapositivas
Functions and pointers_unit_4 por
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4MKalpanaDevi
153 vistas96 diapositivas
Functions and pointers_unit_4 por
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4Saranya saran
82 vistas112 diapositivas

Similar a C function(20)

Function in c program por umesh patil
Function in c programFunction in c program
Function in c program
umesh patil1.3K vistas
Functions and pointers_unit_4 por MKalpanaDevi
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
MKalpanaDevi153 vistas
Functions and pointers_unit_4 por Saranya saran
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran82 vistas
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx por vekariyakashyap
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
vekariyakashyap13 vistas
CH.4FUNCTIONS IN C_FYBSC(CS).pptx por SangeetaBorde3
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde329 vistas
VIT351 Software Development VI Unit1 por YOGESH SINGH
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH64 vistas
Dti2143 chapter 5 por alish sha
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
alish sha736 vistas
Presentation on Function in C Programming por Shuvongkor Barman
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman14.4K vistas

Más de thirumalaikumar3

Control flow in c por
Control flow in cControl flow in c
Control flow in cthirumalaikumar3
439 vistas19 diapositivas
C basics por
C   basicsC   basics
C basicsthirumalaikumar3
1.7K vistas25 diapositivas
Structure c por
Structure cStructure c
Structure cthirumalaikumar3
7.2K vistas23 diapositivas
String c por
String cString c
String cthirumalaikumar3
8.5K vistas16 diapositivas
File handling in c por
File  handling in cFile  handling in c
File handling in cthirumalaikumar3
587 vistas34 diapositivas
File handling-c programming language por
File handling-c programming languageFile handling-c programming language
File handling-c programming languagethirumalaikumar3
1K vistas26 diapositivas

Último

Narration ppt.pptx por
Narration  ppt.pptxNarration  ppt.pptx
Narration ppt.pptxTARIQ KHAN
131 vistas24 diapositivas
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1} por
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}DR .PALLAVI PATHANIA
244 vistas195 diapositivas
11.28.23 Social Capital and Social Exclusion.pptx por
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptxmary850239
291 vistas25 diapositivas
The Accursed House by Émile Gaboriau por
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile GaboriauDivyaSheta
187 vistas15 diapositivas
Are we onboard yet University of Sussex.pptx por
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptxJisc
93 vistas7 diapositivas
11.30.23 Poverty and Inequality in America.pptx por
11.30.23 Poverty and Inequality in America.pptx11.30.23 Poverty and Inequality in America.pptx
11.30.23 Poverty and Inequality in America.pptxmary850239
149 vistas33 diapositivas

Último(20)

Narration ppt.pptx por TARIQ KHAN
Narration  ppt.pptxNarration  ppt.pptx
Narration ppt.pptx
TARIQ KHAN131 vistas
11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239291 vistas
The Accursed House by Émile Gaboriau por DivyaSheta
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile Gaboriau
DivyaSheta187 vistas
Are we onboard yet University of Sussex.pptx por Jisc
Are we onboard yet University of Sussex.pptxAre we onboard yet University of Sussex.pptx
Are we onboard yet University of Sussex.pptx
Jisc93 vistas
11.30.23 Poverty and Inequality in America.pptx por mary850239
11.30.23 Poverty and Inequality in America.pptx11.30.23 Poverty and Inequality in America.pptx
11.30.23 Poverty and Inequality in America.pptx
mary850239149 vistas
Psychology KS5 por WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch81 vistas
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx por ISSIP
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
ISSIP359 vistas
REPRESENTATION - GAUNTLET.pptx por iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood91 vistas
Lecture: Open Innovation por Michal Hron
Lecture: Open InnovationLecture: Open Innovation
Lecture: Open Innovation
Michal Hron99 vistas
The basics - information, data, technology and systems.pdf por JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1106 vistas
The Open Access Community Framework (OACF) 2023 (1).pptx por Jisc
The Open Access Community Framework (OACF) 2023 (1).pptxThe Open Access Community Framework (OACF) 2023 (1).pptx
The Open Access Community Framework (OACF) 2023 (1).pptx
Jisc107 vistas
AI Tools for Business and Startups por Svetlin Nakov
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov105 vistas
Scope of Biochemistry.pptx por shoba shoba
Scope of Biochemistry.pptxScope of Biochemistry.pptx
Scope of Biochemistry.pptx
shoba shoba126 vistas
Sociology KS5 por WestHatch
Sociology KS5Sociology KS5
Sociology KS5
WestHatch65 vistas

C function

  • 2. A large program in c can be divided to many subprogram The subprogram posses a self contain components and have well define purpose. The subprogram is called as a function Basically a job of function is to do something C program contain at least one function which is main(). Classification of Function Library function User define function - main() -printf() -scanf() -pow() -ceil()
  • 3. It is much easier to write a structured program where a large program can be divided into a smaller, simpler task. Allowing the code to be called many times Easier to read and update It is easier to debug a structured program where there error is easy to find and fix
  • 4. 1: #include <stdio.h> 2: 3: long cube(long x); 4: 5: long input, answer; 6: 7: int main( void ) 8: { 9: printf(“Enter an integer value: ”); 10: scanf(“%d”, &input); 11: answer = cube(input); 12: printf(“nThe cube of %ld is %ld.n”, input, answer); 13: 14: return 0; 15: } 16: 17: long cube(long x) 18: { 19: long x_cubed; 20: 21: x_cubed = x * x * x; 22: return x_cubed; 23: }  Function names is cube  Variable that are requires is long  The variable to be passed on is X(has single arguments)—value can be passed to function so it can perform the specific task. It is called Output Enter an integer value:4 The cube of 4 is 64. Return data type Arguments/formal parameter Actual parameters
  • 5. C program doesn't execute the statement in function until the function is called. When function is called the program can send the function information in the form of one or more argument. When the function is used it is referred to as the called function Functions often use data that is passed to them from the calling function Data is passed from the calling function to a called function by specifying the variables in a argument list. Argument list cannot be used to send data. Its only copy data/value/variable that pass from the calling function. The called function then performs its operation using the copies.
  • 6. Provides the compiler with the description of functions that will be used later in the program Its define the function before it been used/called Function prototypes need to be written at the beginning of the program. The function prototype must have : A return type indicating the variable that the function will be return Syntax for Function Prototype return-type function_name( arg-type name-1,...,arg-type name-n); Function Prototype Examples  double squared( double number );  void print_report( int report_number );  int get_menu_choice( void);
  • 7. It is the actual function that contains the code that will be execute. Should be identical to the function prototype. Syntax of Function Definition return-type function_name( arg-type name-1,...,arg-type name-n) ---- Function header { declarations; statements; return(expression); } Function Body
  • 8. Function Definition Examples float conversion (float celsius) { float fahrenheit; fahrenheit = celcius*33.8 return fahrenheit; } The function name’s is conversion This function accepts arguments celcius of the type float. The function return a float value. So, when this function is called in the program, it will perform its task which is to convert fahrenheit by multiply celcius with 33.8 and return the result of the summation. Note that if the function is returning a value, it needs to use the keyword return.
  • 9. Can be any of C’s data type: char int float long……… Examples: int func1(...) /* Returns a type int. */ float func2(...) /* Returns a type float. */ void func3(...) /* Returns nothing. */
  • 10. Function can be divided into 4 categories: A function with no arguments and no return value A function with no arguments and a return value A function with an argument or arguments and returning no value A function with arguments and returning a values
  • 11. A function with no arguments and no return value Called function does not have any arguments Not able to get any value from the calling function Not returning any value There is no data transfer between the calling function and called function. #include<stdio.h> #include<conio.h> void printline(); void main() { printf("Welcome to function in C"); printline(); printf("Function easy to learn."); printline(); getch(); } void printline() { int i; printf("n"); for(i=0;i<30;i++) { printf("-"); } printf("n"); }
  • 12. A function with no arguments and a return value Does not get any value from the calling function Can give a return value to calling program #include <stdio.h> #include <conio.h> int send(); void main() { int z; z=send(); printf("nYou entered : %d.",z); getch(); } int send() { int no1; printf("Enter a no: "); scanf("%d",&no1); return(no1); } Enter a no: 46 You entered : 46.
  • 13. A function with an argument or arguments and returning no value A function has argument/s A calling function can pass values to function called , but calling function not receive any value Data is transferred from calling function to the called function but no data is transferred from the called function to the calling function Generally Output is printed in the Called function A function that does not return any value cannot be used in an expression it can be used only as independent statement.
  • 14. #include<stdio.h> #include<conio.h> void add(int x, int y); void main() { add(30,15); add(63,49); add(952,321); getch(); } void add(int x, int y) { int result; result = x+y; printf("Sum of %d and %d is %d.nn",x,y,result); }
  • 15. A function with arguments and returning a values Argument are passed by calling function to the called function Called function return value to the calling function Mostly used in programming because it can two way communication Data returned by the function can be used later in our program for further calculation.
  • 16. Result 85. Result 1273. #include <stdio.h> #include <conio.h> int add(int x,int y); void main() { int z; z=add(952,321); printf("Result %d. nn",add(30,55)); printf("Result %d.nn",z); getch(); } int add(int x,int y) { int result; result = x + y; return(result); } Send 2 integer value x and y to add() Function add the two values and send back the result to the calling function int is the return type of function Return statement is a keyword and in bracket we can give values which we want to return.
  • 17. Variable that declared occupies a memory according to it size It has address for the location so it can be referred later by CPU for manipulation The ‘*’ and ‘&’ Operator Int x= 10 x 10 76858 Memory location name Value at memory location Memory location address We can use the address which also point the same value.
  • 18. #include <stdio.h> #include <conio.h> void main() { int i=9; printf("Value of i : %dn",i); printf("Adress of i %dn", &i); getch(); } & show the address of the variable
  • 19. #include <stdio.h> #include <conio.h> void main() { int i=9; printf("Value of i : %dn",i); printf("Address of i %dn", &i); printf("Value at address of i: %d", *(&i)); getch(); } * Symbols called the value at the addres
  • 20. CALL BY VALUE & REFERENCE Call By value:  Value of actual arguments are passed to formal arguments.  The operation is done on formal operations. Call By Reference:  It is passing values, address are passed.  The function operates on address rather then values.
  • 21. EXAMPLE PGM’S CALL BY VALUE main() { int x,y,change(int,int); clrscr(); printf(“Enter the values of X & Y:”); scanf(“%d%d”,&x,&y); change(x,y); printf(“In main() X=%d Y=%d”,x,y); return 0; } change(int a,int b) { int k; k=a; a=b; b=k; printf(“In Change() X=%d y=%d”,a,b); } CALL BY REFERENCE main() { int x,y,change(int*,int*); clrscr(); printf(“Enter the values of X & Y:”); scanf(“%d%d”,&x,&y); change(x,y); printf(“In main() X=%d Y=%d”,x,y); return 0; } change(int *a,int *b) { int *k; *k=*a; *a=*b; *b=*k; printf(“InChange()X=%dy=%d”,*a,*b) ; }7
  • 22. OUTPUT CALL BY VALUE: Enter the value of X & Y: 5 4 In Change X=4 Y=5 In main() X=5 Y=4 CALL BY REFERENCE: Enter the value of X & Y: 5 4 In Change X=4 Y=5 In main() X=4 Y=5
  • 23. RECURSION  It function is called repetitively by itself.  Recursion can be used directly and indirectly.  Directly recursion function calls itself for condition true.  Indirectly recursion function is called another function calls
  • 24. EXAMPLE int x=1,s=0; void main(int); void main(x) { s=s+x; printf(“n x=%d s=%d”,x,s); if(x==5) exit(0); main(++x); }
  • 25. OUTPUT x=1 s=1 x=2 s=3 x=3 s=6 x=4 s=10 x=5 s=15