二维数组和指针 [英] Two dimensional arrays and pointers

查看:162
本文介绍了二维数组和指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code片断:

I have the following code snippet:

char board[3][3] = {
                     {'1','2','3'},
                     {'4','5','6'},
                     {'7','8','9'}
                   };

printf("address of board : %p\n", &board);
printf("address of board[0] : %p\n", &board[0]);

两者的printf()语句都打印相同的值: 0x0013ff67

Both printf() statements all print the same value: 0x0013ff67


  1. 按我的知识,板(即)数组名重新presents第一子阵(即)板[0] 和地址

板[0] 重新presents第一要素的第一阵列中的地址(即)板[0] [0]

board[0] represents the address of first element in the first array (i.e) board[0][0]

为什么会出现在我所有的的printf()语句相同的地址?我希望不同的地址,这两个语句。

Why am I getting the same address in all my printf() statements? I expect different addresses for both statements.

我是pretty新的这个东西,不理解这种行为。请赐教。

I am pretty new to this stuff and don't understand this behavior. Kindly enlighten me.

推荐答案

尽管这是一个二维数组,内存里面将重新psented为线性阵列$ P $。所以当你说,板[0] [0]它仍然指向线性阵列中的第一个元素,因此相同的内存地址。

Though it's a 2D array, inside the memory it will be represented as linear array. so when you say, board[0][0] it still points to the first element in that linear array and hence the same memory address.

这篇关于二维数组和指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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