What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
char* buff;
try
{
buff = new char[1024];
if (buff == 0)
throw "Memory allocation failure!";
else
cout << sizeof(buff) << "Byte successfully allocated!"<<endl;
}
catch(char *strg)
{
cout<<"Exception raised: "<<strg<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char* buff;
try
{
buff = new char[1024];
if (buff == 0)
throw "Memory allocation failure!";
else
cout << sizeof(buff) << "Byte successfully allocated!"<<endl;
}
catch(char *strg)
{
cout<<"Exception raised: "<<strg<<endl;
}
return 0;
}
A. 4 Bytes allocated successfully
B. 8 Bytes allocated successfully
C. Memory allocation failure
D. Depends on the size of the data type
Answer: Option D
What is the correct syntax for defining a function in C++?
A. returnType functionName(parameters) { body; }
B. functionName(parameters) { returnType body; }
C. functionName(returnType, parameters) { body; }
D. returnType functionName(parameters, body) { }
What is the purpose of a function prototype in C++?
A. Determines the parameters of the function
B. Specifies the return type of the function
C. Provides the implementation of the function
D. Declares the function before it is defined
Which keyword is used to define a function in C++ that does not return any value?
A. return
B. null
C. void
D. None of the above
What is the correct way to call a function named "add" that takes two parameters in C++?
A. add(a, b);
B. add(int a, int b);
C. functionName = add(a, b);
D. add.functionName(a, b);
Join The Discussion