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

C++ examples for Function:Function Creation

Introduction

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

Demo Code

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

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

int main() // www  . j  a  va 2s .  c  o m
{ 
  printName("a", "b"); 
  return 0; 
}

Result


Related Tutorials