I'm trying to make a dictionary using C language, but the value of the ASCII code is wrong

Asked 2 years ago, Updated 2 years ago, 41 views

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

2022-09-20 21:48

1 Answers

This is because s1[i][j] is (char*), character pointer.


2022-09-20 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.