矩阵打印使用指针
Matrix Printing using Pointers
我被这个问题难住了,我真的需要一些帮助。我有一个函数Void f(int *a, int m, int n),它应该打印所有使用指针的元素。I tried
for(i = 0; i < m; ++i)
for(j = 0; j < n; ++j)
cout << *((a+i)+j);
,但它不打印正确的元素。请帮帮我。
在main函数中,我声明了矩阵,然后读取了元素。
int col, rand, i, j;
int a[100][100];
cout << " col = ";
cin >> col;
cout << " rand = ";
cin >> rand;
for(i = 0; i < rand; ++i)
for(j = 0; j < col; ++j)
{
cout << "a[" << i << "]" << "[" << j << "] = ";
cin >> *(*(a+i)+j);
}
当我尝试从main函数中打印元素时,一切正常
for(i = 0; i < rand; ++i)
for(j = 0; j < col; ++j)
cout << *(*(a+i)+j);
f(*a, col, rand); // function calling in the main function
Try
cout << *(a+i*(p+1)+j);
但我认为下面也会工作。(m
和n
与r
和p
的关系需要澄清。
for(i = 0; i <= r; ++i)
for(j = 0; j <= p; ++j)
cout << *a++;
相关文章:
- 为什么我的函数无法使用指针打印多维数组的元素?
- 对象指针打印结果以相反的顺序进行
- 使用指针打印链表中的节点
- 从指针打印动态int阵列中获取怪异的字符
- 通过尾指针打印节点的钥匙
- 如何使用箭头指针打印出一类数组对象,这些对象中有多个分数
- 如何存储变量的地址并使用指针打印值
- 如何用指针打印一系列字符
- 如何通过指针打印 2D 阵列?C++
- 使用指向列表的指针打印列表
- 如果根本不使用单个取消引用运算符,指向指针的指针打印什么值
- 使用指向字符的指针打印字符数组
- 如何在C++中从一组对象指针打印
- 当用另一个指针打印时,同一指针会给出不同的地址
- 如何使用指针的指针打印姓名列表?
- 用指针打印二进制搜索树C++的奇怪方法
- 通过指针打印矩阵
- 为什么即使在调试版本中,VS 和 Windbg 也会"this"指针打印为"0xcccccccc"?
- 使用for循环和指针打印浮点数组
- 无法使用指针打印 2D 矩阵的值