Thread: Void? Help me!!!!!

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    10

    Void? Help me!!!!!

    I've been making lots of progress in C++ in the last couple of days.

    But when I got to the part on the tutorial about switch case, it introduced the word "void"
    Because there is no explanation, I don't get it.
    Will somebody please help?
    Cprogramming.com Tutorial: Switch-case structure

    Code:
    using namespace std;
    
    void playgame();
    void loadgame();
    void playmultiplayer();
    	
    int main()

    Thanks a bunch

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    void used as a return type basically means that a function will not return anything. In this snippet, it simply means that those 3 functions aren't returning anything.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    10
    what do you mean by not returning anything?

  4. #4
    Registered User NathanOliver's Avatar
    Join Date
    Jun 2010
    Posts
    2
    Not returning anything means that the function ends without returning a value to the function that called it. Take this for example
    Code:
    int Foo(int bar)
    {
        return n + 5;
    }
    Here we said Foo is a function that takes an integer and returns an integer. Now lets say we want to write a function to print something to the screen. We don't need the function to return a value like the previous function did. All it needs to do is print a message so you would write
    Code:
    void Print()
    {
        cout << "This is a message.";
    }
    Now we have the function print. It doesn't take in any parameters and it doesn't return anything after it is called. You do not need a return statement because execution ends at the end of the function because it is void. You can add a return statement but it is not really necessary.
    Code:
    void Print()
    {
        cout << "This is a message.";
        return;
    }

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The previous lesson on functions does make some comments about void functions.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matrix operations using objects
    By circuitbreaker in forum C++ Programming
    Replies: 7
    Last Post: 05-04-2010, 08:53 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 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

Tags for this Thread