Question: Why the below gives different Outputs?

```
 #include<iostream>

 using namespace std;

 int* sqcb(int n)
 {
     int a[3];
     a[0]=n*n;
     a[1]=n*n*n;
     a[2]=786;
     return a;  
 }

 int main()
 {
     int a,c;int const *b;
     cout<<"Enter an Integer:";
     cin>>a;

     b=sqcb(a);

     cout<<*(b)<<"\t"<<*(b+1)<<"\t"<<*(b+2)<<"\t"; // <- this

     cout<<*(b)<<"\t";   // <- and these
     cout<<*(b+1)<<"\t"; // 
     cout<<*(b+2)<<"\t"; // 
 }

```

Answer: 
```
int* sqcb(int n)
{
  int a[3];
  a[0]=n*n;
  a[1]=n*n*n;
  a[2]=786;
  return a;  
}

```

You are returning a pointer to a local variable, which is [naughty](http://en.wikipedia.org/wiki/Undefined_behavior).
You're returning a pointer to a local variable.  

You're not allowed to do that.  

The program is undefined, so anything can happen. Through bad luck, the program doesn't crash for you.  

Most likely, whatever data used to be where `b` points gets overwritten by the streaming function calls. 

If possible, increase the warning level of your compiler, and treat warnings as errors.

If you want to return a collection from a function, you should investigate `std::vector` and `std::array`.