C Array Questions and Answers
Arrays in C language form the foundation of data storage and manipulation. They store multiple values of the same type under a single variable name, allowing efficient data handling. Programming questions and answers related to arrays frequently appear in campus placement exams and coding interviews by TCS, Wipro, and Capgemini. This topic includes C array questions with answers covering array declaration, initialization, multidimensional arrays, and pointer relations. Practicing these problems will enhance your understanding of indexing, memory usage, and algorithm design for real-world applications.
C Array
Showing 10 of
108 questions
71. What value does testarray [2][1][0] in the sample code below contains int testarry [3] [2] [2] ={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
- 5
- 7
- 9
- 11
72. What string does ptr point to in the sample code below ? char *ptr; char mystring [ ] ="abcdefg"; ptr=mystring; ptr+=5;
- fg
- efg
- defg
- cdefg
73. Array name +1 is
- Address of the next array
- Address of the next element
- Address of an Array
- Depends on Array type
74. char ** array[12][12][12] Consider array, defined above. Which one of the following definitions and initializations of p is valid ?
- char ** *p) [12] [12]=array;
- char ****p=array;
- char *(*p) [12] [12]=array;
- const char **p [12] [12]=array
75. Let the base address of the character array arr[50][50][50] is 2000, what will be the address of arr[20][25][30] if the array is represented in row-major format.
- 53280
- 104500
- 54560
- 104560
76. Int a[8] = [0, 1, 2, 3]; The definition of a above explicitly initializes its first four elements. Whch one of the following describes how the compiler treats the remaining four elements ?
- Standard C definesd this particular behavior as implementation-dependent. the compiler writer has the freedom to decide how the remaining elements will be handled.
- The remaining elements are initialized to zero(0)
- it is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized.
- As with an enum, the compiler assigns values the last explicitly initialized element. the final four elementsl will acquire the values 4, 5, 6, and 7, respeveively.
77. Which of the following is the correct way to increment the variable "ptr"? void *ptr; struct mystruct myArray[10]; ptr = myArray;
- ptr=ptr + sizeof (myStruct);
- ++(int*)ptr;
- ptr=ptr + sizeof(my Array);
- ptr= ptr+sizeof(ptr);
78. Which one is the difference between an array and list ?
- Array is a data structure where as list is not a data structure.
- In array elements may not be in order but in list the elements should be in order.
- An array consists of similar type of elements where as the list contains difference type of element.
- List is an abstract but array is not an abstract.
79. Which of the following format for a[3]+1
- * (a+3) +1
- * (a+4)
- (*a+3)+1
- *(a[3]+1)
80. What is wrong with the mentioned below code (assuming the call to malloc() does not fall)? char ptr1 [ ]="hellow World"; char *ptr2=malloc (5); ptr2=ptr1;
- There will be a memory overwrite
- There will be a memory leak.
- There will be a segmentation fault.
- Not enough space is allocated by the malloc ()