STRINGS
String is an Array of Characters terminated by a NULL character '/0'.
Example:
char a[10] = “Hello”;
STRING VARIABLE
There is no separate data type for handling strings in C. They are treated as just an arrays of characters. So, a variable which is used to store an array of characters is called a string variable.
Declaration of String
Strings are declared in C in similar manner as arrays. Only difference is that, strings are of char type.
Example:
char s[5]; //string s can hold maximum of 5 characters including NULL character.
Initialization of String
Example:
char s[4]={'V', 'T', 'U' };
Example: Program to illustrate the initialization of string.
#include<stdio.h>
void main()
{
char s[4]={'V','T','U'}; //or char s[4]="VTU";
printf("Value in array s[0] : %c \n", s[0]);
printf("Value in array s[1] : %c \n", s[1]);
printf("Value in array s[2] : %c \n", s[2]);
}
String is an Array of Characters terminated by a NULL character '/0'.
Example:
char a[10] = “Hello”;
STRING VARIABLE
There is no separate data type for handling strings in C. They are treated as just an arrays of characters. So, a variable which is used to store an array of characters is called a string variable.
Declaration of String
Strings are declared in C in similar manner as arrays. Only difference is that, strings are of char type.
Example:
char s[5]; //string s can hold maximum of 5 characters including NULL character.
Initialization of String
Example:
char s[4]={'V', 'T', 'U' };
Example: Program to illustrate the initialization of string.
#include<stdio.h>
void main()
{
char s[4]={'V','T','U'}; //or char s[4]="VTU";
printf("Value in array s[0] : %c \n", s[0]);
printf("Value in array s[1] : %c \n", s[1]);
printf("Value in array s[2] : %c \n", s[2]);
}
Sign up here with your email
ConversionConversion EmoticonEmoticon