I am trying to create a char pointer array,or another way to put it a string array; using this syntax:
#include <stdio.h>
int main() {
char **a = {"ab", "ac"};
printf("%c", *((*a)+sizeof(char)));
}
To my understanding, a
is a pointer that points to a char*
. When I dereference it, I must access to the char*
which in this context is the pointer that points to the first char
of the string literal "ab"
. Adding one byte to the pointer must yield the pointer, address that points to the second char
to the string literal, and when dereferenced, it must yield the char
: 'b'
? So why does this chunk of code generate such error? Is it because the compiler doesn't allocate adequate amount of memory because I am m erely declaring a pointer instead of an array? The prior questions are just speculations and are optional for one to answer. Thanks in advance.