Please note that I am doing this strange assignment not because I am unclear of the syntax or am new to c.
I was just trying out what would happen if an int was assigned an array:
int a = {1, 2, 3};
To this I got the following warning:
warning: excess elements in scalar initializer
int a = {1, 2, 3};
^
warning: excess elements in scalar initializer
int a = {1, 2, 3};
^
and when I print the contents of a, I get 1
.
But when I do this:
int a;
a = {1, 2, 3};
I get an error:
error: expected expression before ‘{’ token
a = {1, 2, 3};
^
Though I know arrays are not meant to be assigned to int
variables, the above results lead me to question:
- the difference between
int x; x = ...
andint x = ...
and
- what exactly causes the warning or the error message?