Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Final Exam

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 9

***********************************************************************************

************************************************
" 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?

Ans. Dennis Ritchie invented C at Bell Labs


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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:

1 - #define is a preprocessor command often used to introduce named


constants
2 - double and goto are keywords declaring types.
3 - return (0); is normally the last statement in main()
4 - The file stdio.h is where the compiler finds scanf().

Ans. 1, 3, 4
-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
4. The statement -- printf(“HELLO\t\tWORLD\n”);

Ans. Prints HELLO WORLD followed by a new line


-----------------------------------------------------------------------------------
---------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------------------------
5. The expression PI * radius * radius would be used to compute

Ans. A circle's area


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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--**

Ans. Its an infinite loop


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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,
}

Ans. It should be 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

Ans. Enter answer here -- 3


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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

Ans. Enter answer here -- 1


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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

Ans. Enter answer here -- 1


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
12. Assume the given declarations and fill in the value of the expression .
int a = 3, b = 4, c = 0, d = '1';

Expression: c < b && a > 3

Ans. Enter answer here -- 0


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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

Ans. Enter answer here -- 0


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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++

Ans. Enter answer here -- 3


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
15. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;

Expression: a - b * c

Ans. Enter answer here -- (-5)


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
16. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;

Expression: c / a * b

Ans. Enter answer here -- 6


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
17. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;

Expression: a++ + --b

Ans. Enter answer here -- 2


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
18. Assume the given declarations and fill in the value of the expression .
int a = 1, b = 2, c = 3;

Expression: b = a = c

Ans. Enter answer here -- 3


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
19. Assume the given declarations and fill in the value of the expression .
int i = 0, j = 1, k = 2;

Expression: i && j

Ans. Enter answer here -- 0


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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

Ans. Enter answer here 0


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
22. Assume the given declarations and fill in the value of the expression.
int i = 0, j = 1, k = 2;

Expression: (i && (j = k)) || (k > j)

Ans. Enter answer here -- 1


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
23. If a function’s declaration is int foo(void):

Ans. The function has no arguments


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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?

Ans. There is a conversion from double to 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;

Ans. It was intended to compile optimized code


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
29. When declaring fact() why not use double fact() so that you do not have integer
overflow?

Ans. There would be problems with accuracy


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
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);
}

When called with mystery(2, 6) it will return:

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);
}

When called with mystery(7, 91) it will return:

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];

Ans. None of these


-----------------------------------------------------------------------------------
---------------------------------------------------------------------

-----------------------------------------------------------------------------------
---------------------------------------------------------------------
36. In the following code fragment what gets printed?

>>
int data[5] = {0 ,1, 2, 3, 4}, sum = 0 , i;

for (i = 0; i < 5 ; i++)


sum = sum + data[i];
printf(“%d\n”, sum);

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));

what gets printed?

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

You might also like