Is it valid to say in c/c++ that the name of an array is a pointer?
I already know that this is valid
From this can i assume that the name of an array is a pointer?Code:int c[10]; &c[0]==c;
Is it valid to say in c/c++ that the name of an array is a pointer?
I already know that this is valid
From this can i assume that the name of an array is a pointer?Code:int c[10]; &c[0]==c;
-You can't just turn on creativity like a faucet. You have to be in the right mood.
-What mood is that?
-Last-minute panic.
in some context it behaves like one, but not always
check the difference between sizeof(c) and sizeof(&c[0])
if your question is answered, mark the thread as [SOLVED]. Thx.
To post code or command output, use [code] tags.
Check your bash script here // BashFAQ // BashPitfalls
arrays and pointers are different types. But both types represent a very similar concept, except arrays have the additional notion of the size of memory pointed to.
It is very important to remember that arrays decays into a pointer on a change of stack frame.
That means as soon as you are in a different frame the size information is lost
e.g.
Code:main() { int c[10] assert(sizeof(c == sizeof(int) * 10)); f(c); } f(int a[]) { assert(sizeof(a == sizeof(int*))); // a is now a pointer to the array in the previous stack frame!! // [] syntax here is just "syntactic sugar", int * a is the exact same thing }
Last edited by MadCow108; November 18th, 2012 at 01:25 AM.
Bookmarks