String In C Language
In C programming a
string is a sequence of characters terminated with null character \0.
Example:
char c[]=”c string”;
the compiler encounter
a sequence of character enclosed in the double quotation marks, it oppends a
null character \0 at the ends by
default.
How to declare string?
Here we will declare
string:
char s[5];
How to initialize strings?
We can initialize
string in a number of ways.
char c[]=”abc”;
char c[50]=”abcd”;
char c[]= {‘a’,’ b’, ’c’, ’d’, ‘\0’);
char c[5]= {‘a’,’ b’, ’c’, ’d’, ‘\0’);
Initialize string |
Assigning Value to strings
Array and string are
second-class citizen in c. they do not support assignment operator once it is
delcareed.
Example:
char c[10];
c= “C programming”;
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char name[20];
printf(“Enter name :”);
scanf(“%s”,name);
printf(“your name is
%s”, name);
getch();
}
Output:
Enter your name:
pramod
Your name is : pramod
No comments:
Post a Comment