#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;
}
這裏有什麼錯誤?當我顯示內容在該功能它獲得輸出,但當我試圖顯示內容之外的功能時,它顯示垃圾。哪裏不對?將結構指針返回到主函數,出現分段錯誤