LogiQuest
Back to Operator Overloading
8

What will be the output of the program?

#include <iostream>
using namespace std;
struct A {
    int d[3] = {7, 8, 9};
    int &operator[](int i) { return d[i]; }
};
int main() {
    A a;
    a[1] = 50;
    cout << a[0] + a[1] << endl;
    return 0;
}
Medium

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.