String in C Language C भाषा में स्ट्रिंग

What is a String in C?

In C programming, a string is a sequence of characters terminated by a special character called the Null Character ('\0'). A string is represented within double quotation marks (" "). In C language, strings are stored in a one-dimensional character array. The size of the character array must be at least one character greater than the actual length of the string because one extra memory location is required to store the null character ('\0').

C भाषा में स्ट्रिंग क्या है?

C प्रोग्रामिंग में स्ट्रिंग (String) कैरेक्टर्स का एक समूह होती है, जो एक विशेष कैरेक्टर नल कैरेक्टर ('\0') द्वारा समाप्त होती है। स्ट्रिंग को डबल कोटेशन मार्क (" ") के अंदर लिखा जाता है। C भाषा में स्ट्रिंग को One-Dimensional Character Array में स्टोर किया जाता है। कैरेक्टर ऐरे का आकार स्ट्रिंग की वास्तविक लंबाई से कम से कम एक अधिक होना चाहिए, क्योंकि अतिरिक्त मेमोरी लोकेशन में Null Character ('\0') स्टोर किया जाता है।

Example of String

char name[6] = "India";

In the above declaration:

  • char is the data type.

  • name is the name of the character array.

  • 6 represents the size of the array.

  • "India" is the string assigned to the array.

  • '\0' is automatically stored at the end of the string.

उपरोक्त उदाहरण में:

  • char एक Data Type है।

  • name Character Array का नाम है।

  • 6 Array का Size दर्शाता है।

  • "India" Array में स्टोर की गई String है।

  • '\0' स्ट्रिंग के अंत में स्वतः स्टोर होता है।

Memory Representation of a String

A string is stored in consecutive memory locations of a character array. Each character occupies one array element, and the last element contains the null character ('\0').

For example:

char name[6] = "India";

Memory representation:

Array Index012345
CharacterIndia\0

The actual length of the string is 5, but the array size is 6 because one additional location is required for the null character.

स्ट्रिंग का मेमोरी में निरूपण:

स्ट्रिंग के प्रत्येक कैरेक्टर को Character Array की लगातार Memory Locations में स्टोर किया जाता है। अंतिम स्थान पर Null Character ('\0') स्टोर होता है।

उदाहरण में "India" की वास्तविक लंबाई 5 है, लेकिन Array का Size 6 है क्योंकि Null Character के लिए एक अतिरिक्त स्थान की आवश्यकता होती है।

Declaration of String in C

A string can be declared using a character array in C language.

Syntax:

char string_name[size];

Example:

char name[20];
char city[15];
char course[30];

Here, name, city and course are character arrays that can store strings.

स्ट्रिंग डिक्लेरेशन:

C भाषा में स्ट्रिंग को Character Array की सहायता से Declare किया जाता है।

उदाहरण:

char name[20];
char city[15];
char course[30];

यहाँ name, city एवं course Character Arrays हैं जिनमें स्ट्रिंग स्टोर की जा सकती है।

Initialization of String in C

A string can be initialized at the time of declaration in different ways.

Method 1: Using String Literal

char name[6] = "India";

Method 2: Without Specifying Array Size

char name[] = "India";

In this case, the compiler automatically determines the array size, including the null character.

Method 3: Using Individual Characters

char name[6] = {'I', 'n', 'd', 'i', 'a', '\0'};

स्ट्रिंग का इनिशियलाइजेशन:

C भाषा में स्ट्रिंग को Declare करते समय विभिन्न तरीकों से Initialize किया जा सकता है।

  1. String Literal की सहायता से।

  2. Array Size दिए बिना, जिसमें Compiler स्वयं Size निर्धारित करता है।

  3. प्रत्येक Character को अलग-अलग लिखकर तथा अंत में Null Character ('\0') देकर।

Important Characteristics of String in C

  1. A string is a collection of characters.

  2. Strings are stored in character arrays.

  3. A string is enclosed within double quotation marks.

  4. Every valid C string ends with a null character ('\0').

  5. The null character is not included in the actual string length.

  6. The size of the character array must be sufficient to store all characters and the null character.

  7. C does not provide a separate built-in string data type.

C भाषा में स्ट्रिंग की विशेषताएँ:

  1. स्ट्रिंग कैरेक्टर्स का समूह होती है।

  2. स्ट्रिंग को Character Array में स्टोर किया जाता है।

  3. स्ट्रिंग को Double Quotation Marks के अंदर लिखा जाता है।

  4. प्रत्येक सही C String का अंत Null Character ('\0') से होता है।

  5. Null Character को स्ट्रिंग की वास्तविक लंबाई में शामिल नहीं किया जाता है।

  6. Character Array का Size सभी कैरेक्टर्स एवं Null Character को स्टोर करने के लिए पर्याप्त होना चाहिए।

  7. C भाषा में String के लिए कोई अलग Built-in Data Type उपलब्ध नहीं है।

String Header File in C

C language provides a standard header file called string.h, which contains several useful string handling functions.

To use standard string handling functions, we include this header file in our program.

#include <string.h>

Some commonly used string functions are:

  • strlen() – Finds the length of a string.

  • strcpy() – Copies one string into another.

  • strcmp() – Compares two strings.

  • strcat() – Joins two strings.

These string functions will be explained separately with syntax, C programs and output in our next tutorial.

स्ट्रिंग हेडर फाइल:

C भाषा में string.h नाम की एक Standard Header File उपलब्ध है, जिसमें स्ट्रिंग से संबंधित अनेक उपयोगी Functions दिए गए हैं।

इन Functions का उपयोग करने के लिए प्रोग्राम में निम्न Header File शामिल की जाती है।

#include <string.h>

कुछ प्रमुख String Functions हैं:

  • strlen() – स्ट्रिंग की लंबाई ज्ञात करना।

  • strcpy() – एक स्ट्रिंग को दूसरी स्ट्रिंग में कॉपी करना।

  • strcmp() – दो स्ट्रिंग्स की तुलना करना।

  • strcat() – दो स्ट्रिंग्स को जोड़ना।

इन सभी String Functions को अगले Tutorial में Syntax, C Program एवं Output के साथ विस्तार से समझाया जाएगा.

  • A string is stored in a character array. (स्ट्रिंग को Character Array में स्टोर किया जाता है।)

  • The null character ('\0') indicates the end of a string. (Null Character ('\0') स्ट्रिंग के अंत को दर्शाता है।)

  • The size of the array includes space for the null character. (Array के Size में Null Character का स्थान भी शामिल होता है।)

  • string.h is the standard header file for string handling functions. (string.h स्ट्रिंग से संबंधित Standard Functions की Header File है।)

Comments

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025