今天我遇到了C ++问题,需要帮助 [英] Today I had trouble in a C++ question need help

查看:66
本文介绍了今天我遇到了C ++问题,需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int *pi;
for(*pi=0; *pi<5; *pi++)


此代码中的逻辑错误是什么?还是有任何错误?


What is the logical mistake in this code? Or is there any false?

推荐答案

首先,尝试为pi分配一个值:
Firstly, try assigning a value to pi:
int* pi = &integerVariable;


然后,尝试增加内容,而不是指针:
(* pi)++而不是* pi ++


Then, try incrementing the content, rather than the pointer:
(*pi)++ instead of *pi++


您已将pi声明为指向整数的指针,但尚未初始化它,则它指向随机地址;然后在for循环中,您使用的是pi拥有的随机地址.这可能会导致严重的问题,例如内存损坏,内存保护错误等.
You have declared pi as a pointer to integer, but you have not initialized it, then it points to a random address; then in the for loop you are using the random address that pi holds. This could cause serious problems as memory corruptions, memory protection faults, etc.


这篇关于今天我遇到了C ++问题,需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆