C Programming & KUK B.Tech Notes

What is String

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:

Premium E-Books & Study Materials.

Access university-specific notes and programming guides. Download instantly to start studying.

Share Article :

TopperWorld
Prime E-Books

Master programming and core CS concepts with expert-curated study guides.

Recent Tutorials :

Java Most Asked Interview Question and Answer
Top 10 AI companies in India
How Generative AI is Transforming Programming
Top GITHUB Interview Questions and Answers
DSA Most Asked Interview Questions