What is String

WhatsApp Group Join Now
Telegram Group Join Now

In C programming, a string is a sequence of characters terminated with a null character \0.

For examples:

char str[] = "Topperworld\0";                                                                                                                                              

When the compiler encounters a sequence of characters enclosed in the double quotation marks, it appends a null character \0 at the end by default.

Declaring a String in C :


A String in C is an array with character as a data type. C does not directly support string as a data type, as seen in other programming languages like C++. Hence, character arrays must be used to display a string in C. The general syntax of declaring a string in C is as follows:

Syntax:

char variable[array_size];

Examples:

char str[5];
char str2[50];

Initializing a String in C:

Leave a Comment

Your email address will not be published. Required fields are marked *