Multiple choice technology programming languages

#include class NewInt { int num; public: NewInt(int n=0):num(n) {printf("cons\n");} int getInt() const {return num;} void setInt(int n){num =n;} ~NewInt(){printf("Dest\n");} }; int main() { NewInt a[5]; for(int i=0;i<=5;i++) a[i].setInt(i+10); for(int i=0;i<=5;i++) printf("%d\n",a[i].getInt()); return 0; } What does the above code snippet do?

  1. It creates an array of classes

  2. Gives compile time error

  3. It creates an array of objects

  4. It does nothing

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The code creates an array of 5 NewInt objects using the default constructor. However, there's a bug: the loops use i<=5 which accesses a[5], causing array index out of bounds. Despite this error, the intent is clearly to create and work with an array of objects.