#include<iostream>
using namespace std;
struct sample
{
int data[3][2];
};
struct sample* function()
{
struct sample s;
int c=1;
for(int i=0;i<3;i++)
for(int j=0;j<2;j++)
s.data[i][j]=c++;
cout<<"Matrix contents are ";
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
cout<<s.data[i][j])<<"\t";
cout<<"\n";
}
return &s;
}
int main()
{
struct sample *ss;
ss=function();
cout<<"Matrix contents are ";
for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
cout<<ss->data[i][j]))<<"\t";
cout<<"\n";
}
return 0;
}
What is the error here? When I display content in that function it is getting output, but when I try to display contents outside of the function it displays garbage. What is wrong?