Qualcomm Interview Question
Software Engineer / DevelopersArray is a pointer to const by default
Say : char a[10]; is considered as const char *. so we can not change a pointer a to any other array or pointer but we can point multiple pointers to this array.
const int * B ----> means contents pointed by B is constant....the pointer B can point to any address....
int const * B ----> means pointer B is const i.e its address is constant but u can change the contents stored in that address....
From the website: c-faq dot com/aryptr/practdiff dot html
An array is a single, preallocated chunk of contiguous elements (all of the same type), fixed in size and location. A pointer is a reference to any data element (of a particular type) anywhere. A pointer must be assigned to point to space allocated elsewhere, but it can be reassigned (and the space, if derived from malloc, can be resized) at any time. A pointer can point to an array, and can simulate (along with malloc) a dynamically allocated array, but a pointer is a much more general data structure (see also question 4.1).
Array is a collection of similar type of data items and each item is called element of an array.
each element will share the same variable name but have different index.
eg:
int age[50];
float sal[20];
pointer is a variable that stores the memory address.Its called as pointer because it points to a particular address in memory by storing that address.
int *ptr;
int age=30;
ptr=&age;
Difference bw array and pointer is :
**Compiler allocate resource for array at compile time but compiler allocate resource for pointer at execution time.
** Array is a group of element but pointer point to the memory location of variable.
** Pointer are dynamic nature once memory are initialized it can be free or re-sized but for array once memory initialized it can not be free or re-sized.
www dot cplusplus dot com/forum/articles/9/
- vips December 25, 2011This is the best description