Interview Questions   Tutorials   Discussions   Programs   

C - Difference between arrays and pointers?




332
views
asked marvit August 18, 2014 10:05 AM  

Difference between arrays and pointers?


           

1 Answers



 
answered By bhjahnavi   0  
Most of the time, pointer and array accesses can be treated as acting the same, the major exceptions being:
1) the sizeof operator
 sizeof(array) returns the amount of memory used by all elements in array
 sizeof(pointer) only returns the amount of memory used by the pointer variable itself
2) the & operator
 &array returns the address of the first element in array
 &pointer returns the address of pointer
3) a string literal initialization of a character array
 char array[] = “abc” sets the first four elements in array to ‘a’, ‘b’, ‘c’, and ‘\0′
 char *pointer = “abc” sets pointer to the address of the “abc” string (which may be stored in read-only memory and thus unchangeable)
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert