22 lines
412 B
C++
22 lines
412 B
C++
|
|
#include "test_errors.h"
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
// 空指针解引用
|
||
|
|
void test_null_pointer() {
|
||
|
|
int* p = nullptr;
|
||
|
|
std::cout << *p << std::endl;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 数组越界
|
||
|
|
void test_array_out_of_bounds() {
|
||
|
|
int arr[3] = {1,2,3};
|
||
|
|
std::cout << arr[10] << std::endl;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 未初始化变量
|
||
|
|
void test_uninitialized_var() {
|
||
|
|
int val;
|
||
|
|
if (val > 10) {
|
||
|
|
std::cout << "val > 10" << std::endl;
|
||
|
|
}
|
||
|
|
}
|