GeekInterview.com
Series: Subject: Topic:
Question: 746 of 827

What is the difference between a string and an array?

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.  
Asked by: Interview Candidate | Asked on: Mar 6th, 2005
Showing Answers 1 - 4 of 4 Answers
M.Sunil Kumar

Answered On : Dec 5th, 2006

array  it is the collection of similer data types ex:int a[10]ten indicates the size of array. [ ] is index of array, we can give only integer values to array of a.where as string mean colection of group of charaters in double Quotes(" ");

  
Login to rate this answer.
Abhai

Answered On : May 26th, 2007

An array is collection of simillar(any data type like char, int, float ..etc) , string is an array is characters.

  
Login to rate this answer.
Vipul Thakrar

Answered On : Jul 30th, 2011

Array is collection that can hold multiple values at a time where as String can hold only single value at a time.

  
Login to rate this answer.
Sooraj Kumar

Answered On : Aug 3rd, 2011

View all answers by Sooraj Kumar

An Array is collection of elements of similar type which are referred by a common name.Each element is accessed by its value. First element has index 0 and last element has index which is 1 less than the size of array. Declaration of Array:- data_type array_name[size]; String is collection of characters. So it is called character array. Each string is terminated by null character('')

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.