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.  

Showing Answers 1 - 5 of 5 Answers

M.Sunil Kumar

  • 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(" ");

  Was this answer useful?  Yes

Abhai

  • May 26th, 2007
 

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

  Was this answer useful?  Yes

Vipul Thakrar

  • 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.

  Was this answer useful?  Yes

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('')

  Was this answer useful?  Yes

RANJIT KUNDU

  • Sep 25th, 2017
 

Array is a group of similar data types or strings where string is a single line collection of same data types. Whatever see the examples and explanation, array can be multi dimensional means it can access a group of strings when it is one dimensional you can call it string but when it comes two or more dimensions each single dimensions you can call a single string the whole thing is a array.

Code
  1. a[10]//is a string or array.

  2. a[10][10]//is a 2 dimensional array

  Was this answer useful?  Yes

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions