SlideShare a Scribd company logo
C. P. Divate
A large program in ccan be divided to many subprogram
The subprogram possesa self contain components and have well define purpose.
The subprogram iscalled as a function
Basically a job of function is to do something
Cprogram contain at least one function which ismain().
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);
1
1
: answer =cube(input);
12: printf(“nThe cube of %ld is%ld.n”, input, answer);
13:
14: return 0;
15:}
16:
1
7: long cube(long x)
18:{
x_cubed =x * x * x;
return x_cubed;
19: long x_cubed;
20:
21:
22:
23: }
 Function namesiscube
 Variable that are requires is
long
 The variable to be passedon
isX(hassingle arguments)—
value can be passedto
function soit can perform the
specific task. It iscalled
Output
Enter an integer value:4
The cube of 4 is64.
Return data type
Arguments/formalparameter
Actual parameters
Cprogram doesn't execute the statement in function until the function is called.
When function iscalled the program can sendthe function information in the form of one
or more argument.
When the function is used it is referred to asthe called function
Functions often use data that ispassed to them from the calling function
Data ispassedfrom 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 isconversion
This function accepts arguments celcius of the type float. The function return a float value.
So,when this function iscalled in the program, it will perform its task which isto convert
fahrenheit by multiply celcius with 33.8 and return the result of the summation.
Note that if the function isreturning a value, it needs to use the keyword return.
Can be any of C‟sdata type:
char
int
float
long………
Examples:
/* Returns a type int. */
int func1(...)
float func2(...)
void func3(...)
/* Returns a type float. */
/* 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 easyto 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
Doesnot 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 istransferred 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 doesnot return any value cannot be usedin an expressionit 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 valuesand send
back the result to the calling function
int isthe return type of function
Return statement isa keyword and in
bracket we can give valueswhich we
want to return.
Variable that declared occupies a memory according to it size
It hasaddressfor the location soit can be referred later by CPUfor 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 addressof 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();
}
* Symbolscalled the value at the addres
s
#include <stdio.h>
#include <conio.h>
int Value (int x);
int Reference (int *x);
int main()
{
int Batu_Pahat =2;
int Langkawi =2;
Value(Batu_Pahat);
Reference(&Langkawi);
printf("Batu_Pahat is number %dn",Batu_Pahat);
printf("Langkawi isnumber %d",Langkawi);
}
int Value(int x)
{
x =1;
}
int Reference(int *x)
{
*x =1;
}
Passby reference
You pass the variable address
Give the function direct access to the variable
The variable can be modified inside the function
#include <stdio.h>
#include <
conio.h>
void callByValue(int, int);
void callByReference(int *, int *);
int main()
{
int x=10, y =20;
printf("Value of x =%d and y =%d. n",x,y);
printf("nCAll By Value function call...n");
callByValue(x,y);
printf("nValue of x =%d and y =%d.n", x,y);
printf("nCAll By Reference function call...n");
callByReference(&x,&y);
printf("Value of x =%d and y =%d.n", x,y);
getch();
return 0;
}
void callByValue(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("nValue of x =%d and y =%d inside callByValue function",x,y);
}
void callByReference(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Fundamentals of functions in C program.pptx

More Related Content

Similar to Fundamentals of functions in C program.pptx

function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
kushwahashivam413
 

Similar to Fundamentals of functions in C program.pptx (20)

Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Function in c
Function in cFunction in c
Function in c
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
Functions in C.pptx
Functions in C.pptxFunctions in C.pptx
Functions in C.pptx
 
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
 
Functions
FunctionsFunctions
Functions
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
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
 
eee2-day4-structures engineering college
eee2-day4-structures engineering collegeeee2-day4-structures engineering college
eee2-day4-structures engineering college
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
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 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Functions in c
Functions in cFunctions in c
Functions in c
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
 

More from ChandrakantDivate1

More from ChandrakantDivate1 (20)

Web Technology LAB MANUAL for Undergraduate Programs
Web Technology  LAB MANUAL for Undergraduate ProgramsWeb Technology  LAB MANUAL for Undergraduate Programs
Web Technology LAB MANUAL for Undergraduate Programs
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
 
Study of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block DiagramStudy of Computer Hardware System using Block Diagram
Study of Computer Hardware System using Block Diagram
 
Computer System Output Devices Peripherals
Computer System Output  Devices PeripheralsComputer System Output  Devices Peripherals
Computer System Output Devices Peripherals
 
Computer system Input Devices Peripherals
Computer system Input  Devices PeripheralsComputer system Input  Devices Peripherals
Computer system Input Devices Peripherals
 
Computer system Input and Output Devices
Computer system Input and Output DevicesComputer system Input and Output Devices
Computer system Input and Output Devices
 
Introduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROMIntroduction to COMPUTER’S MEMORY RAM and ROM
Introduction to COMPUTER’S MEMORY RAM and ROM
 
Introduction to Computer Hardware Systems
Introduction to Computer Hardware SystemsIntroduction to Computer Hardware Systems
Introduction to Computer Hardware Systems
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)Fundamentals of Internet of Things (IoT)
Fundamentals of Internet of Things (IoT)
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Programming in C - Fundamental Study of Strings
Programming in C - Fundamental Study of  StringsProgramming in C - Fundamental Study of  Strings
Programming in C - Fundamental Study of Strings
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Features and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for BeginnersFeatures and Fundamentals of C Language for Beginners
Features and Fundamentals of C Language for Beginners
 
Basics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and FlowchartBasics of Programming Algorithms and Flowchart
Basics of Programming Algorithms and Flowchart
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Computer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric TransformationsComputer Graphics Three-Dimensional Geometric Transformations
Computer Graphics Three-Dimensional Geometric Transformations
 
Computer Graphics - Windowing and Clipping
Computer Graphics - Windowing and ClippingComputer Graphics - Windowing and Clipping
Computer Graphics - Windowing and Clipping
 

Recently uploaded

DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DrGurudutt
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
AbrahamGadissa
 

Recently uploaded (20)

Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
Dairy management system project report..pdf
Dairy management system project report..pdfDairy management system project report..pdf
Dairy management system project report..pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
 
Pharmacy management system project report..pdf
Pharmacy management system project report..pdfPharmacy management system project report..pdf
Pharmacy management system project report..pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
retail automation billing system ppt.pptx
retail automation billing system ppt.pptxretail automation billing system ppt.pptx
retail automation billing system ppt.pptx
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
Online book store management system project.pdf
Online book store management system project.pdfOnline book store management system project.pdf
Online book store management system project.pdf
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 

Fundamentals of functions in C program.pptx

  • 2. A large program in ccan be divided to many subprogram The subprogram possesa self contain components and have well define purpose. The subprogram iscalled as a function Basically a job of function is to do something Cprogram contain at least one function which ismain(). 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); 1 1 : answer =cube(input); 12: printf(“nThe cube of %ld is%ld.n”, input, answer); 13: 14: return 0; 15:} 16: 1 7: long cube(long x) 18:{ x_cubed =x * x * x; return x_cubed; 19: long x_cubed; 20: 21: 22: 23: }  Function namesiscube  Variable that are requires is long  The variable to be passedon isX(hassingle arguments)— value can be passedto function soit can perform the specific task. It iscalled Output Enter an integer value:4 The cube of 4 is64. Return data type Arguments/formalparameter Actual parameters
  • 5. Cprogram doesn't execute the statement in function until the function is called. When function iscalled the program can sendthe function information in the form of one or more argument. When the function is used it is referred to asthe called function Functions often use data that ispassed to them from the calling function Data ispassedfrom 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 isconversion This function accepts arguments celcius of the type float. The function return a float value. So,when this function iscalled in the program, it will perform its task which isto convert fahrenheit by multiply celcius with 33.8 and return the result of the summation. Note that if the function isreturning a value, it needs to use the keyword return.
  • 9. Can be any of C‟sdata type: char int float long……… Examples: /* Returns a type int. */ int func1(...) float func2(...) void func3(...) /* Returns a type float. */ /* 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 easyto 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 Doesnot 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 istransferred 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 doesnot return any value cannot be usedin an expressionit 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 valuesand send back the result to the calling function int isthe return type of function Return statement isa keyword and in bracket we can give valueswhich we want to return.
  • 17. Variable that declared occupies a memory according to it size It hasaddressfor the location soit can be referred later by CPUfor 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 addressof 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(); } * Symbolscalled the value at the addres s
  • 20. #include <stdio.h> #include <conio.h> int Value (int x); int Reference (int *x); int main() { int Batu_Pahat =2; int Langkawi =2; Value(Batu_Pahat); Reference(&Langkawi); printf("Batu_Pahat is number %dn",Batu_Pahat); printf("Langkawi isnumber %d",Langkawi); } int Value(int x) { x =1; } int Reference(int *x) { *x =1; } Passby reference You pass the variable address Give the function direct access to the variable The variable can be modified inside the function
  • 21. #include <stdio.h> #include < conio.h> void callByValue(int, int); void callByReference(int *, int *); int main() { int x=10, y =20; printf("Value of x =%d and y =%d. n",x,y); printf("nCAll By Value function call...n"); callByValue(x,y); printf("nValue of x =%d and y =%d.n", x,y); printf("nCAll By Reference function call...n"); callByReference(&x,&y); printf("Value of x =%d and y =%d.n", x,y); getch(); return 0; }
  • 22. void callByValue(int x, int y) { int temp; temp=x; x=y; y=temp; printf("nValue of x =%d and y =%d inside callByValue function",x,y); } void callByReference(int *x, int *y) { int temp; temp=*x; *x=*y; *y=temp; }