what are two differences between these two statements.
be easy im a new learner
char string[]="This is a string";
char *string = "This is a string";
what are two differences between these two statements.
be easy im a new learner
char string[]="This is a string";
char *string = "This is a string";
Gahhhhhhhhhhhhh. Stop with the posts already just put all of these in one thread.
One is a char array one is a pointer. The array one can be modified and the pointer one cannot.
Woop?
Sounds suspiciously like a homework question into which you have put little effort. But in any case...
Statement one is assigning that value to an array of characters.
Statement two is assigning the address at which that constant is stored in memory to a pointer.
http://www.eskimo.com/~scs/C-faq/q6.2.html
Suggest you read the whole FAQ before asking any further questions, unless you want to continue getting flamed.
but as i remember, in old DOS compiler (turbo C 2.01) *char also can be modified!
>but as i remember, in old DOS compiler (turbo C 2.01) *char also can be modified!
On some compilers it can and others it can't. The standard says it shouldn't be modified if you want portability, so modify your string literals at your own risk.
Cheers!
a short answer:
A string is a "array of characters".
here string[] and *string are nothing but the name given to memory location where your
string is stored.
1) In string[] you use the array notation to manipulate string and
2) In *string you use the pointer notation for manipulating string
actually,
both string[0] and *string are same.
i would suggest you to read some material for "relationship between array and
pointers".
Not exactly. It's already been explained.The above is an array, whose size is the length of the string of characters, plus one for the null character. You can modify its contents, so long as you stay within the provided length.Code:char foo[] = "This is a string. It is also an array.";This is the same as the previous, however its size is 200 characters in length. Its contents also can be modified.Code:char foo[200] = "This is a string. It is also an array."foo is a pointer to a character. It currently points to a string literal. The literal itself is not to be modified. You can however make this pointer point some place else.Code:char *foo = "This is a string of characters. It is not an array.";
Quzah.
Hope is the first step on the road to disappointment.