Printing char* variable with cout in Visual Studio 2017

-2

I sometime get the following exception

enter image description here

Exception thrown at 0x00007FF9407FC231 (ucrtbased.dll) in Learn.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFEE87BF30. occurred

when I compile the following program in Visual Studio 2017 in x64:

#include <iostream>
using namespace std;

int main()
{
    char* c1 = (char*)"hello";
    cout << c1; //exception
    cin.ignore(1);
}

No problem when compile in x86. Sometimes no exception when I compile firstly in x86 and then in x64.

Is there any illegal code in the program or is it a compiler misbehavior?

c++
visual-studio
asked on Stack Overflow Nov 24, 2018 by nano • edited Nov 24, 2018 by nano

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0