c之数组指针学习
#include <stdio.h> int main(int argn ,char *argv[]) { int buf[10] = {1,2,3,4,5,6,7,8,9}; int (*p1)[3] = &buf; int (*p2)[3] = buf; int * p3 = (int*)((int)buf + 1); int test = *((int *)(p1 + 1)); return 0; }
输出结果:
Breakpoint 1, main (argn=1, argv=0x7ffd994dd1a8) at /home/43521/TestDemoC/./Src/main.c:4 4 { (gdb) n 5 int buf[10] = {1,2,3,4,5,6,7,8,9}; (gdb) n 6 int (*p1)[3] = &buf; (gdb) n 7 int (*p2)[3] = buf; (gdb) n 8 int * p3 = (int*)((int)buf + 1); (gdb) n 9 int test = *((int *)(p1 + 1)); (gdb) n 11 return 0; (gdb) p buf $1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} (gdb) p &buf $2 = (int (*)[10]) 0x7ffd994dd090 (gdb) p p1 $3 = (int (*)[3]) 0x7ffd994dd090 (gdb) p p2 $4 = (int (*)[3]) 0x7ffd994dd090 (gdb) p p3 $5 = (int *) 0xffffffff994dd091 (gdb) p test $6 = 4 (gdb)
青青园中葵,朝露待日晞。
阳春布德泽,万物生光辉。
常恐秋节至,焜黄华叶衰。
百川东到海,何时复西归?
少壮不努力,老大徒伤悲!