void

This is a discussion on void within the C++ Programming forums, part of the General Programming Boards category; what does the void command mean and how do you use it in programming? Sorry for being such a noobie ...

  1. #1
    C++ and openGL Raeliean's Avatar
    Join Date
    Jul 2005
    Posts
    28

    void

    what does the void command mean and how do you use it in programming?
    Sorry for being such a noobie ^^;
    Be inspired.

  2. #2

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Here is an example of when void would be used:

    Code:
    #include <iostream>
    
    using namespace std;
    
    void example()  // example is a function, but I have voided it so it returns nothing to main
    
    int main()
    {
    
    example(); // this calls the function example
    
    return 0; 
    }
    
    void example() // you can now use the function as main has called it
    {
    
    code for exapmle would go here{
    return; // return nothing to main as example is void
    }
    this is just one example of it's use in a function, but void has one golden rule:

    Never use the command 'void main()' as main must ALWAYS return an integerger or int

  4. #4
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    void means no type. As in, no return type for a function, so it doesn't have to return anything. Or a void pointer can be casted into a pointer of any other type.

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

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