I am getting "Access violation" error but unable to identify the root cause for it . I am new to c++ and preparing for C++ coding contest as a beginner. Please help me to get the root cause for it. Please find the attached screenshot.
Thanks in advance .
Here is my code in a single .cpp file.
#include <iostream>
using namespace std;
void reverse(char *str) {
char * end = str;
char tmp;
if (str) {
while (*end) {
++end;
}
--end;
while (str < end) {
tmp = *str;
*str++ = *end; //Getting exception here
*end-- = tmp;
}
}
}
int main ()
{
char *str="Test";
cout << "Before change"<<str; // prints Hello World!
reverse(str);
cout << "After change"<<str; // prints I'm a C++ program
getchar();
}