Site icon i2tutorials

STRINGS

STRINGS

 

Introduction to Strings

 

 

Declaration of string

 

Syntax:

 

char varname[size];

 

Example:

 

char A[10];

 

A is a character array of size 10.

 

Initialization of string

 

(i) Assigning a string to a character array.

(ii) Assigning character by character to a character array.

 

Case 1:

 

char s[10]=”Hello world”;

 

The compiler automatically inserts the Null character at the end.

 

Case 2:

 

char s[10]= {'H','e','l','l','o',','w','o','r','l','d','\0'};

 

If data is given character by character ‘\0’ is added manually.

 

 

 

 

 

 

 

 

 

Exit mobile version