指针算术问题 [英] Pointer Arithmetic Problem
问题描述
#include< stdio.h>
int main(无效)
{
char arrc [] = {'''',''b'',''c'',''\ 0''};
char * pc = arrc;
char ** ppc =& pc;
printf(" arrc =%s \ n",arrc);
printf(" - ----------------------- \ n");
printf(" * pc =%5c \ n" ,* pc);
printf(" ** ppc =%5c \ n",** ppc);
printf(" ++ * pc = %5c,* pc =%5c \ n",++ * pc,* pc);
printf("(** ppc)++ =%5c,** ppc =% 5c\ n,(** ppc)++,** ppc);
返回0;
}
=== ==================输出==========================
[arnuld @ dune ztest] $ gcc -ansi -pedantic -Wall -Wextra ok.c
[arnuld @ dune ztest] $ ./a.out
arrc = abc
------------------------
* pc = a
** ppc = a
++ * pc = b,* pc = a
(** ppc)++ = b,** ppc = b
[arnuld @ dune ztest] $
我对输出感到困惑。在++ * pc之后,* pc应该打印
''b'',而不是''a''。同样适用于** ppc,即使在经历了++之后再次打印相同的元素
。
-
www.lispmachine.wordpress.com
我的电子邮件是@ the以上博客。
Gooogle群组已被屏蔽。原因:过度垃圾邮件
#include <stdio.h>
int main( void )
{
char arrc[] = { ''a'', ''b'', ''c'', ''\0'' };
char* pc = arrc;
char** ppc = &pc;
printf("arrc = %s\n", arrc);
printf("------------------------\n");
printf("*pc = %5c\n", *pc);
printf("**ppc = %5c\n", **ppc);
printf("++*pc = %5c, *pc = %5c\n", ++*pc, *pc);
printf("(**ppc)++ = %5c, **ppc = %5c\n", (**ppc)++, **ppc);
return 0;
}
===================== OUTPUT ==========================
[arnuld@dune ztest]$ gcc -ansi -pedantic -Wall -Wextra ok.c
[arnuld@dune ztest]$ ./a.out
arrc = abc
------------------------
*pc = a
**ppc = a
++*pc = b, *pc = a
(**ppc)++ = b, **ppc = b
[arnuld@dune ztest]$
I am little confused at the output. after ++*pc , the *pc should print
''b'', not ''a''. Same for **ppc, which is again printing the same element
even after having gone through a ++.
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Gooogle Groups is Blocked. Reason: Excessive Spamming
推荐答案
gcc -ansi -pedantic -Wall -Wextra ok.c
[ arnuld @ dune ztest]
gcc -ansi -pedantic -Wall -Wextra ok.c
[arnuld@dune ztest]
./ a.out
arrc = abc
---------- --------------
* pc = a
** ppc = a
++ * pc = b,* pc = a
(** ppc)++ = b,** ppc = b
[arnuld @ dune ztest]
./a.out
arrc = abc
------------------------
*pc = a
**ppc = a
++*pc = b, *pc = a
(**ppc)++ = b, **ppc = b
[arnuld@dune ztest]
我对输出感到困惑。在++ * pc之后,* pc应该打印
''b'',而不是''a''。同样适用于** ppc,即使在经历了++之后再次打印相同的元素
。
-
www.lispmachine.wordpress.com
我的电子邮件是@ the以上博客。
Gooogle群组已被屏蔽。原因:过度垃圾邮件
I am little confused at the output. after ++*pc , the *pc should print
''b'', not ''a''. Same for **ppc, which is again printing the same element
even after having gone through a ++.
--
www.lispmachine.wordpress.com
my email is @ the above blog.
Gooogle Groups is Blocked. Reason: Excessive Spamming
这篇关于指针算术问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!