wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C String Array MCQs

Total questions: 10

Worksheet time: 20mins

Name
Class
Date
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; }
a)
2002
b)
2004
c)
2020
d)
Lvalue Error
e)
None
2.
# 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
b)
1 2 3 4 5 6 7 8
c)
Compiler Error
d)
1 2 3
e)
None
3.
Predict output of following program int main() { int i; int arr[5] = {1}; for (i = 0; i < 5; i++) printf("%d ", arr[i]); return 0; }
a)
1 0 0 0 0
b)
1 1 1 1 1
c)
1 Followed by garbage values
d)
0 0 0 0 0
e)
Compiler Error
4.
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
e)
None
5.
# include <stdio.h> int main() { char str1[] = "HelloWorld"; char str2[] = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l','d'}; int n1 = sizeof(str1)/sizeof(str1[0]); int n2 = sizeof(str2)/sizeof(str2[0]); printf("n1 = %d, n2 = %d", n1, n2); return 0; }
a)
n1=11,n2=10
b)
n1=10,n2=11
c)
n1=9,n2=11
d)
n1=9,n2=10
e)
None
6.
#include<stdio.h> int main() { char str[20] = "Helloworld"; printf ("%d", sizeof(str)); return 0; }
a)
9
b)
11
c)
20
d)
Garbage value
e)
Error
7.
Output of following program? #include <stdio.h> int main() { int i = 5; printf("%d %d %d", i++, i++, i++); return 0; }
a)
7 6 5
b)
5 6 7
c)
7 7 7
d)
Compiler Dependent
e)
None
8.
#include <stdio.h> int main() { printf("%d", main); return 0; }
a)
Address of main function
b)
Compile Error
c)
Runtime Error
d)
Some random value
e)
None
9.
What is the result of Right Shift Operator >> on (00110000>>2)
a)
11000000
b)
1100
c)
11001111
d)
1100000
e)
None
10.
What is the size of the below C structure in TurboC? int main() { struct books{ int pages; char str[4]; }b; printf("%d",sizeof(b)); return 0; }
a)
6
b)
5
c)
8
d)
7
e)
None