【发布时间】:2014-04-16 16:42:44
【问题描述】:
我正在检查我在 stackoverflow 上看到的一些答案,并以一种非常有经验的程序员认为不应该工作的方式改变了一行,令人惊讶的是它确实做到了。谁能解释为什么它是可能的? 问题是具有多个字符的字符常量(我使用的是 Visual Studio 2013)
// stack.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using std::cout;
int * foo()
{
int a = 5;
return &a;
}
int main()
{
int* p = foo();
cout << *p << ' '; // this line should not compile but it did???
*p = 8;
cout << *p << '\n';
}
【问题讨论】:
-
你用你的代码测试什么,多字符文字或未定义的行为?如果您只有关于多字符文字的问题,请删除导致未定义行为的其余代码,它与问题无关,并且会分散您对实际问题的注意力。