`#include <iostream>
using namespace std;
int main()
{
char arr[20];
int i;
for(i = 0; i < 10; i++) {
*(arr + i) = 65 + i;
}
*(arr + i) = '';
cout << arr;
return 0;
}`
I am completely new to programming in C++ and cannot understand this piece of code. It was given to me as a question to solve in my pointers lecture and the output comes out to be “ABCDEFGHIJ” but I cannot understand the working of this code.
I specifically don’t understand what’s happening here:
*(arr + i) = 65 + i;
i.e., how are the alphabets being assigned through their ascii value, how does the computer understand that we have passed an ascii value and not any random integer and this part:
*(arr + i) = ”;
exactly what index of the array becomes a null value here?
CASHmonk25 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
21