1,014 views

Which of the following is illegal declaration in $C$ language?

1. char*str ="Raj is a Research scholar";

2. char str[25] ="Raj is a Research scholar";

3. char str[40] ="Raj is a Research scholar";

4. char[]str ="Raj is a Research scholar";

Ans initialization  of variable in Option D not valid

Character array/ string initialization:
char variable_name[]= "India";
OR
char variable_name[10]= "India"; 

option B,D let str[25} an char array and starting address of array is 1000

 R a j i s a r e a r c h s c h o l a r /0 /0

in Option A  str is char pointer which pointing or store starting address of char array

str

 1000

whats the difference between options B and C?
@gatecse only the size of array is different (25 vs 40).
There is a spelling mistake in the answer. If corrected we can see that the given string does not fit in 25 characters or does it?
The compiler will not throw any error or warning, but since there is no space left for ‘\0’, you’ll see some garbage value after “scholar”.
corect option is d

char[]str ="Raj is a Research scholar";it is not a valid declaration in c language .
by