Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          strings/knold-tot-c-like-4.cc - The Knold & Tot example with char* aliasing.Lecture 3 - slide 12 : 27
Program 5

// Illustrates pointer access to C-style trings.

#include <iostream>
#include <cstring>    // Corresponds to <string.h> in a C program.

void g(){
  char s1[6] = "Knold",
       s2[4] = "Tot",
       *ps1 = &s1[0],    
       *ps2 = &s2[0];

  ps1 = ps2;            // OK here.  Both ps1 and ps2 point at Tot.
  ps2[1] = 'u';         // Affects both ps1 and ps2
  
  std::cout << ps1 << " og " << ps2 << std::endl;   // Tut og Tut
}

int main(){
  g();
}