Hello, I'm a beginner in C language.
const char *s1[3][2]={{"A", "Apple"}, {"B", "Banana"}, {"C", "Cake"}};
printf("%d", s1[0][0]);
return 0;
In a two-dimensional array like this, you want to output a specific value. As you can see in the code above, we tried to output the ASCII value of A located in the two-dimensional array (0,0). But it's not 65 but 108765, 4196288, which is a completely different value... Even the value changes every time.
I've searched everywhere, but I don't know why this situation came out, so I'd like to ask... I'd appreciate it if you could help me a little bit
(+ When I created an array with chars1, it said overflow, so I put const in front of chars1 as an error solution that I searched on Google.)
c array
This is because s1[i][j]
is (char*)
, character pointer.
© 2024 OneMinuteCode. All rights reserved.