The following example defines two structures, and because of the existence of strings in the member, the struct uses a character array, while struct two uses a character pointer.
#include <stdio.h>
#define LEN 20
struct info {
char first[LEN];
char last[LEN];
int age;
};
struct pinfo {
char * first;
char * last;
int age;
};
int main()
{
struct info one = {"Opw", "Cde", 22};
struct pinfo two = {"Tydu", "Gqa", 33};
printf("%s %s is %d years old.\n", one.first, one.last, one.age);
printf("%s %s is %d years old.\n", two.first, two.last, two.age);
return 0;
}
The code works fine. But for struct pinfo variable two, there are hidden dangers. Because two strings in the two are stored in the literal constant area. And the structure of the store is only two addresses.
printf("one.first's size: %d\n",sizeof(one.first));
printf("two.first's size: %d\n",sizeof(two.first));
Results:
one.first's size: 20
two.first's size: 4