CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
Difference between arrays and pointers?


Category C Interview Questions
Rating (0.0) By 0 users
Added on 7/19/2006
Views 2997
Rate it!
Answers:

To access data using pointers we use the *.

to access data stored in array we use indexes such as a[0].



Array is a variable, which is a collection of similar data types.
int a[5]; refer to a collection of 5 integers.

Pointer is a variable which is capable to hold an address of a variable.


a[0] == *(a+0);



 Posted by: Syed Baseer Ahmed    

Contact Syed Baseer Ahmed  Contact Syed Baseer Ahmed

It is difficult to pass arrays as arguments in functions but it is possible to pass pointers as arguments in functions



 Posted by: ahona mitra    

Contact ahona mitra  Contact ahona mitra

array is used for static memory allocation whereas pointer is used for dynamic memory allocation.

pointers points to the value stored at a particular address whereas like array[10] has 10 values stored consequently in addresses.
Initialisation of size of array while declaring its datatype is necessary but declaring while initialing is not necessary for pointers



 Posted by: JAYA GOYAL    

Contact JAYA GOYAL  Contact JAYA GOYAL

pointers are mainly used when we need to do address manipulation.
int *p , a[10];
++p or p++ is valid but a++ or --a is not valid.
secondly pointers can be used for dynamic memory allocation unlike arrays which need the help of structure.
thirdly compilers adot pointer notation internally even if we use arrays in program.



 Posted by: Retheesh G    

Contact Retheesh G  Contact Retheesh G

Array is an finite collection of similar data type.Which stores in the adjacent memory.
Eg:
int a[20].
Explanation:
This array carries 20 integer values.It occupies 40 bytes continuously.

Pointer is used to find the value of an address location.
Eg:
int *a;
Explanation:
In this the pointer variable 'a' have any address.If we declared that the variable pointer variable it stores value of that particular variable.



 Posted by: kumaresh    

Contact kumaresh  Contact kumaresh

in more easy words pointers addresses the first element in an array moreover using this pointer we can declare an array (dynamic memory allocation) and can access the elements by manipulating the address pointer(*p) like ++p,p++ or --p,p--. But in an array all the elements has an associated index through which we can access the particular elements.

Eg:
___________________________
| 10 | 20 | 30 | 40 | 50 |
---------------------------
[0] [1] [2] [3] [4]
---------------------------
given above is a static array with associated indices. the numbers in square brackets ([]) indicates the respective element index.

to access the elements we need to code like -
a[0],a[1],a[2] etc.

but in the case of a pointer (*p)
p will hold the address of the a[0]th element of the array a and we can access the subsequent elements by manipulating this address pointer.

Note: Pointers always hold memory address of variable not their value. i.e. why a pointer is called a memory variable.



 Posted by: Nilotpal    

Contact Nilotpal  Contact Nilotpal

fundamental difference is array is a memory location of similar data types while
pointers are memory addresses (i.e variables of that store address) when arguments are passed to functions as arrays it should be noted that its not the size of the array that is passed or the entire array but the address of the first location of the array. Array name itself can be treated as pointer.



 Posted by: Gaurav Parikh    

Contact Gaurav Parikh  Contact Gaurav Parikh

Array is a single variable to hold the collection of similar types of data.
Pointer is a variable to hold the address of the another variable



 Posted by: sait    

Contact sait  Contact sait

pointer is a variable which holds the address of another variable.
Array is a sequential collection of same data type.
Memory allocation in array is stack memory.
Memory allocation of pointer is heap memory.



 Posted by: uppala mamatha    

Contact uppala mamatha  Contact uppala mamatha


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
What is the purpose of main( ) function?

View Answer
why n++ executes faster than n+1?


View Answer
What is the difference between a string and an array?


View Answer
Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?


View Answer
Can the sizeof operator be used to tell the size of an array passed to a function?


View Answer
Is using exit() the same as using return?


View Answer
Is it possible to execute code even after the program exits the main() function?


View Answer
What is a static function?


View Answer
How do you print an address?


View Answer
What is the difference between NULL and NUL?


View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/6076/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.7