Skip to content

c pointer array #118829

Apr 12, 2024 · 4 comments · 2 replies
Discussion options

You must be logged in to vote

Hello, @zidudu!

The code you provided doesn't compile because you use your ptrArray incorrectly.
Instead of using char *ptrArray[4] = { {"Korea"},{"Seoul"},{"Mapo"},{"Gimpo"} };
You should put elements inside without curly braces, like: char *ptrArray[4] = {"Korea", "Seoul", "Mapo", "Gimpo"};

Here's your full code corected

#include <stdio.h>
int main() {
    int i;
    char *ptrArray[4] = {"Korea", "Seoul", "Mapo", "Gimpo"};
    for (i = 0; i < 4; i++) {
        printf("\n %s", ptrArray[i]);
    }
    ptrArray[2] = "Jongno";
    printf("\n\n");
    for (i = 0; i < 4; i++) {
        printf("\n %s", ptrArray[i]);
    }
    getchar();
}

Have a great day!

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ebndev
Comment options

@MindOfBear
Comment options

Answer selected by LiteBrite82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Programming Help Programming languages, open source, and software development.
6 participants