Results 1 to 3 of 3

Thread: I jUst starteded! wHat is a C?

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    I jUst starteded! wHat is a C?

    Hey, I just started learning c++, I am using bloodshed 4 (beta5 looked better but it couldnt find iostreams.h for some reason) anyway, it is pretty straight forward so far, but 3 things:

    1. What is Enumeration? Can someone tell me what its for and an example.

    2. What would pointers be used for? *I think* they give you the memory address of where a variable is stored, or the value of that variable but why would you ever need to use pointers?

    3. How would I make variables public/private in C++? Do you just declare outside the function? what about something like 'static NAME as TYPE' in Vb, how would you do that in C++.
    asdf

  2. #2
    Addicted Member Buy2easy.com's Avatar
    Join Date
    Jul 2002
    Posts
    200
    a pointer is used to point to a place in memory. its use would be something like...if you have a function and want to return more than one thing back to the calling function. To do that you would need to use a pointer to the variables in the calling function and the new function would then change them and wala magically you can return more than one thing from a function w/o even saying

    return(whatever);

    for evample

    void
    Callme(int *item1, int *item2)
    {
    *item1 = 2;
    *item2 = 3;
    }

    int
    main(void)
    {

    int item1 = 1;
    int item2 = 2;

    callme( &item1, &item2);

    //now item1 & item2 from the main equal 2 and 3

    }


    but without it you would only be able to return 1 value w/ a return statement.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    bloodshed beta5 obviously doesn't include the deprecated .h headers anymore. Use <iostream>, <string>, <vector>, you get the idea. No .h.

    An enumeration is a set of named integral constants. A variable of an enumerated type can only have those values:

    Code:
    enum DaysOfWeek
    {
      Monday,
      Tuesday,
      Wednesday,
      Thursday,
      Friday,
      Saturday,
      Sunday
    }
    
    DaysOfWeek myDay = Monday;
    myDay now has the value 0, which is the first auto-assigned value of an enum.

    public/private:
    Code:
    class A
    {
      // things here are private
    public:
      // things here are public
    protected:
      // things here are protected
    private:
      // things here are private
      // static private variable
      static int count;
    };
    And there are more uses for pointers in addition to what Buy2Easy said. Dynamic memory is always referred to by pointer. You can use them to iterate through arrays.
    You'll get to know more uses for pointers as you learn more of the language.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width