这些是什么类型的指针之间的差异? [英] What are the differences between these type of Pointers?

查看:87
本文介绍了这些是什么类型的指针之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++编程code时,我不小心把支架固定到我的指针,我的程序输出的变化。

由于我新的编程,我想知道这些类型的指针之间的区别:

 为int * A [N];
INT(* A)[N];
为int *(A [N]);

我看了我的教科书数组也是一种指针。


解决方案

 为int * A [N];

一个首要的是一个数组无论元件是什么类型。采用指针*后,我们知道一个数据类型为int数组的指针。

  INT(* A)[N];

通过应用括号,指针*在这种情况下,更高的precedence在[]数组。那么A首先是一个指针不管它指向。应用[]数组后,我们知道是一个指向一个int数组。

 为int *(A [N]);

括号不会改变任何precedence秩序,影响[]数组,因此去掉括号将一代产量为int * A [N] 与您的第一次案例。

 是数组指针?

没有。数组是分配内存池和存储数据的地方依次为指针指向一个特定的指数在存储库和引用存储在该存储单元中的数据的一个数据结构。

I was programming a code in C++ when I accidentally put brackets to my pointer and my programs output changed.

Since I am new to programming I wanted to know the difference between these type of pointers:

int* A[n]; 
int (*A)[n];
int *(A[n]);

I have read in my textbook that arrays are also a type of pointers.

解决方案

int* A[n];

A first and foremost is an array no matter what type the element is. After applying pointer *, we know A is an array of int pointers.

int (*A)[n];

By applying brackets, pointer * has higher precedence over array [] in this case. Then A is first and foremost a pointer no matter what it is pointing to. After applying array [], we know A is a pointer to an array of int.

int *(A[n]);

Brackets won't change any precedence order that would affect the array [], therefore removing brackets would yeild int* A[n] same as your 1st case.

Are array pointers?

No. Array is a datastructure that allocates memory pool and stores the data sequentially where as Pointer points to a particular index in memory pool and references the data stored at that memory location.

这篇关于这些是什么类型的指针之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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