C++ strings and pointers

This is because you have not allocate your objects prior to using them: It’s worth adding that using pointers in this situation is, well, pointless: string objects in the standard C++ library allocate the data for the string from the heap; strings are usually not much more than a pair of pointers anyway.

What does %s and %d mean in printf in the C language?

The printf() family of functions uses % character as a placeholder. When a % is encountered, printf reads the characters following the % to determine what to do: See this Wikipedia article for a nice picture: printf format string The \n at the end of the string is for a newline/carriage-return character.