最近我遇到了这个我自己无法理解的问题.
这三个表达式真正意味着什么?
*ptr++
*++ptr
++*ptr
Run Code Online (Sandbox Code Playgroud)
我试过里奇.但不幸的是,他无法按照他讲述的这三项行动.
我知道它们都是为了递增指针/指向的值而执行的.我还可以猜测可能有很多关于优先级和评估顺序的事情.就像一个指针首先递增指针然后取出指针的内容,一个简单地取出内容然后递增指针等等.正如你所看到的,我对他们的实际操作我没有清楚的理解,我想尽快明确.但是当我有机会将它们应用到程序中时,我真的迷失了.例如:
int main()
{
const char *p = "Hello";
while(*p++)
printf("%c",*p);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
给我这个输出:
ello
Run Code Online (Sandbox Code Playgroud)
但我的期望是它会印刷Hello.最后一个请求 - 请给出一些示例,说明每个表达式在给定的代码段中的工作原理.因为大多数时候只有一段理论飞过我的脑海.
我有一个任务,要求我用随机变量填充堆栈并在FILO命令中弹出它们.虽然我设法让它填满堆栈,但它似乎突然出现了最后一个元素而没有别的.我不知道为什么.任何帮助,将不胜感激.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define STACK_SIZE 10
#define STACK_EMPTY -1
void push(char [], // input/ouput - the stack
char, // input - data being pushed onto the stack
int *, // input/output - pointer to the index of the top of stack
int); // constant - maximum size of stack
char // output - data being popped out from the stack
pop(char [], // input/output - the stack
int *); // input/output - pointer to the index …Run Code Online (Sandbox Code Playgroud)