What type of initialization is needed for the segment “ptr[3] = ‘3’;” to work?

Category: QuestionsWhat type of initialization is needed for the segment “ptr[3] = ‘3’;” to work?
Editor">Editor Staff asked 11 months ago

What type of initialization is needed for the segment “ptr[3] = ‘3’;” to work?
 
(a) char *ptr = “Hello!”;
 
(b) char ptr[] = “Hello!”;
 
(c) both char *ptr = “Hello!”; and char ptr[] = “Hello!”;
 
(d) none of the mentioned
 
This question was posed to me in examination.
 
The origin of the question is Character Pointers and Functions in portion Pointers and Arrays in C of C
NCERT Solutions for Subject Computer science (C Programming) Select the correct answer from above options 
Interview Questions and Answers, Database Interview Questions and Answers for Freshers and Experience

1 Answers
Editor">Editor Staff answered 11 months ago

The correct choice is (b) char ptr[] = “Hello!”;
 
The explanation: None.