| strings/knold-tot-c-like-1.cc - The Knold & Tot example with char*. | Lecture 2 - slide 18 : 28 Program 2 |
// Illustrates reference semantics of C-like strings.
#include <iostream>
void g(){
char *s1 = "Knold", // Compiler Warnings:
*s2 = "Tot"; // deprecated conversion from string constant to char*
s1 = s2; // Both s1 and s2 points to the same "Tot" C-style string.
s2[1] = 'u'; // Expected logical error here...
std::cout << s1 << " og " << s2 << std::endl; // Tut og Tut
}
int main(){
g();
}