Returning a Pointer to a Static Local Variable : Function Variables « Function « C++






Returning a Pointer to a Static Local Variable

Returning a Pointer to a Static Local Variable

#include <iostream>

using namespace std;

char * setName();

int main (void)
{
   char* str = setName();
   cout << str;
   return 0;
}

char* setName (void)
{
   static char name[80]; 
   cout << "Enter your name: ";
   cin.getline (name, 80);
   return name;
}

           
       








Related examples in the same category

1.Function local variableFunction local variable
2.Static function variableStatic function variable