0
Can someone explain the first chapter of functions?
I am confused. For eg, why is a function declared by void data type first and then followed by same function by int data type?
4 Answers
+ 2
Functions will Either return a value (a number) Or they do not return a value.
If they return a value, they will be declared as int.
If they do not return a value, they will be declared as void.
Void functions are usually to print (cout) something.
Although void functions will not return a value(number), they need parameters (usually int) to do some operations and print the processed parameter.
+ 1
function with void data type is declared because we dont want to return any value and function with int return type is used to return int types.
0
it will be easy to explain if you show me the code.
0
if you take a look at eg int addvalues(int a, int b){int a=40; int b = 60; int result = a+b; return result}
we are returning an int value as you can see in "int addvalues"
the int in int addvalues is telling us that this function is returning an int value which is result.
"return result"
but in void, there is no such thing like that.
its not returning anything.