Final Exam
Final Exam
Final Exam
************************************************
" Try Solving the Exam Quesions on your own. If required, you can always come here,
and take help (as and when required)! ~ TSG405"
***********************************************************************************
************************************************
------------------------------------------------------------------------
/*/*/*/*/* F.I.N.A.L E.X.A.M
*/*/*/*/*/
------------------------------------------------------------------------
------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
1. Who invented the C language?
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
2. When you compile a correct C program you get a machine executable file such as
a.out produced by the gnu compiler gcc.
Ans. True
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
3. Which is true:
Ans. 1, 3, 4
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
4. The statement -- printf(“HELLO\t\tWORLD\n”);
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
6. In a format string for printf which would you use to print an int?
Ans. %d
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
7. The code
>>
i = -10;
while ( i < 0)
{ … do something ; i--; }
**--Displays a common error--**
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
8. The following program is suppose to write Hello World onto the screen but it has
syntax errors - find
and correct.
>>
#include <stdio.h>
int main(void)
{
printf(“ Hello World\n”);
return 0,
}
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
9. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';
Expression: a % b
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
10. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';
Expression: b % a
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
11. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';
Expression: a < b
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
12. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
13. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';
Expression: a / b > c
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
14. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';
Expression: c = a++
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
15. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;
Expression: a - b * c
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
16. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;
Expression: c / a * b
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
17. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
18. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;
Expression: b = a = c
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
19. Assume the given declarations and fill in the value of the expression .
int i = 0, j = 1, k = 2;
Expression: i && j
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
20. Assume the given declarations and fill in the value of the expression .
int i = 0, j = 1, k = 2;
Expression: !!i
Ans. Enter answer here -- 0
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
21. Assume the given declarations and fill in the value of the expression .
int i = 0, j = 1, k = 2;
Expression: i || !k
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
22. Assume the given declarations and fill in the value of the expression.
int i = 0, j = 1, k = 2;
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
23. If a function’s declaration is int foo(void):
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
24. In ANSI standard C(1989) code - this is what we are teaching- declarations can
occur in a for statement as in :
>>
for(int i; i < 10; i++0 …
Ans. False
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
25. What happens when the return statement has a double expression and the function
return type is int?
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
26. With the code :
>>
int foobar(int* n){
*n = *n +1;
return *n;
}
when called:
>>
int k = 6;
printf("foobar(k) = %d,",foobar(&k) );
printf(" k = %d\n", k);
what gets printed?
Ans. foobar(k) = 7, k = 7
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
27. A variable declared in a inner block that has the same name as one in the
surrounding block causes an error.
Ans. False
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
28. The original intent of using register int i;
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
29. When declaring fact() why not use double fact() so that you do not have integer
overflow?
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
30. Factorial can only be computed recursively.
Ans. False
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
31. The function mystery is defined as
>>
int mystery(int p, int q)
{
int r;
if ((r = p % q) == 0)
return q;
else return mystery(q, r);
}
Ans. 2
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
32. The function mystery is defined as
>>
int mystery(int p, int q)
{
int r;
if ((r = p % q) == 0)
return q;
else return mystery(q, r);
}
Ans. 7
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
33. A while can always be used to replace a for.
Ans. True
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
34. An if-else statement can always replace an if statement.
Ans. True
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
35. If you declare the array char mystr[10];
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
36. In the following code fragment what gets printed?
>>
int data[5] = {0 ,1, 2, 3, 4}, sum = 0 , i;
Ans. 10
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
37. In the following code fragment
>>
int a[10] = {1,2,3,4,5,6,7,8,9,10}, i = 6 ;
int *p = &a[0];
printf(“%d\n”, *(p + i));
Ans. 7
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
38. The declaration char* str = & a[0]; where char a[5] = “abcd”;
The value of *str is the char ‘a’;
Ans. True
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
39. The input function scanf() uses “call by reference” to pass in argument values.
Ans. True
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
40. Mergesort is less efficient than bubblesort for very large sorting problems.
Ans. False
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
41. if p and q are pointers to double and x and y are double which of the following
is legal:
Ans. y = *q;
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
~ TSG405, 2021