C

This is a discussion on C within the C Programming forums, part of the General Programming Boards category; WHY THE THE int POINTER STORES ONLY int TYPE OF DATA VARIABLES ADDRESS....

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    vizag,A.P.,INDIA
    Posts
    2

    C

    WHY THE THE int POINTER STORES ONLY int TYPE OF DATA VARIABLES ADDRESS.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Not sure what you are asking.

    An int pointer can be forced to point to "anything" - but it will not necessarily allow you to read a pointer from that location.

    Code:
    int *p = (int *)0x1234567;
    will set the pointer p to point at address 0x1234567 - which may not even be a valid address to read in your system, and is not aligned to a int boundary, so it may fail to read an int for that reason too. But you can set an int pointer to anything.

    The type of a pointer [in most architectures] only indicate how the compiler should generate the code that dereferences the pointer - such as the size of the resulting memory access.

    --
    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
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,308
    STOP SHOUTING!

    Anyway, read the homework policy. The question does sound a little strange to me though - an int pointer is a pointer to int, even if you have to typecast to make it so.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by munna View Post
    WHY THE THE int POINTER STORES ONLY int TYPE OF DATA VARIABLES ADDRESS.
    Since you've given what could be interpreted as an answer, should I ask a question?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

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