C++ Pointers Quiz - Question 5

Last Updated :
Discuss
Comments

What does the following C++ code do?

C++
#include<iostream>
using namespace std;

int main() {
    int *ptr = NULL;
    ptr = new int;
    *ptr = 7;
    cout << *ptr;
    delete ptr;
    return 0;
}

Outputs 0

Outputs 7

Causes a compile-time error

Causes a segmentation fault

Share your thoughts in the comments
Article Tags :