

InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
1. |
What will be the output of the program in Turbo-C ? |
Answer» Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the Turbo-C Compiler (under DOS) output. Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better. | |
2. |
What will be the output of the program in Turb C (under DOS)? |
Answer» Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the TurboC Compiler (Windows) output. Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better. | |
3. |
What will be the output of the program if the array begins at address 65486? |
Answer» Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and initialized. Step 2: printf("%u, %u\n", arr, &arr); Here, The base address of the array is 65486. => arr, &arr is pointing to the base address of the array arr. Hence the output of the program is 65486, 65486 | |
4. |
What will be the output of the program if the array begins 1200 in memory? |
Answer» Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array and initialized. Step 2: printf("%u, %u, %u\n", arr, &arr[0], &arr); Here, The base address of the array is 1200. => arr, &arr is pointing to the base address of the array arr. => &arr[0] is pointing to the address of the first element array arr. (ie. base address) Hence the output of the program is 1200, 1200, 1200 | |
5. |
What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes? |
Answer» Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; The array a[3][4] is declared as an integer array having the 3 rows and 4 colums dimensions. Step 2: printf("%u, %u\n", a+1, &a+1); The base address(also the address of the first element) of array is 65472. For a two-dimensional array like a reference to array has type "pointer to array of 4 ints". Therefore, a+1 is pointing to the memory location of first element of the second row in array a. Hence 65472 + (4 ints * 2 bytes) = 65480 Then, &a has type "pointer to array of 3 arrays of 4 ints", totally 12 ints. Therefore, &a+1 denotes "12 ints * 2 bytes * 1 = 24 bytes". Hence, begining address 65472 + 24 = 65496. So, &a+1 = 65496 Hence the output of the program is 65480, 65496 | |
6. |
What will be the output of the program ? |
Answer» Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initialized to a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 . Step 2: int i, j, m; The variable i,j,m are declared as an integer type. Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2 Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3. Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3) Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m Hence the output of the program is 3, 2, 15 | |
7. |
Are the expressions and same for an array of 10 integers? |
Answer» Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints. | |
8. |
A pointer to a block of memory is effectively same as an array |
Answer» Yes, It is possible to allocate a block of memory (of arbitrary size) at run-time, using the standard library's malloc function, and treat it as an array. | |
9. |
Does this mentioning array name gives the base address in all the contexts? |
Answer» No, Mentioning the array name in C or C++ gives the base address in all contexts except one. Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression. When you pass an array name as a function argument, you are passing the "value of the pointer", which means that you are implicitly passing the array by reference, even though all parameters in functions are "call by value". | |
10. |
What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array? |
Answer» If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct answer. But the modern compilers will take care of this kind of errors. Example: Run the below program, it will crash in Windows (TurboC Compiler) #include<stdio.h> int main() { int arr[2]; arr[3]=10; printf("%d",arr[3]); return 0; } Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the Turbo-C Compiler (Windows) output. Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better. | |
11. |
In C, if you pass an array as an argument to a function, what actually gets passed? |
Answer» The statement 'C' is correct. When we pass an array as a funtion argument, the base address of the array will be passed. | |