In this simple C code example we tried to show the difference between function call by value and call by reference in C programming. In function call by value the original variables are not affected because the values are copied inside function definitions. Whereas in function call by reference the original variables are affected because we pass the memory addresses inside function definitions. [js] #include <stdio.h> void swapCallByValue(int x1, int y1); // this is prototype of our function (call by value) void swapCallByReference(int *x1, int *y1); // this is prototype of our function (call by reference) int main(void){ // in...
forward
Month: January 2018
Functions in C Programming – Code Example
For simplicity we divide our code into small pieces / modules known as functions. To use functions in C programming we need to define function prototype, function definition and finally we call the function to perform that functionality. Here we will define a simple sum function, which will accept 2 numbers as an input and will return sum of these numbers. [js] #include <stdio.h> int sum(int x, int y); // this is prototype of our sum function. int main(void){ // for simplicity we divide our code into small pieces / modules known as functions // to use functions in C programming...
forward
forward