I'm reading about C++, and I've come across 'Functions'. I think they're like Labels in ASM (Kind of). Also there's something about 'Returning things';
void someFunction
{
//Code goes here
return;
}
According to the book, return means to return a value. Void also means nothing..?
Sorry if my syntax is a bit rusty, I've been learning for only a few days. Thanks for any help!
Void means that function will return nothing. You wouldn't need to have a return in that function.
Advice to start out C is to buy a Sams or Dummies buck on C or C++ and just go through it the slow way. Takes time but if you enjoy it, its all good.
I have the dummies book
Think of functions as a black box. When functions are called, inputs go into the box, are processed, and then sometimes values come out.
(inputs) -> { processing } -> return outputs..?
Functions have a parameter list that tells you all the inputs, usually denoted with ()'s. The guts/plumbing/details are in {}'s. Most but not all functions return values to the caller.
For instance, a simple function might be
int add(int x, int y)
{
return x + y;
}
When someone calls this add function, it requires two values (also sometimes called arguments). These two values correspond to the two inputs in the parameter list. It will then do some work (in this case, add x and y together), and then give that result back to the caller.