I am learning C and I understand perfectly the pointers and their relation with the arrays, but my problem comes with the character strings. We declare a string of characters like this:
char cadena[] = "Hola";
is equivalent to:
char cadena[] = {'H','o','l','a','char *getCadena (){
static char cadena[] = "Hola"; //static para que su dirección en la memoria sea global
return cadena;
}
'}
and therefore if you want a function to return a string of characters you have to make it static so that the memory address is valid outside the scope of the function:
char *cadena = "Hola";
What I do not understand is that the compiler does when you declare the string of characters like this:
char *getCadena (){
char *cadena= "Hola";
return cadena;
}
declare the array static? I ask it because in testing it I have seen that even declaring a string of characters in that way within a function can be returned without problems, so the address has to be global in some way:
char cadena[] = "Hola";
Thanks in advance and greetings