Declaration and Initialization of strings
Declaring an array of strings this way is rather tedious, that’s why C provides an alternative syntax to achieve the same thing. This above initialization is equivalent to:
har ch_arr[3][10] = {
"spike",
"tom",
"jerry"
};
The first subscript of the array i.e
3
denotes the number of strings in the array and the second subscript denotes the maximum length of the string. Recall the that in C, each character occupies 1
byte of data, so when the compiler sees the above statement it allocates 30
bytes (3*10
) of memory.
the initialization of a string variable,
Char first_name[15]="ARYAN";
Char first_name[15]={'A','R','Y','A','N','\0'};//null character '\0' is required at end in declaration
char string1[6]="hello"; /* string size ='h'+'e'+'l'+'l'+'o'+'\0'=6*/*
Char first_name[15]="ARYAN";
Char first_name[15]={'A','R','Y','A','N','\0'};//null character '\0' is required at end in declaration
char string1[6]="hello"; /* string size ='h'+'e'+'l'+'l'+'o'+'\0'=6*/*
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें