pointers

This is a discussion on pointers within the C++ Programming forums, part of the General Programming Boards category; Look at my last post Code: #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::dec; int main() { int ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    164

    pointers

    Look at my last post


    Code:
    #include <iostream>
    #include <iomanip>
    
    using std::cout;
    using std::endl;
    using std::dec;
    
    int main()
    {
    	int number = 25;
    
    	int* pNumber = &number;
    
    	cout << endl
    		<< dec << pNumber << endl;
    
    	return EXIT_SUCCESS;
    }
    Last edited by manzoor; 08-25-2008 at 07:18 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Your hard-disk is full?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    Oh lol,


    Well, one drive is full,

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by manzoor View Post
    Oh lol,


    Well, one drive is full,
    In this case, you can probably overcome the problem by setting the environment veriable temp to something else - I usually set it to x:\temp wher x is some drive that has lots of space. You can either restart your dev environment from a command prompt after "set temp=x:\temp" or configure your system settings (My computer -> Properties -> Advanced -> Environment Variables). You may want to set the environment variable "TMP" as well.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    Okay thanks,

    One more question to ask, prior to the code

    the pNumber should return the address in decimal but it doesnt why ?

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    the pNumber should return the address in decimal but it doesnt why ?
    That's how pointers are displayed. std::dec probably only applies to how real numeric types are output.

    To display it as an integer (you don't need std::dec), you'll need a cast:
    Code:
    reinterpret_cast<int>(pNumber)
    And lastly an observation: you use cout, endl and dec just once, yet went through all the trouble to type the using directives ... for what?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by anon View Post
    To display it as an integer (you don't need std::dec), you'll need a cast:
    Code:
    reinterpret_cast<int>(pNumber)
    Note that a pointer is not guaranteed to fit in an int - it may be twice as big (or even larger, at least in theory).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    On Windows, it's possible to include windows.h and use INT_PTR. It's guaranteed to fit.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Then cast to size_t?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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