You are on page 1of 5

Stringin

C Programming

By Ariful Asfake Sunny


Web Developer and Product Designer
C
String

❏ Strings are used for storing text/characters. In C programming string is nothing


but a collection of characters in a linear sequence.
❏ Strings are actually array in this language. So we can access a string by
referring to its index number inside square bracket [].
C
String
METHOD OF STRING

Method 1 :
char address[] = {'D', 'H', 'A', 'K', ‘A’, ‘\0’};

The above string also can be defined as:


Method 2 :
char address[] = "DHAKA";
C
String
METHOD OF STRING

Method 1 :
char address[] = {'D', 'H', 'A', 'K', ‘A’, ‘\0’};

What is NULL Character ‘\0’?


● “\0” represents the end of the string.
● It is also referred as String terminator & Null Character.
● The C compiler automatically adds a NULL character ‘\0’ to the character
array created.
C
String
STRING SYNTAX

★ General syntax for declaring a variable as a String:


char string_variable_name [ arraySize ];

★ Classic syntax for declaring a variable as a String:


char string_name [ string_length] = “string”;

*The size of an array must be defined while declaring a C string variable. Because it is used to
calculate how many characters are going to be stored inside that string.

You might also like