One important thing I dont really get.

This is a discussion on One important thing I dont really get. within the C++ Programming forums, part of the General Programming Boards category; Im reading "Sams Teach Yourself C++ in 21 days" and Im on day 6 now, but its one simple thing ...

  1. #1
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90

    One important thing I dont really get.

    Im reading "Sams Teach Yourself C++ in 21 days" and Im on day 6 now, but its one simple thing I just dont get.

    How do you know when to use like:
    int, void, float, double etc etc

    There are diffrent things in all examples but I dont get how you know which one to use.

    Like:
    Code:
    int MyFunc();
    void Myfunc();
    //Which to use when?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Well does your function return anything useful - like an answer or an error state or not?

    If it doesn't return anything useful, then return void.

  3. #3
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    I mean sometimes the book uses "void function" or "int function" or "unsigned int function".
    I dont know whats the diffrence between them all.
    Where do I use what?

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    A function can have a return value. If it doesn't, then it's void. If it has, you need to consider: what does the function return? Is it an integer that can be negative? Then it's int. An integer that cannot be negative? Unsigned int. A floating point number? float or double (double is more precise). A string? Std::string.

    The answer comes naturally after looking at the problem.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very strange thing
    By gustavosserra in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 12:43 PM
  2. most challenging thing to program
    By volk in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 03-28-2003, 02:56 PM
  3. newbie needs help comprehending simple thing
    By A helpless one in forum C++ Programming
    Replies: 6
    Last Post: 12-16-2002, 08:23 PM
  4. What's The Most Important Thing To Learn In C++?
    By DeanDemon in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2002, 05:49 PM

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