i'm trying to print the elements of my array but am getting 4210784 as the result can someone tell me where i'm going wrong with this and what is actual happening.
Code:
#include <stdio.h>
int ray[100];
main()
{
printf("%i\n",(ray));
getchar();
};
Printable View
i'm trying to print the elements of my array but am getting 4210784 as the result can someone tell me where i'm going wrong with this and what is actual happening.
Code:
#include <stdio.h>
int ray[100];
main()
{
printf("%i\n",(ray));
getchar();
};
element that is located at index ind can be retreived as
ray[ind]
ray itself is just a pointer, so printing it value you get some random address used to store the array
so to print the elements of the array would i have to say print from 0 to 99
yes you need a loop
KurtCode:int ray[100];
int i;
for ( i = 0; i < 100; ++i )
printf("%d\n", ray[i]);
you have to use loop (for will be good here)Quote:
Originally Posted by c_programmer
Inside the loop you will print one element on each iteration
right tanks
Make sure that u perform a boundary check (like what ZUK has done ). Because C dosn;t do boundary it. If it goes beyond the size of an array "Segmentation fault" would be the result
ssharish2005