Thread: Pointing to the next character in an array?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Registered User
    Join Date
    May 2011
    Posts
    16
    Yes, I made a mistake, I thought the %p took care of that for me (I thought I was supposed to pass the pointer's address to it for some reason, which makes no sense in retrospect).
    I edited my above post, thanks.

    Edit: any recommendations or advice?
    Code:
    #include <stdio.h>
    int main ()
    {
    	int myArray[] = {5, 6, 7, 8};
    	int * myPointer = &myArray[0];
    
    	printf("Print address of beginning of array of 4-byte integers:\n");
    
    	// print address of myArray[0]
    	printf("&myArray[0]:\t0x%08lx\n", (unsigned long)myPointer);
    	printf("&myArray[0]:\t%p\n", (void*)&myArray[0]);
    	printf("&myArray[0]:\t%p\n", (void*)myPointer);
    
    	// print address of next element of the array
    	printf("&myArray[1]:\t0x%08lx\n", (unsigned long)(myPointer+1));
    	printf("&myArray[1]:\t%p\n", ((void*)&myArray[0])+sizeof(int));
    	printf("&myArray[1]:\t%p\n", ((void*)myPointer)+sizeof(int));
    	return 0;
    }
    Last edited by steez; 06-01-2011 at 08:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array and pointing randomly
    By gloworm in forum C Programming
    Replies: 4
    Last Post: 04-12-2010, 12:03 PM
  2. pointing to an array
    By gloworm in forum C Programming
    Replies: 4
    Last Post: 04-11-2010, 11:46 AM
  3. Replies: 6
    Last Post: 11-03-2009, 01:23 PM
  4. passing/pointing to a 2d array
    By jamie85 in forum C Programming
    Replies: 7
    Last Post: 10-28-2005, 10:16 PM
  5. array of pointers each pointing to an array
    By muttski in forum C Programming
    Replies: 6
    Last Post: 05-01-2002, 02:03 PM