+ 3

What is the meant by char* p= new char[0]; ?

I recently saw a code with a char pointer was initialised like char *str= new char[0]; But I can't understand why it is possible and what is its use?? Please help

8th Mar 2019, 4:23 PM
Vedansh
Vedansh - avatar
5 Réponses
0
this is a pointerto a character and 0 marks the end of a string. this is an array of strings which are terminated by the value null, its memory adress pointer is marked with null.
11th Mar 2019, 12:22 PM
Buhle 💃💃💃
Buhle 💃💃💃 - avatar
0
Declared a string pointer variable *str and initialized it with char[0] element.
19th Mar 2019, 4:22 AM
Nur MD Bijoy (Rohan)
Nur MD Bijoy (Rohan) - avatar
0
Nur MD Bijoy (Rohan) according to your answer a pointer is initialised by a char!! [0] is the size of array here
19th Mar 2019, 4:36 AM
Vedansh
Vedansh - avatar
0
Buhle so now str ==nullptr ? Or (*str) == '\0'?
19th Mar 2019, 4:38 AM
Vedansh
Vedansh - avatar
0
Vedansh this is gonna be the initial index
19th Mar 2019, 6:31 AM
Nur MD Bijoy (Rohan)
Nur MD Bijoy (Rohan) - avatar