Pointers and Strings C++

前端 未结 9 1170
栀梦
栀梦 2020-12-24 15:31

I\'m teaching myself C++ and I\'m a bit confused about pointers (specifically in the following source code). But first, I proceed with showing you what I know (and then cont

9条回答
  •  天命终不由人
    2020-12-24 15:51

    You are asking the right questions as a learner.

    Answers:

    1. In C++, string is an object, the c_str() essentially returns a pointer to the first character of the string (C Style)
    2. You are right about strings in C, the variable actually points to first character of the string
    3. C++ does lot of things based on the type of variable. When you pass a string object cout prints the string. Also, C++ is smart enough to determine *testing is illegal

提交回复
热议问题