What will be the output of the program?
#include <iostream>
#include <string.h>

using namespace std;

const char a[] = "12345";

int main() {
    char* b = new char[sizeof(a)];
    strncpy(b, a, sizeof(a));
    char* c = new(b) char('5');
    cout << a << endl << b << endl << c;
Using an additional option of the new operator, memory for c was allocated inside the block previously allocated for b.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Sign Up Now
or Subscribe for future quizzes