WiiRd forum

Off-topic => Off-topic => Topic started by: doomkaiber001 on December 21, 2010, 09:22:40 AM

Title: Functions (C++)
Post by: doomkaiber001 on December 21, 2010, 09:22:40 AM
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!
Title: Re: Functions (C++)
Post by: Nuke on December 21, 2010, 01:29:11 PM
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.
Title: Re: Functions (C++)
Post by: doomkaiber001 on December 25, 2010, 05:58:27 PM
I have the dummies book
Title: Re: Functions (C++)
Post by: dcx2 on December 26, 2010, 10:21:26 PM
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.