Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    char* buffer;
    try
    {
    buffer = new char[1024];
    if (buffer == 0)
    throw "Memory allocation failure!";
    else
    cout << sizeof(buffer) <<" " << "Byte successfully allocated!"<
    }
    catch(char *strg)
    {
    cout<<"Exception raised: "< }
    return 0;
    }
    1. Depends on the size of the data type
    2. 4 Bytes allocated successfully
    3. 8 Byte successfully allocated!
    4. Memory allocation failure
    5. None of these
Correct Option: A

As we are allocating the memory to the variables and if there are not sufficient size means, it will throw an exception.



Your comments will be displayed only after manual approval.