samedi 7 septembre 2019

Size of array using string length

I read that the size of array should be known at compile time.

If I am right then below code should not work, but it is compiling without any warnings and is working fine.

Could you please explain me what is happening ?

std::string s = "ABCDEFGHIJ"; 

 int n = s.length(); 

// declaring character array 
char char_array[n + 1];

std::cout << sizeof(char_array) << std::endl;

//Actual result

11

Aucun commentaire:

Enregistrer un commentaire