Site icon Gloritech

Parameters vs Arguments in C/C++

When the topic is Function, there are some misunderstandings about what concerns parameter and argument of a function. To create a function in C/C++ , we need to define a return type(void, int, char, float, etc), a name and at least, one variable as the formal parameter.

An exemple in C:

#include<stdio.h>

/*Here, “power” is the name of function, in which represents a mathematical function for any given number (base) raised to some defined number(exponent). Or, any number multiplied by itself for an specific number of times(so called the exponent). */

int power(int base, int n) /* base and n are the formal parameters of the function named power*/

{int p=1;for(int i=1; i<=n; ++i)

p*=base;

printf(“POWER FUNCTION:%d To The Power of %d is: %dn”, base,n,p);

}

int main() { 

power(3,4); /* in main function, we call the function power with two arguments: the int variables ‘base’ and ‘n’, represented by the values of 3 and 4) */

}

Exit mobile version