What is the difference between
char *a[10];
and
char *(a[10]);
I've always used the first for an array of char pointers, but now I've found code used the second.
As I was not sure if it was the same thing, I printed sizeof() both and both return 80 (64bit OS) so I'm inclined to believe both are the same (an array of char pointers).
But as I cannot find any explanation online or anything using *([]) syntax, I was looking for some confirmation.
Thanks
type variableName = value; Where type is one of C types (such as int ), and variableName is the name of the variable (such as x or myName). The equal sign is used to assign a value to the variable.
Declaration of a function provides the compiler with the name of the function, the number and type of arguments it takes, and its return type. For example, consider the following code, int add(int, int); Here, a function named add is declared with 2 arguments of type int and return type int.
A variable name can only have letters (both uppercase and lowercase letters), digits and underscore. The first letter of a variable should be either a letter or an underscore. There is no rule on how long a variable name (identifier) can be.
Declaring (Creating) Variablestype variableName = value; Where type is one of Java's types (such as int or String ), and variableName is the name of the variable (such as x or name). The equal sign is used to assign values to the variable.
The two are equivalent and stand for a 10-element array of pointers to char
.
Contrast with char (*a)[10]
, which is a pointer to a 10-element array of char
.
If in doubt, one could use cdecl
to unscramble C declarations. On Unix it's usually available as a command-line tool. There's also an online version.
char *a[10];
and char *(a[10]);
are the same. To make it clear lets say it this way, char *a[10];
is pointer array
of 10 and later is array of 10 where all are pointers
! You see that both are same with different way of saying that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With