void-help

This is a discussion on void-help within the C++ Programming forums, part of the General Programming Boards category; void means "don't return value" right? but wat does don't return value different from the normal ones....

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    15

    void-help

    void means "don't return value" right? but wat does don't return value different from the normal ones.
    S.b

  2. #2
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    pretend that the type of the function, i.e. the type presented before the function:
    Code:
    int blah()
    is what is going to be replaced where the function was called.
    Example:
    Code:
    int add() {
    	return 1+1 ;
    }
    
    int main()
    {
    	int j=0;
    	j=add(); 
    	return 0;
    }
    the blue is the function being called and the type is int
    in main, WHERE it is called (red) you can pretend that you can replace that location with what it returns. (1+1, or just flip the reds)

    however, with void...
    Code:
    void  add()
    {
    	return ; 
    }
    int main()
    {
    	add(); 
    	return 0;
    }
    in the void add() function.. it doesn't return anything so, in the main, you can't replace the location where you called it with anything (the red).

    I am sorry if this is unclear. I tried to explain it as simply as I could

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    You can use a void function for a lot of things. Say u wanted a function to just out put some information
    Code:
    void output()
    {
        cout << "HEllo"<<endl;
    }
    
    
    int main()
    {
      output();
      return 0;
    }
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    If there is no meaningful value that your function could return, then it shouldn't return anything, and consequently, have a void return type.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Originally posted by Zach L.
    If there is no meaningful value that your function could return, then it shouldn't return anything, and consequently, have a void return type.
    just like void main() !

    just kidding
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    15

    confused

    i still not understand by "return a value".Whether void or not,u will still get the value of the whole nest thing
    S.b

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    118
    Well I'll am not very sure but what I understand by return values is this: when you make a function, the compiler leaves space in the stack for the return value, that can be an int, a bool, a double or anything like that, but when you make a void function, it leaves no space for the return value. You may want to google what the stack is, then it will be much clear, I dont know how to explain it... sorry.
    Why drink and drive when you can smoke and fly?

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, 02:01 AM
  2. Replies: 3
    Last Post: 05-13-2007, 09:55 AM
  3. game window rejected painting !
    By black in forum Windows Programming
    Replies: 4
    Last Post: 03-27-2007, 02: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, 06:40 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21