你能帮我理解存储变量的位置(堆栈,堆,静态内存)吗?我怎样才能确定它?我的意思是不直观,但我想在screan上印上一些标志.可能吗?
到目前为止,我试图通过打印地址来查看变量的存储位置.但这并没有给我太多帮助.你能看看并给我一些建议.如果我犯了一个错误(请参阅我对该计划的评论),请告诉我这个问题.
#include "stdafx.h"
#include <iostream>
using namespace std;
int * p1 = new int [3]; // Static memory as it is a global array;
namespace P {int * p2 = new int[3];} // Static memory as it is a namespace;
namespace {int * p3 = new int[3];} // Static memory as it is a namespace;
using namespace P;
int _tmain(int argc, _TCHAR* argv[])
{
int * p4 = new int[3]; // Heap as there is a new operator.
static …Run Code Online (Sandbox Code Playgroud) 我想使用cin向char*变量输入一个不确定长度的字符串;
我可以做这个:
char * tmp = "My string";
cout << tmp << endl;
system("pause");
Run Code Online (Sandbox Code Playgroud)
它完美地运作.
但我没有做到这一点:
char * tmp
cin >> tmp;
Run Code Online (Sandbox Code Playgroud)
你能告诉我一个什么是错的"
我莫名其妙地无法抓住这个想法,阅读文档并没有帮助我.
我的问题是:
我在Visual Studio 2010中尝试了这一切.至少没有语法错误.但我想解释一下.所以,我希望你会善良并帮助我.
我只是想知道为什么n = 0?
char c = 0xff;
int n = c+1;
cout << n << endl;
system("pause");
Run Code Online (Sandbox Code Playgroud)
1)c = 0xff
2)0xff + 1 = 0x100.
你能解释一下吗?