Programming in C -UNIT III

35 flashcards · Other · by Kamala Viswanathan

  1. A pointer is A. A keyword used to create variables B. A variable that stores address of an instruction C. A variable that stores address of other variable D. All of the above

    C. A variable that stores address of other variable

  2. The operator used to get value at address stored in a pointer variable is A. * B. & C. && D. ||

    A. *

  3. What is (void*)0? A. Representation of NULL pointer B. Representation of void pointer C. Error D. None of above

    A. Representation of NULL pointer

  4. char *p; p = (char*) malloc(100) Short form of the above statements is: A. char p = *malloc(100); B. char *p = (char) malloc(100); C. char *p = (char*)malloc(100); D. char *p = (char *)(malloc*)(100);

    C. char *p = (char*)malloc(100);

  5. In which header file is the NULL macro defined? A. stdio.h B. stddef.h C. stdio.h and stddef.h D. math.h

    C. stdio.h and stddef.h

  6. If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable? A. . B. & C. * D. ->

    D. ->

  7. What would be the equivalent pointer expression for referring the array element a[i][j][k][l] A. ((((a+i)+j)+k)+l) B. *(*(*(*(a+i)+j)+k)+l) C. (((a+i)+j)+k+l) D. ((a+i)+j+k+l)

    B. *(*(*(*(a+i)+j)+k)+l)

  8. What will be the output of the program ? A. ink B. ack C. ite D. let

    A. ink

  9. What will be the output of the program? A. 30 B. 27 C. 9 D. 3

    A. 30

  10. What will be the output of the program ? A. x=31, y=502, z=502 B. x=31, y=500, z=500 C. x=31, y=498, z=498 D. x=31, y=504, z=504

  11. Where is linear searching used? a) When the list has only a few elements b) When performing a single search in an unordered list c) Used all the time d) When the list has only a few elements and When performing a single search in an unordered list

    d) When the list has only a few elements and When performing a single search in an unordered list Explanation: It is practical to implement linear search in the situations mentioned in When the list has only a few elements and When performing a single search in an unordered list, but for larger elements the complexity becomes larger and it makes sense to sort the list and employ binary search or hashing.

  12. What is the best case for linear search? a) O(nlogn) b) O(logn) c) O(n) d) O(1)

    Answer: d Explanation: The element is at the head of the array, hence O(1).

  13. What is the worst case for linear search? a) O(nlogn) b) O(logn) c) O(n) d) O(1)

    Explanation: Worst case is when the desired element is at the tail of the array or not present at all, in this case you have to traverse till the end of the array, hence the complexity is O(n).

  14. Uses of functions A. Helps to avoid repeating a set of statements many times. B. Enhances the logical clarity of the program. C. Helps to avoid repeated programming across programs. D. Makes the debugging task easier. E. All of the above

    E. All of the above

  15. Any C program A.Must contain at least one function. B.Need not contain any function. C.Needs input data. D.None of the above

    A.Must contain at least one function.

  16. Determine the output A. 10 B. 9 C. 11 D. None of these.

    B. 9

  17. Default parameter passing mechanism is A. call by value B. call by reference C. call by value result D. None of these.

    A. call by value

  18. What is the result of compiling and running the code? A. will print Hello World B. Compilation Error C. will print garbage value D. None of these.

    B. Compilation Error

  19. Determine the output A. 54544 B. 45445 C. 54554 D. 45545

    D. 45545

  20. C. II and III

  21. What will the function rewind() do? A. Reposition the file pointer to a character reverse. B. Reposition the file pointer stream to end of file. C. Reposition the file pointer to beginning of that line. D. Reposition the file pointer to beginning of file.

    D. Reposition the file pointer to beginning of file.

  22. Input/output function prototypes and macros are defined in which header file? A. conio.h B. stdlib.h C. stdio.h D. dos.h

    C. stdio.h

  23. Which standard library function will you use to find the last occurance of a character in a string in C? A. strnchar() B. strchar() C. strrchar() D. strrchr()

    D. strrchr()

  24. What is stderr ? A. standard error B. standard error types C. standard error streams D. standard error definitions

    C. standard error streams

  25. Does there any function exist to convert the int or float to a string? A. Yes B. No

    A. Yes

  26. Which of the following statement is correct about the ftell() function? A. It returns the current position. B. It sets the file pointer to the given position. C. It sets the file pointer at the beginning of the file. D. It reads a character from the file.

    A. It returns the current position.

  27. The process in which a function calls itself directly or indirectly is called? A. Recursion B. Type Conversions C. Constant D. Abstract Classes

    A. Recursion The process in which a function calls itself directly or indirectly is called recursion

  28. function fun() is called __________ if it calls the same function fun(). A. indirect recursive B. direct recursive C. Both A and B D. None of the above

    B. direct recursive

  29. Which of the following is not an example of recursion? A. Towers of Hanoi (TOH) B. DFS C. Inorder Tree Traversals D. SFS

    D. SFS

  30. Iteration requires more system memory than recursion. A. TRUE B. FALSE C. Can be true or false D. Can not Say

    B. FALSE Recursion requires more system memory than iteration due to the maintenance of stack.

  31. When a recursive function is called in the absence of an exit condition, it results in an infinite loop due to which the stack keeps getting filled(stack overflow). This results in a run time error. A. TRUE B. FALSE C. Can be true or false D. Can not Say

    A. TRUE When a recursive function is called in the absence of an exit condition, it results in an infinite loop due to which the stack keeps getting filled(stack overflow). This results in a run time error.

  32. The data structure used to implement recursive function calls _____________ A. Array B. Linked List C. Binary tree D. Stack

    D. Stack The compiler uses the data type stack for implementing normal as well as recursive function calls.

  33. What will be output for the following code? A. 6 B. 7 C. 8 D. 9

    C. 8 The output for the following code : 8

  34. What will be output for the following code? A. Hello is printed once B. Hello infinite number of times C. Hello is not printed at all D. 0 is returned

    B. Hello infinite number of times In the above code, we are calling main() from main(), which is recursion. However, we have not defined any condition for the program to exit. Hence, “hello” will be printed infinite number of times. To prevent this, we need to define a proper exit condition in the recursive function.

  35. Which of the following is true about recursion? A. Recursion provides a clean and simple way to write code. B. The recursive program has less space requirements than iterative program C. The principle of stack is FIFO D. All of the above

    A. Recursion provides a clean and simple way to write code. Recursion provides a clean and simple way to write code is true about recursion.