I'm sure you'll find out as soon as you use them. It's rather obvious.
You should make the first one return a const char& or a char since the function is const and you shouldn't be providing non-const access to the member data. But that's not the obvious thing that is wrong with them.
if i is -1 you will return buf[-1] - out of bounds access
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
in this case using i == stringlength will give you the out of bound access
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
How do I make the print function use printf() to output the name of the string, the string literal, and the size of the string literal with the three all displayed on one line per string object?
What is string name?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
like
?Code:printf("%s: %s(%d)\n", name, buf, stringlength);
But why do you need a printf if you trying to write in C++?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler