c - 指针值修改行为
问题描述
我是 C 程序员初学者,我遇到了一些我无法完全理解的事情。
这是我的整个代码:
#include <curses.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <winuser.h>
#define DELAY 300000
int x = 3, y = 20;
int max_y = 0, max_x = 0;
int next_x = 0;
int directionX = -1;
int directionY = 0;
int main(int argc, char *argv[])
{
initscr();
noecho();
curs_set(FALSE);
getmaxyx(stdscr, max_y, max_x);
while(1)
{
// drawing on the map
clear();
mvprintw(y, x, "o");
refresh();
usleep(DELAY);
// make next step
next_x = x + directionX;
//set next step directionX
if (next_x >= max_x || next_x < 0)
{
directionX*= -1;
}
else
{
x+= directionX;
}
}
endwin();
}
从我的调试中,这张图片描述了我无法完全理解的问题:
请有人向我解释一下,如何将指针值分配给-1并接收+1?
解决方案
推荐阅读
- html - 使用分页符设置表格的最大行并将剩余数据显示到下一页
- r - 即使可以从终端运行相同的命令,R system() 也无法分配内存
- python - AWS Sagemaker | 为什么多实例训练所花费的时间乘以实例数
- javascript - 国际化电话号码正则表达式
- excel - pywin32选择excel列中的所有数据
- java - 从角度获取数据时出现CORS问题
- sql - 将数据类型更改为与第二个数据库相同
- boost-spirit - 由于 boost 精神占位符限制不超过 10 导致编译错误
- docker - HAProxy Docker Container 无法使用 localhost 在我的 Cockroach DB docker 容器之间进行负载平衡
- css - 我在这里过度使用 sass 扩展了吗?