I'm not sure of if I understand your question, but if you increment your pointer by one you will have it pointing towards the next element, example:
Code:
#include <stdio.h>
int
main (int argc, char **argv)
{
int array[] = {1,2,3};
int *p;
p = array; /* point p towards the first element */
(*p)++; /* increment value pointed to by p by 1 */
p++; /* increment pointer by one, making it point to the next element in array[] */
printf ("p = %p, *p = %d\n\n", p, *p);
printf ("[%p] array[%d] = %d\n", &(array[0]), 0, array[0]);
printf ("[%p] array[%d] = %d\n", &(array[1]), 1, array[1]);
printf ("[%p] array[%d] = %d\n", &(array[2]), 2, array[2]);
return 0;
}
inside the square-brackets you will have the address of values. You will see that the address which p is pointing towards will be the same as the address of array[1].
(The address-of operator '&' is exactly what it says it is - an operator the get the address of some variable:
Code:
int x = 5;
printf("addr: %p value: %d\n", &x, x);
Originally Posted by
pawanspace
Also the example I have given is used when We want to have an two dimensional array, but we don't need to have all the rows the same length. Is this the way to use it?
To me that sounds like bad coding or bad problem-solving, and in terms of memory there are no rows (etc).
If you think that it will be easier to manage your linear array of numbers by treating it as a matrix with rows and cols that is up to you, but I wouldn't write my code like that.