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
An ARRAY is a collection of similar data types.For eg. int a[5]; An integer type array of size 5 is created in memory. A STRING is an array of characters. xFor eg.. char a[5]; a string is usually enclosed in double quotes. Source: CoolInterview.com
Answered by: Ankita Leekha | Date: 7/25/2009
| Contact Ankita Leekha
an array is a collection of similar elements which is maintaining under one variable name. eg. int a[10]; here the memory is allocating for ten integer variables. where as in string it is a group of characters maintaining under one variabe name.. eg. char b[10]; here memery allocating for ten character values..hence we can define the string is also a one type of aray. Source: CoolInterview.com
Answered by: satya | Date: 5/13/2010
| Contact satya
Respected sir/mam, I want ask u 1 Question & the Q is "Write a programme that reads & writes 5 character strings,each of length 10." Please send this pgm's code . Source: CoolInterview.com
Answered by: archana a. lohiya | Date: 9/4/2010
| Contact archana a. lohiya
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.
|