InterviewSolution
| 1. |
Are The Following Two Statements Identical? Char Str[6] = Kicit ; Char *str = Kicit ; |
|
Answer» No, Arrays are not pointers. An array is a single, pre-allocated chunk of contiguous elements (all of the same type), FIXED in size and location. A pointer on the other hand, is a reference to any data element (of a particular type) located anywhere. A pointer must be assigned to point to space allocated elsewhere, but it can be REASSIGNED any TIME. The array declaration char str [6]; requests that space for 6 characters be set aside, to be KNOWN by name str. In other WORDS there is a location named str at which six characters are stored. The pointer declaration char *str ; on the other hand, requests a place that holds a pointer, to be known by the name str. This pointer can point almost anywhere to any char, to any contiguous array of chars, or nowhere. No, Arrays are not pointers. An array is a single, pre-allocated chunk of contiguous elements (all of the same type), fixed in size and location. A pointer on the other hand, is a reference to any data element (of a particular type) located anywhere. A pointer must be assigned to point to space allocated elsewhere, but it can be reassigned any time. The array declaration char str [6]; requests that space for 6 characters be set aside, to be known by name str. In other words there is a location named str at which six characters are stored. The pointer declaration char *str ; on the other hand, requests a place that holds a pointer, to be known by the name str. This pointer can point almost anywhere to any char, to any contiguous array of chars, or nowhere. |
|