Sunday, August 26, 2018

Functions

In c language, the main function doesn't return any value or void.

But default return type of main function is int in c++.

So we need to add 'return 0' statement at the end of main function block.

Some compilers take the return value as int even if we don't declare the type in main.some give warning and some give error... So it is best to mention return type.

Function prototype of main.

int main();
int main(int argc,char* argv[]);

In c, function declaration is not compulsory.But in c++ it is mandatory.the compiler cross checks with prototype whenever we call a function.it checks the return type and number of arguments and their type.

Function prototype:
type function-name(arg-list);

Arg-list means the type also along with names(not compulsory as dummy).

In c, empty parenthesis refers to variable no. of arguments but here it is void.to have variable no.of args or open parameter list here we use
void dosome(...);

The parameters passed doesn't effect the original variables..a local copy is created there.to effect them use call by reference.with &

int& max(float&)-- both args and return types are by reference.
As return by reference is there, we can call it to assignment.
max(a,b)= 56;

Inline functions are replaced by the original code by compiler.

No comments:

Post a Comment