ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It means the return value of the main function. When void, the compiler assumes that you don't want to return a value and so returns 0 to the shell (or whoever was the invoker of the program/function). You can read the return value from shell directly by saying 'echo $?' after the command or implicity by && and || operators.
Writing the return value is done by saying something like
'return 27;' in the end of the function.
..and "int" means that the main() function returns a integer (..., -85, 0, 1, 2, ) and "void" means that main() does not return anything. You could say that the "void"-version is less complete. If you run the compiler (gcc) on it with strict syntax-checking (gcc's -Wall -pedantic options), it will output a warning about this.
Also, the "int"-version should end with:
return 0; /* or some error code: 1,2,3... */
Because main is defined to return a integer number, and without a "return <number>" it would not comply to that.
Normally a program should return such an error code to the calling program
void is a C datatype, commonly used for functions that could have all kinds of data for arguments.
For instance, bsearch(), qsort() are standard parts of the C library.
They require that the last argument to the library call be a function pointer. The function prototype they expect is like this:
Code:
int compare(void *, void *);
meaning that you can pass it pointers to anything: an int, a double, a struct, etc. That is what K & R meant when creating the void datatype.
It doesn't just mean 'nothing' it really means 'anything you want'
What you say is true about void * but not for void. void * is a different type to void, one is a pointer type and the other is not a type, unless you consider 'the lack of' as a type.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.