* String :
1] "String is one dimensional array of type char".
2] Every string is "C" terminates with null character [\o].
3] The string constant is a set of characters enclosed in double quotation.
Example :
Declaration Of String Variable :
1] The character array may be initialized at the time of declaration also.
2] It can be initialized into two two ways.
First way : char city [10]={'P','U','S','A','D'};
Second : char city [10]="PUSAD" ;
3] If an array is initialized where it is declared, mentioning the sizeis optional as in the following example. At this time, the size of array will be determined automatically, based on the number of element initialized.
First way : char name [ ]=" Sky " ;
Second way : char city [ ]={'H' , 'Y' , 'D'};
void main()
{
char name[80];
printf("Enter your name");
scanf("%s", name);
printf("You have entered=%s",name);
}
Output:
Enter your name
Eagle
Your have entered=Eagle
* Representation of string variable(char type array) in a memory:
Array elements are always stored in a contagious memory location.Consider the following example.
char A [5]=" Sky " ;
It can be represented in a memory as.
Element= A[0] A[1] A[2] A[3] A[4]
Value = S K Y '\0'
Address= 9770 9371 9372 9373 9374
C language has been the basocs of all.... Learning it would be useful to job aspirants
ReplyDeleteGreat work man
ReplyDelete