Explain Call by Reference in C language ?
Call by value
- In call by reference, original value is modified because we pass reference (address).
- Here, address of the value is passed in the function, so actual and formal arguments shares the same address space. Hence, value changed inside the function, is reflected inside as well as outside the function.
Sample Code
#include<stdio.h>
void change(int *num)
{
printf("Before adding value inside function num=%d \n",*num);
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}
int main()
{
int x=100;
printf("Before function call x=%d \n", x);
change(&x);
printf("After function call x=%d \n", x);
return 0;
}
Output
Before function call x=100
Before adding value inside function num=100
After adding value inside function num=200
After function call x=200
Categorized in:
Tagged in:
Accentur interview questions and answers, Applied Materials interview questions and answers, Asian Paints Ltd. interview questions and answers, Bosch India Software interview questions and answers, C Call by Reference: Using pointers, C++ function call by reference, call by reference, call by reference definition, Call By Reference Example C Program, call by reference in c without pointers, call by reference in c++, call by reference in java, call by value and call by reference, Call by Value and Call by Reference in C, call by value and call by reference in c with example, call by value and call by reference in java, Call by vlaue, Capgemini interview questions and answers, CASTING NETWORKS INDIA PVT LIMITED interview questions and answers, CGI Group Inc interview questions and answers, Chetu interview questions and answers, Ciena Corporation interview questions and answers, Collabera Technologies interview questions and answers, define call by reference, Dell International Services India Pvt Ltd interview questions and answers, DHFL Pramerica Life Insurance Company Ltd interview questions and answers, difference between call by value and call by reference, Difference Between Call by Value and Reference in C, Elico HealthCare Services Ltd interview questions and answers, Flipkart interview questions and answers, Function call by reference in C, HCL Technol interview questions and answers, IBM interview questions and answers, Indecomm Global Services interview questions and answers, Mavenir interview questions and answers, Mphasis interview questions and answers, NetApp interview questions and answers, Oracle Corporation interview questions and answers, PeopleStrong interview questions and answers, plintron interview questions and answers, R Systems interview questions and answers, Raqmiyat Information Technologies Pvt Ltd interview questions and answers, Reliance Industries Ltd interview questions and answers, SAP Labs India Pvt Ltd interview questions and answers, Tata AIA Life Insurance interview questions and answers, Tech Mahindr interview questions and answers, The Linde Group interview questions and answers, what is call by reference, What is function call by reference