Why we have used pointer in this C code? Basically, I am just searching a string in the array, but without pointer, it is unable to run. But why is that?
int main() {
char *x[] = {"ab", "bc", "cd", 0};
char *s = "ab";
int i = 0;
while(x[i]) {
if(strcmp(x[i], s) == 0) {
printf("Gotcha!\n");
break;
}
i++;
}
}
Aucun commentaire:
Enregistrer un commentaire