0

pls explain how this assignment operator works...is it a 2d array or 1d array?

char a[]={"0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "!@#$%^&*?_:"};

10th Feb 2019, 7:10 AM
[ ]
[     ] - avatar
6 Answers
+ 4
You are declaring a 1d array and assigning a 2d array to it (strings are arrays of chars). It works because there isn't any difference in the implementation of multidimensional arrays, the data is still put contiguously. In the end, it's a 1d array. Actually, the second array may not even be a 2d array in the first place, since there are no commas.
10th Feb 2019, 8:35 AM
Zen
Zen - avatar
+ 4
If you write string literals next to each other they will just be concatenated by the compiler. So it's just a single big string.
10th Feb 2019, 10:30 AM
Schindlabua
Schindlabua - avatar
+ 2
No, you will get the character '1' instead (I've tested).
10th Feb 2019, 9:16 AM
Zen
Zen - avatar
+ 2
10th Feb 2019, 2:10 PM
[ ]
[     ] - avatar
0
Zen what if i write a[1] wil it access ABCDEF.....?
10th Feb 2019, 8:57 AM
[ ]
[     ] - avatar