pointers for getting elements of an array in C
Posted
by
Manolo
on Stack Overflow
See other posts from Stack Overflow
or by Manolo
Published on 2012-12-13T04:37:08Z
Indexed on
2012/12/13
5:03 UTC
Read the original article
Hit count: 151
I am a newbie in C and I would like to get the elements of an array with a function, I have tried different options, but I still do not get the elements. My function is:
void getelements(int *a, int cl)
{
int *p;
for (p=&a[0];p<&a[cl];p++)
{
printf("%d\n",*p);
}
}
I know that the solution should work like that, but it only prints the first element and then memory positions. I am calling my function with:
int v={10,12,20,34,45};
getelements(&v,5);
Any help? I need to use arithmetic of pointers. Thanks
© Stack Overflow or respective owner