When I compile and run this program via gcc(g++)/Cygwin it compiles and acts as expected.
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
for (int arg = 1; arg <= argc; arg++)
{
cout << argv[arg] << endl;
}
return 0;
}
However, when compiling with Visual Studio 13, the program compiles but I am given an access violation upon execution. What gives?
Unhandled exception at 0x000B5781 in demo.exe: 0xC0000005: Access violation reading location 0x00000000.
arg <= argcSo if you have 1 argument (argc = 1) you will getarg = 1and1 <= 1and then go on and doargv[1]which is the second of ... one arguments. Also it appears that Visual Studio compiles the code just fine, as evidenced by the fact that ... it compiled and you ran the program. - ta.speot.is