Question 1
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 bit
arr++;
printf("%u", arr);
return 0;
}
2002
2004
2020
invalid Operation with array address
Question 2
#include <stdio.h>
int main()
{
int arr[5];
// Assume base address of arr is 2000 and size of integer is 32 bit
printf("%u %u", arr + 1, &arr + 1);
return 0;
}
Question 3
What is the output for a 64-bit Compiler?
# 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;
}
1, 2, 3, 4, 5, 6, 7, 8
Compiler Error
1 2
Run Time Error
Question 4
#include<stdio.h>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6};
int *ptr = (int*)(&a+1);
printf("%d ", *(ptr-1) );
return 0;
}
Question 5
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
only (i)
only (ii)
either (i) or (ii) but not both
neither (i) nor (ii)
Question 6
int *A [10], B[10][10];
Question 7
char a[100][100];
Question 8
#include <stdio.h>
#define SIZE(arr) sizeof(arr) / sizeof(*arr);
void fun(int* arr, int n)
{
int i;
*arr += *(arr + n - 1) += 10;
}
void printArr(int* arr, int n)
{
int i;
for(i = 0; i < n; ++i)
printf("%d ", arr[i]);
}
int main()
{
int arr[] = {10, 20, 30};
int size = SIZE(arr);
fun(arr, size);
printArr(arr, size);
return 0;
}
Question 9
int main()
{
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
Question 10
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;
}
Compiler Error: Array index out of bound.
The always prints 0 five times followed by garbage value
The program always crashes.
The program may print 0 five times followed by garbage value, or may crash if address (arr+5) is invalid.
There are 37 questions to complete.