If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > pointers & double pointer question...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 06:42
fredm fredm is offline
Registered User
 
Join Date: Feb 2004
Posts: 1
pointers & double pointer question...

Here's the scoop on the poop,


static int xx[3][4] = { {33,44,55,66},
{45,56,67,78},
{34,45,98,76}
};

main() {
printf("val = %d\n", *(*(xx+1)+2)); //same as xx[1][2]
}

Works fine... val = 67.

However,

main() {
int **pp = (int **)&xx;
printf("val = %d\n", *(*(pp+1)+2)); //same as xx[1][2]
}

Compiles without error but gives a segmentation fault at runtime. Why ?
I realize that the problem has to do with the process stack AND the fact that it is a double pointer but am unable to give a plausible explanation.

I can peel the two dim array into a one dim array using a pointer like this:

main() {
int *p = (int *)&xx;
printf("val = %d\n", *(p+6)); //same as xx[1][2]
}

Works fine when compiled and run: val = 67.



So what's the scoop in using the double pointer.

thanx,
fsm
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On