Page 64 - DCAP404 _Object Oriented Programming
P. 64
Unit 3: Review of Functions
The main method can take various forms as listed below: Notes
main()
main(void)
void main()
void main(void)
int main()
int main(void)
int main(int argc, char *argv[])
main(int argc, char *argv[])
void main(int argc, char *argv[])
As is evident from the above forms, return type of the main method specifies the value returned
to the operating system once the program finishes its execution. If your main method does not
return any value to the operating system (caller of this method), then return type should be
specified as void.
!
Caution In case you design your main method in such a way that it must return a value to
the caller, then it must return an integer type value and therefore you must specify return
type to be int.
Self Assessment
Fill in the blanks:
1. A function is a group of ………………. that is executed when it is called from some point
of the program.
2. The execution of the program starts from the function …………….. .
3. The …………………… specifies the type of the data the function returns.
4. The …………………… list could be empty which means the function do not contain any
parameters.
5. A function declaration is same as the declaration of the…………………... .
3.2 Function Overloading
A function may take zero or more arguments when called. The number and type of arguments
that a function may take is defined in the function itself. If a function call fails to comply by the
number and type of argument(s), the compiler reports the same as error.
Suppose we write a function named sum to add two numerical values given as arguments. One
can write the function as:
int sum(int a, int b)
{
return (a + b);
}
LOVELY PROFESSIONAL UNIVERSITY 57