const variable

This is a discussion on const variable within the C++ Programming forums, part of the General Programming Boards category; Why I need to typecast a const variable for outputiing it's address. Code: const int i=39; cout<<(void *)&i;//Works Ok cout<<&i;//Error ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    113

    const variable

    Why I need to typecast a const variable for outputiing it's address.
    Code:
    const int i=39;
    cout<<(void *)&i;//Works Ok
    cout<<&i;//Error illegal structure operation.

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Quote Originally Posted by vaibhav
    Why I need to typecast a const variable for outputiing it's address.
    Code:
    const int i=39;
    cout<<(void *)&i;//Works Ok
    cout<<&i;//Error illegal structure operation.
    AFAIK...there is no need to typecast to get the address..it should work fine.....anyways what compiler are u using

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    113
    Does it work fine on your compiler?I am using turbo c++.Do check it on your compiler.

  4. #4
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Quote Originally Posted by vaibhav
    Does it work fine on your compiler?I am using turbo c++.Do check it on your compiler.
    Stop using that compiler...its 15 year old compiler...does not follows all standands....
    Go for DEV C++ Compiler......You can download it from here
    http://www.bloodshed.net/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function template has already been defined
    By Elysia in forum C++ Programming
    Replies: 19
    Last Post: 04-14-2009, 11:17 AM
  2. The so annoying LNK2005... please help!
    By Mikey_S in forum C++ Programming
    Replies: 14
    Last Post: 02-01-2009, 04:22 AM
  3. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 09:32 AM
  4. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM

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