C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old May 26th, 2003, 08:32 PM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
Quote:
Originally posted by 7stud
lol. Not really. I understand what the notation represents(see the previous couple of posts and the original thread), I was wondering about what happens internally in memory. However, the second part of the post was very helpful--thanks.
Ok, let me try again. I am guessing at what exactly you are referring to when you say "what happens internally in memory" - I assume you mean during pointer operations, since the pointer itself is just a 32-bit address no matter what it points to (on a win32 system, anyway). If you mean something else by this, let me know. Also, I apologize if I state the obvious below, but the best way to explain this is to get down to the basics.

Quote:
Originally posted by 7stud
If you want a pointer to a basic type to jump to the next row, it won't work. A pointer declared like this:

int* pint;

won't do what you want.
Basically, the compiler remembers what type the pointer is pointing to, so it knows its size. In fact, the size is all that matters. If you have a byte, pbyte++ will increment it by 1. If it points to a long, then plong++ increments it (the 32-bit address) by 4.

Quote:
Originally posted by 7stud
Also, I'm not sure about the internals of this:

int (*pArr2d)[3] = Arr2d;

and how it works. The one thing I noticed is that you can say:

pArr2d[0]

which doesn't make sense to me, since pArr2d is not supposed to be an array of pointers like when declaring it this way:

int* pArr2d[3];
int (*pArr2d)[3] = Arr2d;

is a declaration and initialization at the same time. So let's break it down to make it simplier:

int (*pArr2d)[3]; // this makes pArr2d a pointer to type X (X = arrray of 3 ints)
pArr2d = Arr2d; // set the address of pArr2d to the address of Arr2d, duh.

pArr2d[0] is using a pointer in array-style accessing. Take a look at this first:

int *pint;
int array[10] = {0,1,2,3,4,5,6,7,8,9};
pint = array; // pint = &array[0];
pint[5] accesses the 6th value in array[]. To the compiler, it is exactly the same as array[5], or *(pint+5), or *(array+5). They are all the same, since pointers and arrays are the same.
This is why pint = array works, and you don't need to use pint = &array[0] syntax.

Okay, going back to:

pArr2d[0]

It is accessing the 1st element of Arr2d, which is the first X in the array. What is the first X? X is an array of 3 ints, so the first X is the first array of 3 ints - otherwise, the first 'row' of the 2D array.

I hope that explanation helps...

Reply With Quote
  #17  
Old May 26th, 2003, 11:59 PM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,365 7stud User rank is Private First Class (20 - 50 Reputation Level)7stud User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 20 m 28 sec
Reputation Power: 14
Sorry, I didn't mean I didn't understand. I got it the first time. Thanks.

Reply With Quote
  #18  
Old May 27th, 2003, 05:43 AM
Jason Doucette's Avatar
Jason Doucette Jason Doucette is offline
jasondoucette.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Canada
Posts: 378 Jason Doucette User rank is Private First Class (20 - 50 Reputation Level)Jason Doucette User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 23 m 8 sec
Reputation Power: 11
Oh, ok, no problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > array containing arrays pointer incrementing?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap