#include <iostream>
using namespace std;
int main() {
int* ptr = nullptr;
*ptr = 10;
return 0;
}
- Issue: Segmentation fault (SIGSEGV) or a similar error
- Explanation: The code declares a pointer
ptr
and initializes it with a null pointer (nullptr). - Problem: Dereferencing the null pointer by trying to assign a value to the memory location it points to (
*ptr = 10;
). - Outcome: This results in undefined behavior and often causes a segmentation fault as it's illegal to access or modify memory using a null pointer.