What is the meaning of 'declare a function'?

21st Dec 2015, 1:02 PM
Prashant Bharduaja
Prashant Bharduaja - avatar
2 Answers
+ 1
Declaring a function means that you tell the compiler 3 things 1. name of the function 2. return type of function 3. function arguments and their data type. it is done as follows: int sum(int x, int y); here we telling the compiler that the name of function is "sum", it returns integer value and accepts two arguments both of integer type.
3rd Jan 2016, 8:16 AM
Priyansh Gangwar
Priyansh Gangwar - avatar
There are two parts creating a function in C++, you need to declare it and then you need to define it. Declaring it tells the compiler the name return type and arguments, defining it tells the compiler what the function actually does. You can do these things in the same place or separately, but the function must be declared before it is called. You do not have to define it before it is called.
14th Jan 2017, 11:16 PM