Quiz Test | Computer Programming | Sec- A, B, C, D | 2 nd Sem | Winter 2019-20 | Max Marks = 20| Time: 1 Hr
Name: Adm. Number: Sec:
A. Multiple Choice Questions: Write the most appropriate choice in the space provided. Any overwriting will
attract zero credit. Consider that each program segment has appropriate head er files. [ 1 10=10 ]
1. What is the output of the following C code? [ ]
int main( ) {
int i = 1 ;
while(++i<= 5) printf("%d ", i++) ;
return 0 ; }
(A) 2 4 (B) 1 3 5 (C) 2 3 4 (D) 1 4
2. The output of the following C code prints as: (Hint: The ASCII value of character „a‟ is 97.) [ ]
int main( ) {
float x = 'y' ;
printf("%f ", x) ;
return 0 ; }
(A) 97.000000 (B) 120.000000 (C) 121.000000 (D) 122.000000
3. The output of the following C code is: [ ]
int main( ) {
signed char chr ;
chr = 120 ;
printf("%c\n", chr) ;
return 0 ; }
(A) 120 (B) -120 (C) x (D) Error
4. Which of the following is a valid variable name declaration? [ ]
(A) int_a3 (B) int a_3 (C) int 3_a (D) int 3a
5. The output of the following C code is [ ]
int main( ) {
int x = 2, y = 5 ;
(x& y) ? printf("A ") : printf("B ") ;
(x&& y) ? printf("C ") : printf("D ") ;
return 0 ; }
(A) A C (B) B D (C) A D (D) B C
6. The output of the following C code is: [ ]
int main( ) {
int i = 10 ;
i = !i>14 ;
printf("%d", i) ;
return 0 ; }
(A) 10 (B) 0 (C) 14 (D) None of these
7. The output of the following C code is: [ ]
int main( ) {
int x = 5 ;
printf (“%d %d %d\n”, x, x<<2, x>>2) ;
return 0 ; }
(A) 5 20 2 (B) 20 20 1 (C) 5 20 1 (D) 5 5 1
8. The output of the following C code is: [ ]
int main( ) {
int a=5, b=10, c=15 ;
int choice ;
choice = a>b && a>c? a: (b > c? b: c) ;
printf("%d", choice) ;
return 0 ; }
(A) 5 (B) 15 (C) 10 (D) 0
9. The output of the following C code is: (Hint: 0x is the symbol to represent hexadecimal number.) [ ]
int main( ) {
if (7 & 8)
printf("Honesty") ;
if ((~7 & 0x000f) == 8)
printf("is the best policy \n") ;
return 0 ; }
(A) Honesty is the best policy (B) Honesty (C) is the best policy (D) No Output
10. Which operators perform operation on data in binary level? [ ]
(A) Logical Operators (B) Bitwise Operators (C) Relational Operators (D) None of these
B. Answer the following questions: Write the appropriate answer in the space provided. Any overwriting will
attract zero credit. Consider that each program segment has appropriate header files. [ 1 10=10 ]
1. int main( ) {
unsigned int num = 4 ; The output of the C program is:
int i ;
for( i=0; i<16; i++)
printf("%d", (num<< i & 1<<15)? 1 : 0) ;
return 0 ; }
2. int main( ) {
int a = 1 ; The output of the C program is:
while(a<=1)
if(a%2)
printf("%d, ", a++) ;
printf("%d", a+10) ;
return 0 ; }
3. int main( ) {
The output of the C program is:
printf("%d", printf ("%d", printf ("%d", printf ("%s", "IIT")))) ;
return 0 ; }
4. int main( ) {
int n = 4, i, j, k, t ;
for(i = 1; i <= n – 1; i++)
{ The output of the C program is:
for(j = 1; j <= i; j++)
printf("%2d", i%10 ) ;
for(k = 1; k <=2*n-2*i-1 ; k++)
printf ("%2c", 32) ;
for(t = 1; t <= i; t++)
printf("%2d", t%10) ;
printf(" \n") ; }
for(i = 1 ; i <= 2*n-1 ; i++)
printf("%2d", n) ;
return 0 ; }
5. int main( ) {
int i = 1 ;
switch( i ) The output of the C program is:
{
printf (" My City is ") ;
case 1 : printf ("Kolkata") ; break ;
case 2 : printf ("Mumbai") ; break ;
default : printf ("None of these") ;
}
return 0 ; }
6. char str1[ ] = "IITISM" ;
What does the fragment of C-program
char str2[ ] = {'C', 'S', 'E', 'D', 'E', 'P', 'A', 'R', 'T', 'M','E','N','T'} ;
print?
int n1 = sizeof(str1)/sizeof(str1[0]) ;
int n2 = sizeof(str2)/sizeof(str2[0]) ;
printf("n1 = %d, n2 = %d", n1, n2) ;
7. char s[11] = "Computer" ;
int i = 0 ; What does the fragment of C-program
int count = 0 ; print?
while(i<11) {
if(s[i]=='a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'u' || s[i] == 'o')
count ++ ;
i++; }
printf("Count = %d", count) ;
8. char mystr[ ] = "This is the first quiz of C programming" ; The output of this C code fragment is:
printf ("%s", strcpy(mystr, "IITISM")) ;
9. int a[ ] = {22, 19, 17, 36, 12, 15, 28, 35, 66, 43} ;
int i, j, n = sizeof(a)/sizeof(int) ;
for(i = 0; i < n; ++i)
for(j = 0; j < i; ++j) The output of the C program fragment is:
if (a[i] > a[j]) {
a[i] = a[i] + a[j] ;
a[j] = a[i] - a[j] ;
a[i] = a[i] - a[j] ;
}
for(i = 0; i < n; ++i)
printf("%2d", a[i]) ;
10. int main( ){
int i, j, temp, size = 7 ;
int arr[7]={1, 3, 6, 9, 11, 22, 5} ; The output of the C program is:
for(i=0, j=size-1; i<(size/2); i++, j--)
{
temp = arr[i] ;
arr[i] =arr[j] ;
arr[j] = temp ;
}
for(i=0; i<size; i++)
printf("%d\n",arr[i]) ;
return 0; }
-END-
Rough Work