Assigning multiple strings into double pointer

This code works fine,of course.
1
2
3
4
5
6
#include<stdio.h>
int main(void)
{
    char* a[]={"You","Hello World","George"};
    return 0;
}

But I can't compile this code
1
2
3
4
5
6
#include<stdio.h>
int main(void)
{
    char** a={"You","Hello World","George"};
    return 0;
}

gcc says:

1.c: In function ‘main’:
1.c:4:5: warning: initialization from incompatible pointer type
char** a={"You","Hello World","George"};
^
1.c:4:5: warning: (near initialization for ‘a’)
1.c:4:5: warning: excess elements in scalar initializer
1.c:4:5: warning: (near initialization for ‘a’)
1.c:4:5: warning: excess elements in scalar initializer
1.c:4:5: warning: (near initialization for ‘a’)


I thought ** and *[] are exactly the same, but it seems not.
What is the difference between these two? Why double pointer isn't working?
Last edited on
char a[] = "test";. Memory is created for test because of the [] and the address of t assigned to a.
char *a = "test"; Wrong: A is supposed to get an address.
Topic archived. No new replies allowed.