Check out the below code
char *str;
gets(str); // or fgets
puts(str);
its an example program in c++. Actually I feel its not a good way of coding because we did not assign a memory location to the char pointer str. The book says char array[10] has a limitation of length whereas char pointer str does not have a fixed length, we can input as many chars as possible. But I believe pointers can never be used without assigning a memory address to it, as I have learnt in C.
I think this must be the right way of doing it,
char a[100];
char *str=a;
fgets(a,100,stdin);
puts(a);
Kindly make me sure. Is it a good way of coding pointers without assigning a variables memory address to it? or what are the best ways to do it. Let me know what happens if we use pointers without assigning a memory address.Thanks.