I came across this question while practicing pointer questions, and, according to my understanding, I thought option C would be correct, but Option D was the correct answer, so I ran the code in Visual Studio Code and it did give a compilation error.
Strings are terminated by a NULL character. Then why is an error occurring if the for loop is checking for the occurrence of the NULL character?
What is the problem with this code? Here is the actual code:
#include<iostream>
using namespace std;
int main() {
char st[] = "ABCD";
for(int i = 0; st[i] != ‘\0’; i++) {
cout << st[i] << *(st)+i << *(i+st) << i[st];
}
return 0;
}