C++ Function Definition Keeping your variables local in your function

Introduction

To see a local variable at work, consider the code in the following example:


#include <iostream> 

using namespace std; 

void printName(string first, string last) 
{ 
  string fullname = first + " " + last; 
  cout << fullname << endl; 
} 

int main() //ww  w  .java  2s  . c om
{ 
  printName("a", "b"); 
  return 0; 
}



PreviousNext

Related