JE> Hmmm This may sound a little strange to you guys that have been doing
this
JE> for awhile..But can someone please explain the use of void and tell me
JE> what it does when it is on the left, right and on both sides..
Ok, A VIOD is a value that is not required (to put it simply) ...
in a program where you use say a function called : DOHAPPY();
and the function requires no parameters, then it would be declared as :
* DOHAPPY(VOID);
The void as seen in the example above tells the compiler that when the
function is used in the code, that you dont have to supply it with
rameters.
In the example there is a * meaning the return type.
The 'Return Type' (simply) is what you wish to return the information in. Eg:
CHAR *DOHAPPY(VOID);
This function requires no parameters so is (VOID) and will return information
to the main routine or whatever routine it is declared from in a string, such
as : "THIS IS A STRING".
And if you do not require a return value then you will supply the function
with a void at the start eg :
VOID DOHAPPY(VOID);
Which will perform a function that requires NO RETURN VALUE and NO
RAMETERS.
If that is not a good enough explanation, heres an example :
void main(void);
void dohappy(void);
void main(void) {
dohappy(); -- Note that this function has no parameters and no variable
to return a value to.
-- Note that there is no RETURN statement at the end of the
function, because it is a VOID function.
}
void dohappy(void) { -- This is our void function as the main function
Nothing will be returned, no parameters are required.
--- DO FUNCTION ---
-- And again there is no return value because this is a
VOID statement (function or whatever).
}
Hope this was a lot of use, cos it took me 5 minutes of my life to type out.
And if it was, that is good, hope it helps some of the learners out there.
-=- DANIEL HEBBERD -=-
--- Renegade v666 dMp
---------------
* Origin: dMp ][, Man can not live on Toons alone... (3:774/750)
|