C++

Objectives :

  • File Name: string_iteration_Cstrtok1.cpp
    Showing C/strtok function, finds the next token in a string, and similar task can be done with simple string iteration.
  • dynamic memory management
    • chptr1 = new char [str.size()+1];
       delete[] chptr1;
    • C/strcpy (chptr1, str.c_str());
       
  • Syntax :
    #include <string.h>
    char *strtok( char *str1, const char *str2 );
     
  • Code : string_iteration_Cstrtok1.txt
 

Step: 1 Create a source file.

Step: 2 Edit and save Source file

Step: 3 Runtime Views:

Step: Brief discussion :

Operators new and new[]
C++ language offers dynamic memory allocation with the "operator new. new is followed by a data type specifier.

int * n1;
n1= new int [25];

Operators delete and delete[]
Since we enforce new memory allocation, at the end this memory should be freed up using "delete" keyword.

delete pointer;
delete [] pointer;