Thread: pointer dereference

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    196

    Thumbs up pointer dereference

    Code:
    int x[] = {1,2,3,4,5}; int *ptr, **ptr2; ptr = x; ptr2 = &ptr;
    referring to the above code sample, how do you update x[2] to 10 using "ptr2"?

    Is it **(*ptr2+2) = 10 or **(ptr2+2) = 10 or *(*ptr2+2) = 10 or *(&ptr2+2) = 10.

    As per my understanding,its *(*ptr2+2) = 10
    Just want to confirm it.
    Last edited by leo2008; 04-12-2021 at 11:46 AM.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    813
    >> As per my understanding,its *(*ptr2+2) = 10
    >> Just want to confirm it.

    Why not code it yourself and test it? I did! ;^)

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    196
    It shows *(*ptr2+2) = 10

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dereference a pointer in a function
    By royalts in forum C Programming
    Replies: 8
    Last Post: 02-26-2015, 02:57 AM
  2. null pointer dereference
    By qwertylurker in forum C Programming
    Replies: 3
    Last Post: 03-14-2011, 12:06 AM
  3. Suspicious dereference of pointer
    By subhashish1213 in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2009, 08:19 AM
  4. Pointer dereference
    By taurus in forum C Programming
    Replies: 1
    Last Post: 11-09-2008, 07:41 AM
  5. Dereference pointer to void pointer to member
    By phil in forum C Programming
    Replies: 5
    Last Post: 04-20-2005, 11:54 AM

Tags for this Thread