Skip to main content

Posts

Showing posts from 2022

Example of Sting in C

  Basic Program of String in C Programing #include<stdio.h> #include<conio.h> void main( ) { char s[50]; clrscr( ); printf("\nEnter the string :"); scanf("%s",s); printf("\nYour string : %s",s); getch(); } Note : When we read the string we only specify the string name , because string is an array        and the array name will specify the base address i.e. address of the zeroth position           element. Thus , the statements , scanf("%s",s); and, scanf("%s",&s[0]);   are same. output : Enter the string : computer Your string : computer Enter the string : computer science Your string : computer This is because the scanf( ) function will get terminated by pressing the space.     Join us on Facebook: Click Here     c programming language,c programming software,c programming download,c programming online,c programming examples,c programming tutorial,c programming code c p...

About String in C

  String in C programing String is a sequence or a group of characters. The char type variable is capable of storing a single character while the character array is capable of storing the group of characters. So,string is just a character array. The general form of string declaration is , char stringname[size of array]; e.g.  char s[50]; This statement will declare the character array capable of storing the 50 characters. Initialization of string  To initialize the string there are two ways, (a) char str[5]={'a','j','a','y','\0'}; In this case , all the characters are enclosed in the single quotes and are given within the Curley braces separated by comma. '\0' is the NULL character and is used to end the string. (b) char s[5]="ajay"; When the string is initialized by enclosing the group of    characters in the double quotes , the    '\0' or NULL character will automatically get inserted. Reading and Displ...