Question:
What is the difference between a string and an array?
Answer:
An array is an array of anything. A string is a specific kind of an array with a well-known convention to determine its length. There are two kinds of programming languages: those in which a string is just an array of characters, and those in which it’s a special type. In C, a string is just an array of characters (type char), with one wrinkle: a C string always ends with a NUL character. The “value” of an array is the same as the address of (or a pointer to) the first element; so, frequently, a C string and a pointer to char are used to mean the same thing. An array can be any length. If it’s passed to a function, there’s no way the function can tell how long the array is supposed to be, unless some convention is used. The convention for strings is NUL termination; the last character is an ASCII NUL (‘’) character. Source: CoolInterview.com
"character array" is called as "string" where as array is used to store collection of any simliar data type. Source: CoolInterview.com
Answered by: sreelatha | Date:
| Contact sreelatha
string is also made up of consecutive location that is array. Without array we can not store any string. We can't define difference between both string and array. Source: CoolInterview.com
Answered by: shanmugam | Date: 11/23/2007
| Contact shanmugam
Array is a collection of elements of similar data-types. Data-type can be any data-type....While String is a collection of character data-type terminated with a ' Source: CoolInterview.com
Answered by: Pinki Ruparel | Date: 3/4/2010
| Contact Pinki Ruparel
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|