Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    The Knold & Tot example with char*.Lecture 2 - slide 14 : 42
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();
}