【发布时间】:2011-07-09 21:37:24
【问题描述】:
我有一个小的学校作业。我的输出不正确。你能看看我做错了什么吗?
//1. Create a char pointer named cp
char *cp;
//2. Dynamically allocate a char and store its address in cp
char dynamicChar = 'A';
cp = &dynamicChar;
//3. Write the character 'x' into the char
*cp = 'x';
//4. Print out the value of the char using cout
cout << cp << endl;
打印输出语句打印A@@ 而不仅仅是A。我不确定我做错了什么。
【问题讨论】:
-
“动态分配一个字符” - 可能意味着:cp = new char;
标签: c++ pointers char dereference