Thread: (int*) question

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    1

    Question (int*) question

    abc = (int *)&abc + 2;


    does the (int*) turn the address of abc+2 into a pointer, if not, can someone explain it.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    >does the (int*) turn the address of abc+2 into a pointer

    No. The address of abc, &abc, is resolved into a pointer (of whatever type abc is). The cast, (int*), converts that resulting pointer to a pointer to an int. The addition of 2 results in a pointer that is 2 * sizeof(int) bytes from &abc. This is the value that is then assigned to abc, which one might presume to be a pointer to int.

    Or, abc is assigned a value which is a pointer to a location 2 integers beyond the location of abc itself.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM