C - Assign values to variables through function by Call by Reference.
Call by Reference - In this technique we pass address (pointer) of variables instead of actual variables, any changes made to the variables will reflect to actual variables.
In this code snippet program will assign values to the variables through function by using Call by References.
C Code Snippet - Assign Values to Variables using function - Call by Reference
/*C - Assign value to variables
through function by Call by Reference.*/
#include <stdio.h>
void assignValues(int *x, int *y){
*x=10;
*y=20;
}
int main(){
int a,b;
//assigning values
assignValues(&a,&b);
printf("After assigning values from function a: %d, b: %d\n",a,b);
}
After assigning values from function a: 10, b: 20