*********************************************************************** *********************** ARRAYS

******************************

*********************************************************************** 1] What would the output of the following program? main() { char a[] = "Visual C++"; char *b = "Visual C++"; printf("\n %d %d",sizeof(a),sizeof(b)); printf("\n %d %d",sizeof(*a),sizeof(*b)); } 2] For the following statements would arr[3] and ptr[3] fetch the same cha racter? <Yes / No> char arr[] = "Surprised"; char *ptr = "surprised"; 3] For the statements in 9.2 does the compiler fetch the character arr[3] and ptr[3] in the same manner? 4] What would be the output of the following program, if the array begins at address 1200? main() { int arr[] = {2,3,4,1,6}; printf("%d %d",arr, sizeof(arr)); } 5] exts? Does mentioning the array name gives the base address in all the cont

6] What would be the output of the following prograam, if the aray begins at address 65486 ? main() { int arr[] = {12,14,15,23,45}; printf("%u %u",arr, &arr); } 7] ? Are the expressions arr and &arr same for an array of 10 integers

8] What would be the output of the following prograam, if the aray begins at address 65486 ?

4.14.2.arr + 1.6.4. &arr + 1).23.2.3. / False> 13] What would be the output of the following program if the array begins a t 65472? main() { int a[3][4] = { 1.8. b = "Sunstroke". 15] If we pass the name of a 1-D int array to a function it decays into a p ointer to an int. 7.sizeof(a) / sizeof(a[0])). char *p = "Coldwave".7}. printf("\n %d".main() { int arr[] = {12. } 14] What does the follwoing declaration mean: int(*ptr)[10].4. } 12] <True A pointer to a block of memory is effectively same as an array. printf("\n %s %s".1.a + 1.2. a = "Coldwave". If we pass the name of a 2-D array of integers to a fu nction what would it decay into ? .15.3.5. } 9] ? 10] When are 'char a[]' and 'char *a' treated as same by the compiler Would the following program compile successfully ? main() { char a[] = "Sunstroke".9.p). printf("%u %u".a. &a + 1). } 11] What would be the output of the following program ? main() { float a[] = {12.45}.4.0 }.3. printf("\n %u %u".

When it sees the expr ession ptr[3] it generates the code to start at location stored in ptr.8.3.4. fun(&ptr). 17] What would be the output of the following program ? main() { int a[3][4] = { 1. int *ptr. add three to the pointer.2. In other words. move past it.16] How would you define the function f() in the following program? int arr[MAXROW][MAXCOL].9. fun(arr). whereas ptr[3] is three places past the object pointed to by ptr.0 }. } fun(int **p) { printf("\n %d".3. arr[3] is three places past the start of the o bject named arr. and finally fetch the character pointed to. ptr = &a[0][0].**p). 7. and fetch the character there. 4] 5] 1200 10 No. } *********************************************************************** ************************* ANSWERS **************************** *********************************************************************** 1] 11 2 1 1 Yes 2] 3] No. 4. Whenever mentioning the array name gives its base address . For arr[3] the compiler generates code to start at location arr.8.2.

8] 9] 10] . It decays into a pointer to an array and not a pointer to a fun(int a[][MAXCOL]) { } OR fun(int (*ptr)[MAXCOL]) /* ptr is pointer to an array */ { } pointer. ke place in two situations: ----6] This decaying doesn't ta When array name is used with sizeof operator. No. When the array name is an operand of the & operator.it is said that the array has decayed into a pointer. 11] 12] 13] 14] 15] 16] 65488 65496 When using them as formal parameters while defining a function. 'arr' gives the address of the first 'int' whereas '&ar r' gives the address of array of 'ints'. 65486 65486 7] No. Since these addresses happen to be same the results of the expressions are same. Even though both may give the same addresses as in (6) they mea n two different things. because we may assign a new string ot a pointer but not to an array 4 True 65480 65496 'ptr' is a pointer to an array of 10 integers. 17] 1 .

Sign up to vote on this title
UsefulNot useful