Function calls

After a function is declared and defined, it can be called from anywhere within the program: from within the main function, from another function, and even from itself. Calling the function involves specifying the function name, followed by the function call operator and any data values the function expects to receive. These values are the arguments for the parameters defined for the function. This process is called passing arguments to the function.

You can pass arguments to the called functions in three ways:
  • Pass by value, which copies the value of an argument to the corresponding parameter in the called function;
  • Pass by pointer, which passes a pointer argument to the corresponding parameter in the called function;
  • C++ only Pass by reference (C++ only), which passes the reference of an argument to the corresponding parameter in the called function. C++ only

Begin C++ only If a class has a destructor or a copy constructor that does more than a bitwise copy, passing a class object by value results in the construction of a temporary object that is actually passed by reference.

The compiler generates an error when a function argument is a class object and all of the following conditions are true:
  • The class needs a copy constructor.
  • The class does not have a user-defined copy constructor.
  • A copy constructor cannot be generated for that class.
End C++ only

Begin C onlyA function call is always an rvalue.End C only

Begin C++ onlyA function call belongs to one of the following value categories depending on the result type of the function:
  • An lvalue if the result type is an lvalue reference type Begin C++11 onlyor an rvalue reference to a function typeEnd C++11 only
  • Begin C++11 onlyAn xvalue if the result type is an rvalue reference to an object typeEnd C++11 only
  • A Begin C++11 only(prvalue)End C++11 only rvalue in other cases
End C++ only