-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsource.cpp
More file actions
42 lines (33 loc) · 886 Bytes
/
source.cpp
File metadata and controls
42 lines (33 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <vector>
class Example {
int* ptr;
public:
Example() : ptr(new int(42)) {} // Memory leak potential
void setPtr(int* p) {
delete ptr; // Potential double delete
ptr = p;
}
~Example() {
delete ptr; // Potential double delete
}
};
int divide(int a, int b) {
if (b == 0) {
std::cout << "Division by zero!" << std::endl; // Exception not thrown
return -1;
}
return a / b;
}
int main() {
Example ex;
int x = 10;
int y = 0;
std::cout << divide(x, y) << std::endl; // Divide by zero at runtime
int* ptr = nullptr;
std::cout << *ptr << std::endl; // Dereferencing null pointer
std::vector<int> vec;
std::cout << vec[10] << std::endl; // Out of bounds vector access
return 0;
}