Segmentation fault executing SetPoint in script

Please read tips for efficient and successful posting and posting code

_ROOT Version:_6.20/04
Platform: Ubuntu 18.04 running in a VirtualBox VM on Win 10 laptop
Compiler: installed CERN binary

I am totally new to root (and almost totally new to c++) and I was following a tutorial video from ACU. In lesson 2 he uses SetPoint to generate data for a graph. When I tried to emulate the code I get a seg fault. The SetPoint statement works OK from the ROOT command line but within a script it causes a fault. Can someone please let me know if I am doing something wrong?

  g=new TGraph();
    g->SetPoint(k, k, k*k-4*k+7);

I also have a non-root-related question. I hate re-typing. Does anyone know how to paste items that I copied to the clipboard from within the VM running Linux to the windows side? I already installed the Guest Additions.

  TGraph *g = new TGraph();
  for ( Int_t k = 0; k < 25; k++ ) {

ROOT Primer

ROOT Courses -> Basic

Google -> learn C++

Google -> VirtualBox clipboard

I also have a non-root-related question. I hate re-typing. Can you use Google to search for solutions of non ROOT related questions yourself? You do not need to install any additions.

Many thanks Wile_E,
My original post had comma separators rather than semi-colons in the for statement although in the script I had the correct separators. The thing that I missed was declaring k as an integer. Do you have any idea why the script worked without declaring k as an integer in the tutorial I was watching? Could an earlier version of ROOT, or another version of Linux not have required declaring the variable?