Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
An array is just a pointer
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Stuart Golodetz, post: 4195211"] a) Try both 'int *x' and 'int (*x)[10]' at [URL]http://www.cdecl.org/[/URL] b) Consider the difference between types and values. A variable of type 'int *' is a pointer to an int, regardless of the value it contains, but it may point at either an individual int, or an element of an array of ints, or indeed somewhere completely invalid. To say that a variable of type 'int *' that contains the address of the first element of an array of ints 'points at the array' is to some extent an understandable colloquialism, but it's imprecise. The pointer points at the first int in the array, because by type it is a pointer to an (one, singular) int. The key point is that whatever *value* I store in the pointer at runtime, I can't change its *type* (types are compile-time entities). In the following, both x and y have the same type: int *x = new int; int *y = new int[23]; They are both pointers to a single int. At runtime, x contains the address of an individual int, and y contains the address of an int that happens to be the first element of an int array. If you want to colloquially describe that situation by saying 'y points to the array', then that's up to you (most people would probably understand what you meant), but formally speaking it's not the case. Regards, Stu [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
An array is just a pointer
Top