Sunday, July 12, 2009

How to declare pointer to an array in C programming?

I am writting a program for a class and my tutor says that declaring a pointer to an array will make the program run better. How do I do this?

How to declare pointer to an array in C programming?
%26gt; I am writting a program for a class and my tutor says that declaring a pointer to an array will make the program run better.


You haven’t told me the context of the code, but I get a bad feeling with such a statement? Pointers make your program run better? What kind of statement is that?





I recommend you read up your book on pointer notation. No book? See http://www.cprogramming.com/tutorial/c/l...
Reply:myFunction(int someArray[]) {


int *arrayPtr = %26amp;someArray[0];
Reply:assuming your array is an integer array





int *pointer;


int int my_array[] = {1,2,3,4,5,6};


pointer = %26amp;my_array[0];





Which means, make an integer pointer. Make an integer array. Point the pointer to the address of the first item in the array.
Reply:From the very little C knowledge I have, you point to the first item in the array.


No comments:

Post a Comment