Dereferencing Your Return Value Immediately So You Don't Need to Use It as a Pointer - C++ Function

C++ examples for Function:Function Return

Description

Dereferencing Your Return Value Immediately So You Don't Need to Use It as a Pointer

Demo Code

#include <iostream> 
#include <string>
using namespace std; 

string *readCode() //w  w w  .  j a  v a  2  s. c  o m
{ 
  string *code = new string("ABCDEF"); 
  return code; 
} 

int main() 
{ 
  string newcode; 
  int index; 

  for (index = 0; index < 10; index++) 
  { 
    newcode = *readCode(); 
    cout << newcode << endl; 
  } 

  return 0; 
}

Result


Related Tutorials