help me

This is a discussion on help me within the C++ Programming forums, part of the General Programming Boards category; hi can any one give me an example of pointer??...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Unhappy help me

    hi

    can any one give me an example of pointer??

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    int* ptr;

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    #include <iostream.h>


    void main()
    {

    int var = 50;
    //next 2 lines create and initilize
    int *pvar;
    pvar = &var;

    cout << "The variable var, pointed to by pvar, is: ";
    cout << *pvar << ".\nvar is located at adress: ";
    cout << pvar << endl;
    }

    the benifit of this is you can manipulate variables that are out of scope (if you want to change a variable outside your function or whatever you can pass the adress)
    =@-OmegatronO-@=

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >the benifit of this is you can manipulate variables that are out of scope
    The disadvantage is that your whole program is undefined. Don't use void main.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    2
    thanks

    thanke you v mat.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    sry bout that
    twas just an example
    =@-OmegatronO-@=

  7. #7
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    what is so bad about voiding main()? In my c++ class, we were told to not even delcare main(), as such:

    Code:
    #include <iostream.h>
    
    main()
    {
          cout << "Hello";
          return 0;
    }

    It obviously does the same as int main(), but still, why at all?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >what is so bad about voiding main()?
    It's wrong, the standard specifies that main is to return an int, if it doesn't you never know what will happen. The chances of something horrible happening really are slim, but that doesn't make an undefined construct any safer.

    >In my c++ class, we were told to not even delcare main()
    That's acceptable since an empty return value is implied to be int. Personally, I prefer to stay as standard as I can and the standard says either
    int main ( void )
    or
    int main ( int argc, char **argv )

    When I was learning C, my instructor recommended the use of void main. At the time I thought he was amazing but now I realize that his knowledge of both the language in general and the standardized language was very basic. The point is, don't always believe the first thing you're told, research it and find out for sure if it's correct, you never know when the person teaching you is only one step ahead of you in learning. Though since I've shunned void main I've forever alienated myself from that job at Microsoft.

    -Prelude
    My best code is written with the delete key.

  9. #9
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    return value

    howdy,
    the way i understand it is that the OS CAN react negatively to a return value other than 0 when execution end thus:
    int main()
    {....
    .....
    .....
    return 0;
    }

    signals the OS that execution ended cleanly.

    M.R.

  10. #10
    Unregistered
    Guest
    (if you want to change a variable outside your function or whatever you can
    pass the adress)
    what do you mean?

Popular pages Recent additions subscribe to a feed

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