Re: incrementing a pointer to an array
- From: utab <umut.tabak@xxxxxxxxx>
- Date: Sat, 30 Aug 2008 10:03:10 +0200
On Sat, 30 Aug 2008 07:58:05 +0000, Richard Heathfield wrote:
utab said:
On Fri, 29 Aug 2008 23:29:22 -0700, subramanian100in@xxxxxxxxx, India
wrote:
The following portion is from c-faq.com - comp.lang.c FAQ list ·pointer to int */
Question 6.13
int a1[3] = {0, 1, 2};
int a2[2][3] = {{3, 4, 5}, {6, 7, 8}}; int *ip; /*
int (*ap)[3]; /* pointer to array [3] of int */\The trick is here because you are getting the address of the pointer to
ap = &a1;
the first element, If I am not mistaken...
if you use sizeof on ap you will see that it is associated to the whole
array...8 bytes.
Wrong. ap is a pointer to the first element of the array, but using
sizeof on ap is by no means required to result in 8, and indeed on my
system it does not. Nor need it result in 3*sizeof(int) - and again, on
my system it does not.
#include <stdio.h>
int main(void)
{
int a1[3] = {0, 1, 2};
int (*ap)[3]; /* pointer to array [3] of int */
Hi,
ap = &a1;
Could you clarify this statement for me? is not ap pointer to whole array
of 3?
printf("**ap = %d\n", **ap);not incrementing, dereferencing, sorry
printf("sizeof ap = %d\n", (int)sizeof ap); ap++;
return 0;
}
**ap = 0
sizeof ap = 4
Incrementing this address is undefined.
Why?
<snip>
.
- Follow-Ups:
- Re: incrementing a pointer to an array
- From: Richard Heathfield
- Re: incrementing a pointer to an array
- References:
- incrementing a pointer to an array
- From: subramanian100in@xxxxxxxxx, India
- incrementing a pointer to an array
- Prev by Date: Re: incrementing a pointer to an array
- Next by Date: Re: incrementing a pointer to an array
- Previous by thread: Re: incrementing a pointer to an array
- Next by thread: Re: incrementing a pointer to an array
- Index(es):
Relevant Pages
|