Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain the pointers for inter-function communication in C language.
We know that functions can be called by value and called by reference.
- If the actual parameter should not change in called function, pass the parameter-by value.
- If the value of actual parameter should get changed in called function, then use pass-by reference.
- If the function has to return more than one value, return these values indirectly by using call-by-reference.
Read Also: Function Call by Value in C and Function Call by Reference in C
Example
Following is the C program for the demonstration of returning the multiple values −
#include<stdio.h>
void main() {
void areaperi(int,int*,int*);
int r;
float a,p;
printf("enter radius of circle:
");
scanf("%d",&r);
areaperi(r,&a,&p);
printf("area=%f
",a);
printf("perimeter=%f",p);
}
void areaperi(int x,int *p,int *q) {
*p=3.14*x*x;
*q=2 * 3.14*x;
}
Output
When the above program is executed, it produces the following output −
Enter radius of circle: 5 Area=78.50000 Perimeter=31.40000
Note
- Pointers have a type associated with them. They are not just pointer types, but rather are the pointer to a specific type.
- The size of all pointers is same, which is equal to size on int.
- Every pointer holds the address of one memory location in computer, but the size of a variable that the pointer refers can be different.
Advertisements