c - &ar[0][0] 和 ar 的区别
问题描述
当我打印ar
和&ar[0][0]
作为指针时,我看到了相同的值。所以我希望它们可以互换,但是,事实并非如此:
int main(void)
{
#define rowsCount 4
#define colsCount 3
int ar[rowsCount][colsCount] =
{
{0, 1, 2},
{3, 4, 5},
{6, 7, 8},
{9, 10, 11},
};
int rowIndex = 1;
int colIndex = 5;
printf("TEST: %p %p\n", ar, &ar[0][0]);
printf("%d\n", ar[rowIndex][colIndex]);
printf("%d\n", *(&ar[0][0] + rowIndex * colsCount + colIndex));
printf("%d\n", *(ar + rowIndex * colsCount + colIndex));
return 0;
}
解决方案
推荐阅读
- odoo - 日记帐上没有定义默认借方和贷方账户 - Odoo v13
- android - Android Gradle 问题缩小启用 true
- python - 如何将函数的返回值保存到文件中
- php - 考试表格摘要中的模块更改
- ios - 如何为 enom 值输入变量?
- node.js - 尽管在 Mac 上工作,但在 Windows 上的 node.js ENOTFOUND
- laravel - 如何在 Laravel 8.0x 中调用资源控制器
- java - 高斯分布函数对程序和数学的不同答案
- java - Spark Java:向量汇编器的列名中的转义点
- python - 尝试在 Anaconda Prompt 中创建 tensorflow 环境时,为什么会收到“[Errno 13] Permission denied”?