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. |
#include<stdio.h>int main(){int a[10][20][30] = {0};a[5][2][1] = 2;return 0;}Which of the following will print the value 2 for the above code?(A) printf(“%d”,*(((a+5)+2)+1));(B) printf(“%d”,***((a+5)+2)+1);(C) printf(“%d”,*(*(*(a+5)+2)+1));(D) None of these |
| Answer» | |
| 2. |
What is output?# include <stdio.h>void print(int arr[]){int n = sizeof(arr)/sizeof(arr[0]);int i;for (i = 0; i < n; i++)printf("%d ", arr[i]);}int main(){int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};print(arr);return 0;}(A) 1, 2, 3, 4, 5, 6, 7, 8(B) Compiler Error(C) 1 2(D) Run Time Error |
| Answer» | |
| 3. |
Predict the output of below program:#include <stdio.h>int main(){int arr[5];// Assume that base address of arr is 2000 and size of integer// is 32 bitarr++;printf("%u", arr);return 0;}(A) 2002(B) 2004(C) 2020(D) lvalue required |
| Answer» | |
| 4. |
#include <stdio.h>int main(){int a[][] = {{1,2},{3,4}};int i, j;for (i = 0; i < 2; i++)for (j = 0; j < 2; j++)printf("%d ", a[i][j]);return 0;}(A) 1 2 3 4(B) Compiler Error in line ” int a[][] = {{1,2},{3,4}};”(C) 4 garbage values(D) 4 3 2 1 |
| Answer» | |
| 5. |
Does C perform array out of bound checking? What is the output of the following program?int main(){int i;int arr[5] = {0};for (i = 0; i <= 5; i++)printf("%d ", arr[i]);return 0;}(A) Compiler Error: Array index out of bound.(B) The always prints 0 five times followed by garbage value(C) The program always crashes.(D) The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid. |
| Answer» | |
| 6. |
#include <stdio.h>int main(){char p;char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8};p = (buf + 1)[5];printf("%d\n", p);return 0;}(A) 5(B) 6(C) 9(D) None of the above |
| Answer» | |
| 7. |
Predict output of following programint main(){int i;int arr[5] = {1};for (i = 0; i < 5; i++)printf("%d ", arr[i]);return 0;}(A) 1 followed by four garbage values(B) 1 0 0 0 0(C) 1 1 1 1 1(D) 0 0 0 0 0 |
| Answer» None | |
| 8. |
Assume the following C variable declarationint *A [10], B[10][10];Of the following expressionsI A[2]II A[2][3]III B[1]IV B[2][3]which will not give compile-time errors if used as left hand sides of assignment statements in a C program (GATE CS 2003)?(A) I, II, and IV only(B) II, III, and IV only(C) II and IV only(D) IV only |
| Answer» None | |
| 9. |
Output of following program?#include<stdio.h>int main(){int a[] = {1, 2, 3, 4, 5, 6};int *ptr = (int*)(&a+1);printf("%d ", *(ptr-1) );return 0;}(A) 1(B) 2(C) 6(D) Runtime Error |
| Answer» | |
| 10. |
Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n + m] be another integer array.void xyz(int a[], int b [], int c[]){int i, j, k;i = j = k = O;while ((i<n) && (j<m))if (a[i] < b[j]) c[k++] = a[i++];else c[k++] = b[j++];}Which of the following condition(s) hold(s) after the termination of the while loop? (GATE CS 2006)(i) j < m, k = n+j-1, and a[n-1] < b[j] if i = n(ii) i < n, k = m+i-1, and b[m-1] <= a[i] if j = m(A) only (i)(B) only (ii)(C) either (i) or (ii) but not both(D) neither (i) nor (ii) |
| Answer» | |