Diff in string and array

0 digvijay Jadeja · July 30, 2015
I didn't quite get it in the tutorial ways the diff between string and array.

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · July 30, 2015
an array is a container

int arr[] = {1, 2, 3, 4};

represented like so:

[1][2][3][4]

a string is a combination of zero or more characters followed by a null terminator:

this is a string\0

in c, a string is a combination of characters followed by a null terminator.  this set of characters can be placed within an array to represent a string

char str[] = "this is a string";    // null terminator at the end

represented as an array like so:

[t][h][i][s][ ][i][s][ ][a][ ][s][t][r][i][n][g][\0]
0 Superman HC · July 30, 2015
Basically.. a string will treat its elements as character... you cant do much instead of printing them on screen
On the other hand.. an array can be a collection of int, char, string, boolean and the operations can be implemented accordingly..
0 Jon Z. · July 30, 2015
In short a string is an array of char.
  • 1

C

107,034 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator