Showing posts with label Pointers. Show all posts
Showing posts with label Pointers. Show all posts

Pointers

1) int const* p
     const int * p
      both indicates “p” is a pointer that points to a constant integer
      Hence “(*p)++ “ , “(*p)-- “ are not possible

2)
int * const p
    indicates that p is constant pointer and it contains the address of an integer. 
    Hence “p++”, “p --” are not possible

Incrementing and Decrementing Pointers

main()
{
      int *a,*s,i;
      s=a=(int*)malloc(sizeof(int));
      for(i=0;i<4;i++)
             *(a+i)=i*10;
      printf("%d\n",(*++s)++); //Increments address by 4 and then value
      printf("%d\n",(*s)++); //Increments value only
      printf("%d\n",*++s); //Increments address only
      printf("%d\n", ++*s ); //Increments value only
      printf("%d\n",++s++); //Error

}

Pointers


 int a;                                An integer
 int *a;                              A pointer to an integer
 int **a;                            A pointer to a pointer to an integer
 int a[10];                        An array of 10 integers
 int *a[10];                      An array of 10 pointers to integers
 int (*a)[10];                    A pointer to an array of 10 integers
 int (*a)(int);                    A pointer to a function a that takes an integer argument and returns an integer
 int (*a[10])(int);            An array of 10 pointers to functions that take an integer argument and return an integer