recategorized by
1,151 views
1 votes
1 votes
In which of the following case(s) character array must end with null char?
  1. char c[] = "GATE";
  2. char c[] = {'2', '0', '2', '3'};
  3. char c[4] = "GATE";
  4. char c[16] = "2023";
recategorized by

2 Answers

6 votes
6 votes

Answer: A, D

Option A: 

char c[] = "GATE";

Since size of array is not mentioned so ‘\0’ must be at the end of the string.

 

Option B: 

char c[] = {'2', '0', '2', '3'};

We initialized the array so array size will be 4.

 

Option C: 

char c[4] = "GATE";

Size of array is provided so this array will store 4 characters. No ‘\0’ at the end.

 

Option D:

char c[16] = "2023";

Since size of the array is 16 and we only initialized with 4 characters compiler will add ‘\0’ to all the remaining positions.

0 votes
0 votes

1.) char a[] = “GATE” : NULL IS THERE

2.) char a[] = {‘1’,’2’,’3’} : NULL IS NOT THERE : Bcoz size is 3 not 4

3.) size is 4 no space for null.

4.) We have null after ‘3’ till end of array.

edited by
Answer:

Related questions