C tutorial - Strings in c programming language

Programming languages or concepts

 Strings in c programming language:-

      Strings:-

         String is a nothing but a collection of characters in a linear sequence. To represent ap string, a a set of characters are enclosed within double quotes (" "). The c string like "inprout.tech" old look like as follows in memory.

   Strings are defined as array of characters.

Example of string in C:
                        char str []="inprout.tech";

    index - 0   1   2   3   4    5     6    7    8    9    10   11
  Str-          i   n   p   r   o    u     t     .     t    e      c     h
   
       

Declaration & Initialisation of strings:- 

Syntax: 
                char variable_name[size];

Ex.
          char ch[20];

it is also possible to declare C string as a pointer to a char.

      char* ch1= "inprout.tech";

A stream is usually declared as an array of characters.

        Ex.       char ch[30];

initalizing of string :-


      char String_name[ String_length] = " String";

       Initalizing a string A string can be initiated in different array we will explain this with the help of an example below is an example or declare a string with name as str and initialize it with"inprout.tech".

Examples:
         char ch1[30] ={'i','n','p','r','o','u','t'};
             //Array Initialisation
       
         char ch2[20] ={"inprout.tech"};     //shortcut array Initialisation.

          char ch3[30] ="  ";     //Empty & null c string of,0 equal to"  ".



Basic c program using string for getting clear understanding of Initialisation and declared string:-

#include<stdio.h> 

  int main() 
{    

    // declare and initialize string 

    char str[] = "insproutsoftware"; 

      

    // print for use for printing string 

    printf("%s",str); 

      

    return 0; 


       For more details click here:-

close