In this video tutorial lets learn how to add two integer numbers using functions in C programming language.
Related Read:
Function / Methods In C Programming Language
Addition of 2 Numbers: C
Video Tutorial: Addition of 2 Numbers using Function: C Program
[youtube https://www.youtube.com/watch?v=1fmOsKbnTxQ]
Source Code: Addition of 2 Numbers using Function: C Program
#include<stdio.h> int add(int, int); // function prototype int main() { int a, b; printf("Enter 2 integer numbers\n"); scanf("%d%d", &a, &b); //function call add(a, b); printf("%d + %d = %d\n", a, b, add(a, b)); return 0; } //function definition int add(int x, int y) { return(x+y); }
Output 1
Enter 2 integer numbers
25
25
25 + 25 = 50
Output 2
Enter 2 integer numbers
50
5
50 + 5 = 55
Here we call user defined function add from within printf() function. We pass 2 integer variables as argument to add method. The values of variable a and b are copied to variable x and y. Note that values of variable x and y are local to function add and main function do not know values of x and y. x and y are separate copy and altering which do not alter the value of variables a and b.
a and b are called actual arguments.
x and y are called formal arguments.
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert