I'm kinda new to C++

This is a discussion on I'm kinda new to C++ within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I'm a little new to C++, but I do know some useful things. I already know quite a ...

  1. #1
    Registered User DeanDemon's Avatar
    Join Date
    Nov 2002
    Posts
    37

    Unhappy I'm kinda new to C++. and I need some help!

    Hi everyone,

    I'm a little new to C++, but I do know some useful things. I already know quite a bit about it, but there are some things giving me troubles.

    For one thing, I'm not quite sure what the difference between long unsigned ints, and short signed ints is at all. It confuses me since there're four types of intengers, and I'm not quite sure what the difference is between them all.

    Secondly, when I put in a prototype for my function, type in some parameters, and then branch off to that particular function, it never works for some reason. I dont understand the need for function prototypes and parameters.
    Last edited by DeanDemon; 11-28-2002 at 07:52 PM.
    -Dean

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: I'm kinda new to C++

    Originally posted by DeanDemon

    For one thing, I'm not quite sure what the difference between long unsigned ints, and short signed ints is at all. It confuses me since there're four types of intengers, and I'm not quite sure what the difference is between them all.
    First, the difference between signed and unsigned just means that if it's signed it can have both non-negative and negative numbers, while unsigned is strictly non-negative numbers.

    The following examples assume a standard 8-bit byte

    Of the standard integer types, you basically have

    // These must be one byte in size
    unsigned char // 0 through 255
    signed char // -128 through 127

    // Must be at least 2 bytes
    // The following examples assume 2-bytes
    unsigned short int // From numbers 0 through 65535
    signed short int // -32768 to 32767

    // Must be greater than or equal to sizeof( short int )
    // The following assumes 4-bytes
    unsigned int // 0 through 4294967295
    signed int // -2147483648 through 2147483647

    // Must be greater than or equal to sizeof( int )
    // The following assumes 4-bytes
    unsigned long int // 0 through 4294967295
    signed long int // -2147483648 through 2147483647


    Originally posted by DeanDemon

    Secondly, when I put in a prototype for my function, type in some parameters, and then branch off to that particular function, it never works for some reason. I dont understand the need for function prototypes and parameters.
    You need prototypes lots of times for complex applications and where not everything in your project is not in one compilation. Linking isn't actually done until after compilation -- it's 2 different phases. Also, what if the definition is in another file? It would take a long time for the compiler to search because it could be anywhere, but the only information you need at compile time is that the function exists, has certain parameters, and returns a certain type of value. Therefor you can just put the prototype in a common place included by both files.

    Prototypes aren't always necissary in a single file project if you just put the definiton before you call it, however, you can't always do that IE if you have 2 functions which call each other.

    If you need more of an explanation, I'm sure someone'll respond. I'm gonna go to mcdonalds now for my thanksgiving dinner. Bye!

  3. #3
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    I never use prototypes i just do something like this:

    Code:
    #include <iostream.h>
    #include <windows.h>
    int number;
    void hello(int amount)
    {
       for(int x;x<amount;x++)
       {
        cout<<"\nHello";
       }
    }
    
    int main()
    {
     cout<<"How many Hello's?: ";
     cin>>number;
     hello(number);  //call the function with the number amount of hello's
     return main();  //just because you want it to stay open or repeat it self
    }
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  4. #4
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    uhh sorry you can leave out the

    #include <windows.h>
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

  5. #5
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    You can hold off on using prototype for a little while until you learn the language better and have to make larger programs, prototypes are however intending to make things easier and faster in a lot of ways, so eventually you should start using them.

  6. #6
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    they're not easier they make things harder

  7. #7
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    Originally posted by devour89
    I never use prototypes
    Do you at least use prototypes when designing/implementing classes?

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by devour89
    I never use prototypes i just do something like this:
    Well that's limiting yourself to just using 1 file or solely inline functions.

    Prototypes are necissary with multiple files in one project, where one file calls a function from another.

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    if you're thinking about the same 'function parameters' as I am, they're usually called arguments. Functions have to have arguments because they usually have to have some type of data to perform their task, like a function that multiplies 2 numbers would need those 2 numbers before it could multiply them. Could you give us a code example of function prototypes and calls that doesn't work? Someone might be able to help you better if you do.

  10. #10
    Registered User DeanDemon's Avatar
    Join Date
    Nov 2002
    Posts
    37

    Talking Thanks, people!

    I finally got functions down.( After 4 days) Now, I can move on and learn new things in C++. Celebrate gewd times, C'MON!
    -Dean

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math Parser thingy.....it's kinda cool
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 06-17-2005, 02:53 PM
  2. String Reversal (kinda different from the rest)
    By actionwillspeak in forum C Programming
    Replies: 19
    Last Post: 02-17-2005, 01:32 PM
  3. Dos Graphic....kinda
    By Xeavor in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:14 AM
  4. Kinda surprised no one has mentioned this ("Under God" Decision")
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 84
    Last Post: 06-21-2004, 09:45 PM
  5. Explanation and its kinda cool
    By CAP in forum C Programming
    Replies: 4
    Last Post: 07-24-2002, 05:12 PM

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