What will be the output of the following C++ code?

#include <iostream>
   using namespace std;
   int main()
   {
       char arr[20];
       int i;
       for(i = 0; i < 10; i++)
           *(arr + i) = 65 + i;
       *(arr + i) = '\0';
       cout << arr;
       return(0);
   }

a) ABCDEFGHIJ
b) AAAAAAAAAA
c) JJJJJJJJ
d) AAAAAAJJJJ

1 thought on “What will be the output of the following C++ code?”

  1. a
    Explanation: Each time we are assigning 65 + i. In first iteration i = 0 and 65 is assigned. So it will print from A to J.
    $ g++ point1.cpp
    $ a.out
    ABCDEFGHIJ

Leave a Comment