Function
1. The C standard C00 allows inline functions. Inline is a request.
inline int max(int a, int b)
{
if(a > b)
return a;
else
return b;
}
a = max(x,y);
/*
This is now equivalent to
if(x > y)
a = x;
else
a = y;
*/
2. In C, printf() returns the number of characters successfully written on the output and scanf() returns number of items (not characters) successfully read.
3. In C, return type of getchar(), getc(), fgetc() is int (not char). So, assign the returned values to an integer type variable.
4. Variable Argument
#include<stdarg.h>
#include<stdio.h>
double average(int num, ...)
{
va_list arguments; // A place to store list of arg
double sum = 0;
va_start(arguments, num); //Init arg
for(int x = 0; x < num; x++)
sum += va_arg(arguments, double);
va_end(arguments);
return sum;
}
int man()
{
cout << average(3, 12.2, 22.3, 4.5);
}