What is the main difference of the decleration:
char string[30] and char *string;
in the program? I mean, why is it that when I retrieved the value of string using char *string in the decleration it displays a null value?
What is the main difference of the decleration:
char string[30] and char *string;
in the program? I mean, why is it that when I retrieved the value of string using char *string in the decleration it displays a null value?
char array[30];
This allocates a total of 30 'char'acters, including the final one for the null, if you plan on using it with string functions anyway.
char *string;
This one is a pointer to a character. This is commonly referred to as a "string". This allocates no space. (Actually, it's not entirely true. It allocates no "string space", but rather, is a pointer, which takes up a tiny bit of space, but it isn't space you can use as your string.) There is no such thing as a (data type of a) 'string' in C. What you do with a "string", is allocate the amount of space you want, or, if it's already allocated some place, you can use this "char *", a 'character pointer', to point at the location of said string.
I'm tired and don't feel like giving you an entire lesson on pointers right now, but that's the difference between the two.
Quzah.
Hope is the first step on the road to disappointment.