Thread: C++ terms Questions

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    C++ terms Questions

    I want to know the meaning and relationship of the terms below as I get confused:
    1. Identifier
    2. Parameter and variable
    3. auto, register, extern, static, mutable
    4. and how to use enum in C++?

    Thx!!

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    1. Identifier
    2. Parameter and variable
    3. auto, register, extern, static, mutable
    4. and how to use enum in C++?
    I can answer most of those.

    A variable is simple. It is a variable in your program. Ex:

    int a;
    char *b;
    double c;
    float d;
    bool e;

    Those are all variables.

    A parameter is a variable you pass to a function. Ex:

    void myFunction ( int parameter1, double parameter2 );

    There are many different types of parameters, but no matter what type they are, they are all parameters - which means they are all variables passed to functions.


    I used to know auto, but not anymore, so I will go on to register.
    Computers have several registers. They are places that the computer can keep data for quick reference if the data needs to be called up quickly or is very important. There are only a certain amount of registers, however.

    You can declare a variable as a register variable, which means that it will use a register to be stored. If there are no registers available, it will just be allocated in normal memory. Ex:

    register int x;

    Next is extern. You can also declare variables as extern, which means the variable is declared in another source file. This is usually used in projects. Ex:

    extern int x;

    This will allow you to use the variable x even though it was declared in another source file. If you included the other source file using #include, then there is no need to use extern.

    Next is static. static means that once the variable goes out of scope, it is still there. It is most often used in functions.

    Ex:

    int GetX ( void )
    {
    static int x = -1;
    x++;
    return x;
    }

    That function declares a static int x and gives it the value -1. It then increments it to 0, and returns that value. Well, lets say we call the function again. Instead of doing that same thing, it would start at 0 and increment it to 1, and return 1. Then the next time it would return 2, then 3, then 4, etc. static variable can become invaluable in stuff like recursion, etc.

    I do not know what mutable is.
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Thx, How about "Identifier", "auto", "mutable", and how to use enum in C++?

    Thx!!~

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    oh yeah, enums. I forgot to answer the enums part.

    enum = enumerated variable

    ex:

    enum myenum {
    RED, BLUE, GREEN
    };

    Basically I just created three constants, RED, BLUE, and GREEN. RED = 0
    BLUE = 1
    GREEN = 2

    enums always start at 0, unless you assign values to the variables.

    you can also now say:

    myenum bob;

    That is like creating a variable of that data type, so that variable can only hold three values: 0, 1, and 2, or RED, GREEN, and BLUE.

    other examples:

    enum x
    {
    RED = 5,
    BLUE,
    GREEN
    };

    In that one: RED = 5, BLUE = 6, GREEN = 7

    another:

    enum y
    {
    RED = 6, GREEN = 8, BLUE = -5
    };

    That one is pretty obvious what each one equals.
    You do NOT have to use the . notation for enumerated values. You can refer to them like normal, global, constant variables.
    My Website

    "Circular logic is good because it is."

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    thx soo much!! but how about identifier?

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Identifier is just a name. It is just what it says it is.....

    struct point{
    int x;
    int y;
    }

    point is an identifier.

    auto is a keyword that is redundant now. It was used to state that a variable should be allocated on the stack as a local variable. But since all local variables are on the stack anyway it is not needed.It just means local scope.

    mutable is a keyword for use inside of a class.A const object may not alter any of the class members UNLESS they are declared mutable. Its like saying this object is const but parts of it can change if necessary.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Thx a lot!
    And that mean identifier, parameter, variable are all similar stuff, or highly related??

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Identifier is the name you give to things like variables, classes, structs, etc. Any name you give something is an identifier, and there are rules as to what characters you can include.
    The identifier of a variable is it's name.
    Parameters are variables that are passed to a function, but since not all variables are passed to functions, not all variables are parameters.
    To further confuse the issue, the parameters passed by a function are often called arguments in the receiving function.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    101
    Thx! But, Does it mean that identifier, parameter, variable are all similar stuff, or highly related?? Thx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  3. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  4. Various Variable Questions.
    By Zeusbwr in forum C++ Programming
    Replies: 6
    Last Post: 10-14-2004, 05:02 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM