What is the difference between String and Array?

What is the difference between String and Array?

Main difference between String and Arrays are:

 A string is a specific kind of an array with a well-known  convention to determine its length where as An array is an array of anything.

In C, a string is just an array of characters (type char)and always ends with a NULL 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 NULL termination; the last character is an ASCII NULL character.
 

By:Vivek Kr. Agarwal
Date:2029-12-08 00:00:00

Array can hold group of element of the same the type, and which allocates the memeory for each element in the array,if we want we can obtain the particular value from an array by giving index value.

Ex: int a[10];

a variable holds the values of integer at max 10.

String can hold any type of data, but it makes together we can't obtain the particular value of the string.

String s="Pra12";

By:praveen
Date:0000-00-00 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher