None of them are declaring strings , they are declaring variables that can support strings .
The last one seems strange to me, but it works, if used right, is generally not used unless it has a specific reason. The others are all correct.
This declares that the variable str*
will be a pointer to characters. Where are these characters is problem of another part of the code say, what you need is that then put the string address in this variable.
char *str;
The following is not allowed because you can not determine the size of array .
char str[];
It's already changing a bit because it already saves space for 100 characters (99 useful) and the string will be next to the variable already allocated in the stack . The content will be placed next.
char str[100];
In fact the most common is to do so in the stack or static area:
#include <stdio.h>
int main(void) {
char str[] = "teste";
char *strx = "teste";
printf("%s", str);
printf("%s", strx);
}
See running on ideone . And in Coding Ground . Also put it in GitHub for future reference .
See more in Char pointer or char array .
Understand the difference between array and pointer .
And still read: