top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is pointer to array in c?

+2 votes
377 views
What is pointer to array in c?
posted Feb 18, 2015 by Alwaz

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes
 
Best answer

Explanation:
A pointer which holds base address of an array or address of any element of an array is known as pointer to array. For example:

(a)

#include<stdio.h>
int main(){
  int arr[5]={100,200,300};
  int *ptr1=arr;
  char *ptr2=(char *)arr;
  printf("%d   %d",*(ptr1+2),*(ptr2+4));
  return 0;       
}

Output: 300   44

(b)

#include<stdio.h>
int main(){
  static int a=11,b=22,c=33;
  int * arr[5]={&a,&b,&c};
  int const * const *ptr=&arr[1];
  --ptr;
  printf("%d ",**ptr);
  return 0;        
}

Output: 11
answer Feb 19, 2015 by Mohammed Hussain
0 votes
  1. Pointer variable holds address of some data (pointer type should match data type).
  2. An array variable holds the address of the first element of the array.

In effect, pointer to an array of particular type holds the address of the array of the same data type.
For example:

double *p; // Pointer to double data type
double balance[10]; // Array of double data type

p = balance; // Pointer points to the address of first element of the array.
For detailed reference: http://www.tutorialspoint.com/cprogramming/c_pointer_to_an_array.htm

answer Feb 19, 2015 by R.senthil
...