Thread: pointers

  1. #1
    Registered User
    Join Date
    May 2002

    Thumbs up pointers

    hello guys,
    here is my problem, pls go through.
    pls tell me the answer and ***why***

    int *p,*q;
    p=(int *)1000;
    q=(int *)2000;

  2. #2
    If you use p = (int *)1000; you tell the compiler that you want to set p to point to memory address 1000. You should use *p = 1000; and *q = 2000;

    Because the memory addresses are of an integer type, the output given will still be 1000, but the value pointed to by p will not be 1000 and the value pointed to by q will not be 2000.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Some kind of forced pointer difference exercise

    The answer is 500 (if sizeof(int)==2)
    The answer is 250 (if sizeof(int)==4)

    There's a 1000 bytes between p and q, but pointer difference (q-p) returns the number of ints between the two pointers

Popular pages Recent additions subscribe to a feed

Similar Threads

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