Original Post
if i define it as int table[32]; (there is a question, look at the title)
Quote:
Original post by password
Aren't they exactly the same thing? table is also the adress to the first element..
Quote:
Original post by Brother Bob Quote:
Original post by password
Aren't they exactly the same thing? table is also the adress to the first element..
If you had bothered reading the other posts, you would know that isn't the case. table is an array of 32 integers in the example given, but can be used to get the address to the first element. This, however, doesn't mean table IS the address to the first element, because it isn't.
Quote:
Original post by password
I was merely pointing out that they had the same adress and that's a fact, the other was a question and the answer is that they are different types.
Quote:
Original post by password
I was talking about what I have read in a book myself, also I DID read the other posts so don't atleast tell me, what I did when you don't even know. I was merely pointing out that they had the same adress and that's a fact, the other was a question and the answer is that they are different types.
If you're going to correct me, and in an irascible way at that, do it right atleast..
Quote:
Original post by rip-off
Also, the address value obtained from table == &table[0] meaning that they point to "the same address", yet are different types (int * and int (*)[32] ).
Quote:
Original post by TheFez6255
Yes and no, they both point to the same spot but are different types. The OP defined table as int table[32] so table's type is int * [32] while &table[0]'s type is int *. So basically using one instead of the other would cause the compiler to complain.
Quote:
Original post by Fruny Quote:
Original post by password
I was merely pointing out that they had the same adress and that's a fact, the other was a question and the answer is that they are different types.
The problem is that table itself doesn't have an address (try doing &table). It is not a variable: table[0], table[1]... are. However, table has a value, which is indeed the address of table[0].
Quote:
Original post by Brother Bob
As Fruny mentioned, the array name doesn't have an address, but it can be used to get one.
Quote:
Original post by Polymorphic OOP Quote:
Original post by Brother Bob
As Fruny mentioned, the array name doesn't have an address, but it can be used to get one.
No, arrays have an address just like other types -- that's how you are able to make references and pointers to arrays.
Quote:
Edit: Holy moly lots of misinformation in this thread :|
Quote:
Original post by Zahlman
You are in agreement. The array has an address. The array NAME does not.
Quote:
Original post by Fruny
The problem is that table itself doesn't have an address (try doing &table). It is not a variable: table[0], table[1]... are. However, table has a value, which is indeed the address of table[0].
Quote:
Original post by Zahlman
It *is* an address, but there is no chunk of memory (at least not one accessible to the programmer, unless he creates another one by making a pointer to the array beginning) storing the value corresponding to that address. It exists only in the mind of the compiler.
void float_function( float& );void double_function( double );void array_function( int (&)[32] );void ptr_function( int* );int main(){ float float_var; float_function( float_var ); // float_var is passed by reference double_function( float_var ); // float_var is converted to double double double_var; float_var == double_var; // float_var is converted to double int array[32]; array_function( array ); // array is passed by reference ptr_function( array ); // array is converted to a pointer to the first element int* ptr; array == ptr; // array is converted to a pointer to the first element}Quote:
Original post by Polymorphic OOP
Table in fact does have an address and &table is well defined.
This topic has been locked by a moderator. New replies are not allowed.
GameDev.net uses cookies to ensure you have the best experience on our platform. Learn more