1.导图:
2.源码:
#include <iostream>
using namespace std;
template <typename T>
class stack{
T data[10];
int top;
public:
stack():top(-1){};
void add_data(T data1){
if(top==9){
return;
}
top++;
data[top]=data1;
}
void del_data(){
if(top==-1){
return;
}
top--;
}
void show(){
for(int i=0;i<=top;i++){
cout<<data[i]<<"->";
}
cout<<"NULL"<<endl;
}
};
int main()
{
stack <int>t1;
t1.show();
t1.add_data(111);
t1.add_data(222);
t1.add_data(333);
t1.show();
t1.del_data();
t1.show();
return 0;
}
2.现象:
3.源码:
#include <iostream>
using namespace std;
void show(char *p,int i){
if(i>=12){
throw int();
}
cout<<*(p+i)<<endl;
}
int main()
{
char buf[12]="hello world";
try {
show(buf,12);
} catch (int) {
cout<<"访问越界"<<endl;
}
return 0;
}
3.现象: