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

问题描述

限时删除!!

我在C ++中编程代码,当我不小心把方括号放在我的指针和我的程序输出改变了。

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是一个int指针数组。

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];

通过使用括号,指针*在这种情况下优先于数组[]。然后A首先是一个指针,无论它指向什么。在应用array []之后,我们知道A是一个int数组的指针。

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]);

括号不会更改会影响数组[]的任何优先级顺序, 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?

否。数组是一种数据结构,它分配内存池,并在Pointer指向内存池中的特定索引并引用存储在该内存位置的数据时顺序存储数据。

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.

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

1403页,肝出来的..

09-06 08:32