Hi guys! Programming question:

In C, is an array _exactly_ the same thing as a pointer to the first element of the array? How does the program know the size of the array? Where is this information stored?

I just found out the difference between the length of a string and the size of the buffer reserved for that string. But if `char s[]` and `char *s` are the same thing, who controls the size of that?

(boost appreciated)

Follow

@camelo003

No, C actually has the concept of a traditional array hidden in it. Consider:

float a[3][4], *b = a;

(Your compiler won't like that assignment to b!)

and try saying a[1][2] versus b[1][2], and so forth.

Also take a look at sizeof(a)

C understands types, including multi-dimensional arrays. It has for a long, long time.

Arrays and pointers intersect in C, but are not identical.

Sign in to participate in the conversation
Mastodon for Families and Friends

This is a family server