I have generally thought that the following two prototypes were interchangeable:
int main(int argc, char ** argv);
int main(int argc, char * argv[]);
In general I had imagined that char ** argv
and char * argv[]
were interchangeable. However, I have also come accross some stuff on the internet that claim that you can declare structs like
struct S {
int size;
int ar[];
};
And then simply malloc
appropriately so that ar
can be as large as you want at runtime.
But this seems rather strange to me. If I had instead declared
struct S {
int size;
int * ar;
};
Can I still do the same thing? I would have imagined this depends on what you make ar
point to.
How exactly are int * ar
and int ar[]
different when used inside a struct? What about with char ** argv
and char * argv[]
in function prototypes? Do they have different semantics in C as opposed to in C++?