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?

15th Sep 2016, 4:56 PM
Aditya Gupta
4 odpowiedzi
+ 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.
16th Sep 2016, 7:31 AM
Davood Abdollahi
Davood Abdollahi - avatar
+ 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.
15th Sep 2016, 5:29 PM
Abhishek Narwal
Abhishek Narwal - avatar
0
it will be easy to explain if you show me the code.
15th Sep 2016, 5:30 PM
Abhishek Narwal
Abhishek Narwal - avatar
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.
16th Sep 2016, 1:20 AM
Tayo
Tayo - avatar