Pointer Question..

This is a discussion on Pointer Question.. within the C Programming forums, part of the General Programming Boards category; Here is my code Code: int main() { int m, *k; m = 10; k = &m; printf("Address of m ...

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    Da World
    Posts
    6

    Pointer Question..

    Here is my code
    Code:
    int main()
    {
          int m, *k;
          m = 10;
          k = &m;
          printf("Address of m is : %d %d %d",&m, k, &(*k));
          
          return 0;
    }
    Suppose the address of m = 300.
    So the output of this program should be
    Code:
    300 300 300
    I get the correct output when i try compiling this program in gcc.
    But in Turbo C i get a different output. Something like
    Code:
    300 300 400
    My question is when the compiler compiles this program does it substitute the expression &(*k) with &(m) or with &(10) ??
    Last edited by Dave_Sinkula; 10-11-2006 at 05:51 PM. Reason: Fixed [code][/code] tags.

  2. #2
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Try ...

    Code:
    printf("Address of m is : %p %p %p",&m, k, &(*k));

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 09:54 AM
  3. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 10:59 AM
  4. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 01:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

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