Thread: why there is a void?

  1. #1
    Justin Klisk
    Guest

    why there is a void?

    i'm new in cprogramming.that's why i'm here?so,certain program there have a void and certain program there don't have void thing. what is it all about? it's not returning the value back to it.
    hope to know it as soon. "VOID"

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Well...void main is bad. But, I suppose you could be talking about a function not returning a value to the calling function.

    Which are you talking about?
    The world is waiting. I must leave you now.

  3. #3
    justin klisk
    Guest
    well,yes i'm talking about the function that not returning a value to the callling function.

    could u give me a example that i can refer to?plss...
    just two program,with void main and the other without void main.
    thanks a lot..i will be here today. Important.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    #include <stdio.h>
    
    void main ( void )
    {
    	printf("Hello World!\n");
    	return;
    }
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
    	printf("Hello World!\n");
    	return 0;
    }
    Don't use void main!
    Code:
    #include <stdio.h>
    
    int ReturnsSomething ( void );
    void DoesntReturnSomething ( void );
    
    int main ( void )
    {
    	printf("Checking return status of functions..\n");
    	printf("Press any key..\n\n");
    	getchar();
    	if ( ReturnsSomething() == 0 )
    	{
    		printf("He was nice.\n");
    	}
    	else
    	{
    		printf("He wasn't so nice!\n");
    	}
    
    	if ( DoesntReturnSomething() == 0 )
    	{
    		printf("He was nice.\n");
    	}
    	else
    	{
    		printf("He wasn't so nice.\n");
    	}
    	return 0;
    }
    
    int ReturnsSomething ( void )
    {
    	return 0;
    }
    
    void DoesntReturnSomething ( void )
    {
    	return;
    }
    Void main doesn't return a status. How can your operating system check the return status of a program that doesn't return a status? Your operating system expects you to return something, if you don't it gets confused, and it's also undefined behavior - that's not good.

    Search the board using the search function to read more on this.

    - edit -
    Heh, I'm not sure if that compare program will compile or not... ah well, search for void main ...and you got your 2 examples.

    Good luck.
    Last edited by Shadow; 02-09-2003 at 03:34 AM.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. game window rejected painting !
    By black in forum Windows Programming
    Replies: 4
    Last Post: 03-27-2007, 01:10 AM
  4. msvc just ate one of my source files
    By Eber Kain in forum C++ Programming
    Replies: 6
    Last Post: 07-01-2004, 05:40 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM