Question about defining string Guess

I’ve got some background experience in C++ but it’s been some time so I’ve been watching every video in its entirety anyway, but on S02L15 Ben says to define the string Guess like so…

string Guess = " ";

I’ve never seen this before, and every time I’ve defined a string in the past and every time I’ve read code with a string I’ve seen it like this

string Guess;

The difference is that the first way there is actually a value for Guess, and it’s a space whereas in the second way it’s defined as a null value.

Is there a reason why you should define it as an empty value as opposed to just a null value? Wouldn’t it create memory issues and be poor practice?

@ben is just trying to reinforce the importance of initialising variables. Though since std::string is a class which has a default constructor doing std::string Guess = " "; or with just "" isn’t needed.

Privacy & Terms