cout << "please enter a integer" << endl;
int num;
cin >> num;
char *A=(char *)malloc(sizeof(char));
int length = strlen(A);
char *test = A;
char *B = "heel";
while (num){
*test = num % 10 + '0';
num = num / 10;
*test++;
}
*test++ = '\0';
cout << endl << A<<endl<<length<<endl<<B;
为什么对test操作结果A输出相应的结果而test中是乱码?
为什么对test操作结果A输出相应的结果而test中是乱码?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
oyljerry 2015-05-07 14:15关注因为test指针你已经进行了++等操作,它已经指向末尾地址了,所以打印的时候是乱码了,而A是开始分配的地址空间,没有动。所以正确。
解决 无用评论 打赏 举报