Returning pointer to structure to main function, getting segmentation error
<pre><code>#include&lt;iostream&gt;
using namespace std;
struct sample
{
    int data[3][2];
};
struct sample* function()
{
    struct sample s;
    int c=1;
    for(int i=0;i&lt;3;i++)
     for(int j=0;j&lt;2;j++)
      s.data[i][j]=c++;

    cout&lt;&lt;"Matrix contents are ";
    for(int i=0;i&lt;3;i++)
    {
     for(int j=0;j&lt;2;j++)
      cout&lt;&lt;s.data[i][j])&lt;&lt;"\t";
     cout&lt;&lt;"\n";
    }
    return &amp;s;
}
int main()
{
struct sample *ss;
ss=function();
cout&lt;&lt;"Matrix contents are ";
for(int i=0;i&lt;3;i++)
{
    for(int j=0;j&lt;2;j++)
     cout&lt;&lt;ss-&gt;data[i][j]))&lt;&lt;"\t";
    cout&lt;&lt;"\n";
}
return 0;
}
</code></pre>

<p>What is the error here? When I display content <em>in</em> that function it is getting output, but when I try to display contents outside of the function it displays garbage.  What is wrong?</p>
