delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/13/08:16:59

From: "J. van Eijnsbergen" <hanvane AT worldonline DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Main + Void
Date: Thu, 13 Mar 1997 13:16:04 -0800
Organization: ZIN http://www.worldonline.nl/~hanvane/zin.htm
Lines: 61
Message-ID: <33286E94.5435@worldonline.nl>
References: <01bc2f01$9891dc60$7cae71a5 AT mod DOT exo DOT com>
Reply-To: hanvane AT worldonline DOT nl
NNTP-Posting-Host: drdt2-p29.worldonline.nl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

MoD wrote:
> 
> just a quick question.. the "Main" part... is that the main body of the
> code?
> and what is "void" used for? =)
> 
> PS
> hope everyone is patient enuff to get me through these beggining stages =)


Hello MoD,

I am only a beginner too, so maybe we can help each other.

MAIN() is the main part of a c/c++ program (it has to be there).
So in main you can call other routines for instance routine1 and
routine2.
The term VOID means that there are no variables to return.
In the following example main calls 2 routines (1 and 2).
Routine1 only prints something on the screen and routine2 calculates
something.
In routine1 you can use VOID (cause no numbers have to be returned to
the main program).
In routine2 the program calculates something (an addition) so VOID
cannot be used. Numbers are returned (in this case the answer). 

The example:
======== this is just an example (no true c-code)=======
main(void)
{
var1=1
var2=1
routine1();                 // call routine1
answer=routine2(var1,var2); // call routine2
printf ("1+1=%d\n",answer); // or in C++ you can use COUT
}
/********
routine1(void)
{
 printf("This program calculates 1 + 1\n");
}
/********
int
routine2(A,B)
{
result=A+B
RETURN(result)
}
======== this is just an example (no true c-code)=======

As I said the above is no true (to be compiled) c-code. I did not
declare any variables and routines; this to keep it short (if you need
the real working c-code, e-mail me, I will send it to you).

I hope the VOID thing is clear now.
Greetings from Holland,
-- 
Han van Eijnsbergen
hanvane AT worldonline DOT nl
http://www.worldonline.nl/~hanvane/index.html
http://www.worldonline.nl/~hanvane/zin.htm

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019