数组名称作为指针

编程入门 行业动态 更新时间:2024-10-18 18:29:10
本文介绍了数组名称作为指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

据我所知,在int arr [10]中,整数数组的名称 " arr" 相当于指向数组第一个元素的指针。但是 " arr" 实际上是一个指针,与int * arr;相同? 我试图修改这个arr以下代码中的东西。海湾合作委员会警告我不相容的指针,我不知道。 ---------------- ----------------------------------------------- #include< stdio.h> void incrementPtr(int **); int main(int argc, char * argv []){ int i; int a [3] = {10,20,30}; incrementPtr(& a); for(i = 0; i< 3; i ++){ printf(" a [% d] =%d \ n",i,*(a + i)); } 返回0; } void incrementPtr(int ** a){ * a ++; } ------------------------------------------------ - 任何人都有任何意见我为什么收到警告?并且 如果a在这段代码中可以修改吗? 谢谢。

解决方案

newgoat写道:据我所知,在int arr [10]中,整数数组的名称arr等同于指向第一个的指针数组的元素。但是arr确实是一个指针,与int * arr;相同。 ? 没有。这个问题太死了,让人觉得鹦鹉看起来很活泼。你是否认为你是第一个有这种想法的人?这是为了避免多次回答我们有这样的问题,我们有一个常见问题解答 < c-faq/>。请在发布之前检查它。 其中,您可能会觉得有趣: < c-faq/aryptr/aryptr2。 HTML>但我听说char a []是与char * a相同的。 < c-faq/aryptr/aryptrequiv html的>那么什么是指C中指针和数组的等价?$ b / b < http:// c-faq。 COM / aryptr / aryptrparam.html>如果它们如此不同,那么 为什么数组和指针声明可以互换为函数 正式参数? [ ...]任何人都有任何意见我为什么得到警告?并且如果a在这段代码中可以修改吗?

一旦你检查了常见问题解答,就像你应该已经完成​​的那样,你就会知道答案是否为。

" Martin Ambuhl" <毫安***** @ earthlink>在留言中写道 新闻:Nf ****************** @ newsread2.news.atl.earth link ...

newgoat写道:

据我所知,在int arr [10]中,整数数组的名称arr等效于指向数组第一个元素的指针。但是arr确实是一个指针,与int * arr;相同。 ?没有。

公平声明。 这个问题已经死了,很无聊让鹦鹉看起来很好看活泼。 ?我承认我现在睡着了,但WTF你忘记了吗? 你认为你是第一个想到这个吗? 敌意。 这是为了避免反复回答我们有这样的事情我们有一个常见问题< http:// c -faq/> ;.请在发布之前检查。其中,您可能会觉得有趣: < c-faq/aryptr/aryptr2.html>但我听说char a []与char * a相同。 < c-faq/aryptr/aryptrequiv.html>那么C中的指针和数组的等价是什么意思? < c-faq/aryptr/aryptrparam.html>如果它们如此不同,那么为什么数组和指针声明可以作为函数形式参数互换? 公平。公平。公平公正。 [...]

任何人都有任何意见我为什么收到警告?并且如果a在这段代码中可以修改吗?一旦你查看常见问题解答......你就会知道答案。

公平。 检查常见问题后,您应该已经完成​​了,

在您告诉他之前,他怎么能知道常见问题?他有先见之明吗?我认为这只是为了上帝。并且,我认为它违反了许多关于 通信理论的法律。 Rod Pemberton

Rod Pemberton写道:

" Martin Ambuhl" <毫安***** @ earthlink>在消息中写道新闻:Nf ****************** @ newsread2.news.atl.earth link ...

newgoat写道:

据我所知,在int arr [10]中,整数数组的名称arr等同于指向数组第一个元素的指针。但是arr确实是一个指针,与int * arr;相同。 ?

没有。

公平的陈述。

这个问题太死了,让人看起来很无聊热闹。

?我承认我现在睡着了,但WTF你忘记了吗?

他假设一个共同的文化遗产极客,每个人都知道 Monty Python的死鹦鹉素描。毫无疑问, 维基百科上有一篇完整的文章: en.wikipedia/wiki/Dead_Parrot 。 我必须说我看过阅读常见问题解答的更友好的用语。 。 S.

As far as I understand, in "int arr[10]", the name of the integer array "arr" is equivalent to the pointer to the first element of the array. But is "arr" really a pointer, identical as "int *arr;" ? I tried to modify this "arr" thing in the following code. GCC warns me of incompatible pointers, which I have no idea of. --------------------------------------------------------------- #include<stdio.h> void incrementPtr(int **); int main(int argc, char *argv[]){ int i; int a[3] = {10, 20, 30}; incrementPtr(&a); for(i = 0; i < 3; i++){ printf("a[%d] = %d\n", i, *(a + i)); } return 0; } void incrementPtr(int **a){ *a++; } ------------------------------------------------- Anyone has any opinion why I got the warning? And if "a" in this code can be modified? Thanks.

解决方案

newgoat wrote:

As far as I understand, in "int arr[10]", the name of the integer array "arr" is equivalent to the pointer to the first element of the array. But is "arr" really a pointer, identical as "int *arr;" ? No. This question is so dead and boring it makes the parrot look lively. Do you imagine you are the first with this thought? It is to avoid repeatedly answering such things that we have a FAQ <c-faq/>. Please check it before posting. Among others, you might find interesting: <c-faq/aryptr/aryptr2.html> But I heard that char a[] was identical to char *a. <c-faq/aryptr/aryptrequiv.html> So what is meant by the ``equivalence of pointers and arrays'''' in C? <c-faq/aryptr/aryptrparam.html> If they''re so different, then why are array and pointer declarations interchangeable as function formal parameters? [...] Anyone has any opinion why I got the warning? And if "a" in this code can be modified?

Once you check the FAQ, as you should have already done, you will know the answer.

"Martin Ambuhl" <ma*****@earthlink> wrote in message news:Nf******************@newsread2.news.atl.earth link...

newgoat wrote:

As far as I understand, in "int arr[10]", the name of the integer array "arr" is equivalent to the pointer to the first element of the array. But is "arr" really a pointer, identical as "int *arr;" ? No.

Fair statement. This question is so dead and boring it makes the parrot look lively. ? I admit I''m asleep right now, but WTF did you forget? Do you imagine you are the first with this thought? Hostility. It is to avoid repeatedly answering such things that we have a FAQ <c-faq/>. Please check it before posting. Among others, you might find interesting: <c-faq/aryptr/aryptr2.html> But I heard that char a[] was identical to char *a. <c-faq/aryptr/aryptrequiv.html> So what is meant by the ``equivalence of pointers and arrays'''' in C? <c-faq/aryptr/aryptrparam.html> If they''re so different, then why are array and pointer declarations interchangeable as function formal parameters? Fair. Fair. Fair and Fair. [...]

Anyone has any opinion why I got the warning? And if "a" in this code can be modified? Once you check the FAQ ... you will know the answer.

Fair. Once you check the FAQ, as you should have already done,

How could he know about the FAQ before you told him? Is he prescient? I thought that was only for God. And, I think it violates a number of laws of communication theory too. Rod Pemberton

Rod Pemberton wrote:

"Martin Ambuhl" <ma*****@earthlink> wrote in message news:Nf******************@newsread2.news.atl.earth link...

newgoat wrote:

As far as I understand, in "int arr[10]", the name of the integer array "arr" is equivalent to the pointer to the first element of the array. But is "arr" really a pointer, identical as "int *arr;" ?

No.

Fair statement.

This question is so dead and boring it makes the parrot look lively.

? I admit I''m asleep right now, but WTF did you forget?

He is assuming a shared cultural heritage of geek, where everybody knows Monty Python''s dead parrot sketch. It should come as no surprise that Wikipedia has a full article on it: en.wikipedia/wiki/Dead_Parrot. I must say I''ve seen kinder wordings of "read the FAQ". S.

更多推荐

数组名称作为指针

本文发布于:2023-07-28 02:33:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1226491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   指针   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!