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

// Illustrates that C-like strings cannot be assigned.
// The similar assignment is possible on C++ strings.
// Does not compile.

#include <iostream>

void g(){
  char s1[6] = "Knold",
       s2[6] = "Tot  ";

  s1 = s2;           // Compiler error: Invalid array assignment
  s2[1] = 'u';       // OK.
  
  std::cout << s1 << " og " << s2 << std::endl; 
}

int main(){
  g();
}