Strings in C

Strings, Array of characters!

You know what is ‘char’ datatype?
char refers to Character datatype. It stores one character at a time. For example:
char choice;
printf(“Do you want coffee? y or n : “);
scanf(“%c”,&choice);
The problem with char datatype is that you can only store one byte(i.e. one character at a time). So simply, here you need string.
String is nothing but array of character variables.
This is how you can declare a string.
Syntax:
char <stringname>[size];
Example:
char name[20];
I used ‘name’ character variable of size 20. Means it can take 20 characters at a time now.
You will get to know how to use string in taking input and showing output in next post.
Even string have inbuilt function that we will see later.
In string, a value is stored in a sequence in memory location. For example, “Tree” will store in variable a[10] like this:
ValueTree\0
Variablea[0]a[1]a[2]a[3]a[4]a[5]a[6]a[7]a[8]a[9]
Memory Location101478101479101480101481101482101483101484101485101486101487

Related Posts with Strings in C