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).
Array int `a[3];` is a local array of function sqcb. After exiting the function the memory used by the function is relaesed and can be used for other requirements (for example it can be used by operator functions of stream std::cout). So your program has undefined behaviour because the function returns a pointer to this released memory, 

You could get well-formed program if you would define this array as having static storage duration. For example

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

```