我仍然对STL中的map和set数据结构之间的差异感到困惑.我知道set是以排序的方式存储值,那么map呢?它是按排序顺序存储值吗?地图存储成对的值(键,值),这个功能的优点是什么?
以下程序运行正常
#include <stdio.h>
#include <string.h>
int * p(void);
main()
{
int *x = p();
printf("%d", *x);
}
int * p(void)
{
int x;
x=10;
return (&x);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我像这样修改上面的程序
#include <stdio.h>
#include <string.h>
int * p(void);
main()
{
int *x = p();
printf("%d", *x);
}
int * p(void)
{
int *x;
*x=10;
return (x);
}
Run Code Online (Sandbox Code Playgroud)
在执行上述代码时,抛出分段错误错误.
谁能解释这种行为?