0 c++
#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;
}
Run Code Online (Sandbox Code Playgroud)
这里有什么错误?当我在该功能中显示内容时它正在输出,但是当我尝试在该功能之外显示内容时它显示垃圾.怎么了?