Coding Quiz 1

20 Questions | Total Attempts: 64

SettingsSettingsSettings
Please wait...
Programming Quizzes & Trivia

This is your description.


Questions and Answers
  • 1. 
    • A. 

      5 5 5 5

    • B. 

      3 5 3 5

    • C. 

      5 3 3 5

    • D. 

      None of the above

  • 2. 
    typedef int (*test)(float*, float*); test tmp; What is the type of tmp?
    • A. 

      Function taking two pointer-to-float arguments and returning pointer to int

    • B. 

      Pointer to int

    • C. 

      pointer to function taking two pointer-to-float arguments and returning int (d) none of the above

    • D. 

      None of the above

  • 3. 
    #include <stdlib.h> int *f1(void) { int x = 10; return &x; } int *f2(void) { int *ptr; *ptr = 10; return ptr; } int *f3(void) { int *ptr; ptr = malloc(sizeof *ptr); return ptr; } Which of these functions uses pointers incorrectly?
    • A. 

      F3 only

    • B. 

      F1 and f3

    • C. 

      f1 and f2

    • D. 

      F1, f2, and f3

  • 4. 
    #include <stdio.h> int counter(int i) { static int count = 0; count = count + i; return count; } int main(void) { int i, j; for (i = 0; i <= 5; i++) j = counter(i); printf("%d\n", j); return 0; } What is the output of this program?
    • A. 

      10

    • B. 

      15

    • C. 

      6

    • D. 

      7

  • 5. 
    #include <stdio.h> void f(char**); int main(void) { char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" }; f(argv); return 0; } void f(char **p) { char *t; t = (p += sizeof(int))[-1]; printf("%s\n", t); } What is the output of this program on an implementation where int and all pointer types occupy 2 bytes?
    • A. 

      Ab

    • B. 

      Cd

    • C. 

      Ef

    • D. 

      Gh

  • 6. 
    #include <stdio.h> int main(void) { int i = 3; int j; j = sizeof(++i + ++i); printf("i=%d j=%d\n", i, j); return 0; } What is the output of this program on an implementation where int occupies 2 bytes?
    • A. 

      I=4 j=2

    • B. 

      I=3 j=2

    • C. 

      I=5 j=2

    • D. 

      The behavior is undefined

  • 7. 
    #include <stdio.h> int main(void) { char p; char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8}; p = (buf + 1)[5]; printf("%d\n", p); return 0; } What is the output of this program?
    • A. 

      5

    • B. 

      6

    • C. 

      9

    • D. 

      None of the above

  • 8. 
    #include int main(void) { int a[5] = { 1, 2, 3, 4, 5 }; int *ptr = (int*)(&a + 1); printf("%d %d\n", *(a + 1), *(ptr - 1)); return 0; } What is the output of this program?
    • A. 

      2 2

    • B. 

      2 1

    • C. 

      2 5

    • D. 

      None of the above

  • 9. 
    Point out the error in the program. #include int main() { const int x; x=128; printf("%d", x); return 0; }
    • A. 

      Unknown data type const int

    • B. 

      Stack overflow in x

    • C. 

      Const variable have been initialised when declared.

    • D. 

      No error

  • 10. 
    #include <stdarg.h> #include <stdio.h> int ripple(int n, ...) { int i, j, k; va_list p; k = 0; j = 1; va_start(p, n); for (; j < n; ++j) { i = va_arg(p, int); for (; i; i &= i - 1) ++k; } va_end(p); return k; } int main(void) { printf("%d\n", ripple(3, 5, 7)); return 0; } What is the output of this program?
    • A. 

      7

    • B. 

      6

    • C. 

      5

    • D. 

      3

  • 11. 
    void *ptr; myStruct myArray[10]; ptr = myArray; Which of the following is the correct way to increment the variable "ptr"?
    • A. 

      Ptr = ptr + sizeof(myStruct);

    • B. 

      ++(int*)ptr;

    • C. 

      Ptr = ptr + sizeof(myArray);

    • D. 

      Increment(ptr);

    • E. 

      Ptr = ptr + sizeof(ptr);

  • 12. 
    #define MAX_NUM 15 Referring to the sample above, what is MAX_NUM?
    • A. 

      MAX_NUM is an integer variable.

    • B. 

      MAX_NUM is a linker constant.

    • C. 

      MAX_NUM is a precompiler constant.

    • D. 

      MAX_NUM is a preprocessor macro.

    • E. 

      MAX_NUM is an integer constant.

  • 13. 
    Void (*signal(int sig, void (*handler) (int))) (int); Which one of the following definitions of sighandler_t allows the above declaration to be rewritten as follows: sighandler_t signal (int sig, sighandler_t handler);
    • A. 

      Typedef void (*sighandler_t) (int);

    • B. 

      Typedef sighandler_t void (*) (int);

    • C. 

      Typedef void *sighandler_t (int);

    • D. 

      #define sighandler_t(x) void (*x) (int)

    • E. 

      #define sighandler_t void (*) (int)

  • 14. 
    Point out the error in the following program. #include<stdio.h> void display(int (*ff)()); int main() { int show(); int (*f)(); f = show; display(f); return 0; } void display(int (*ff)()) { (*ff)(); } int show() { printf("ASTIWZ"); }
    • A. 

      Error: invalid parameter in function display()

    • B. 

      Error: invalid function call f=show;

    • C. 

      No error and prints "ASTIWZ"

    • D. 

      No error and prints nothing.

  • 15. 
    Char txt [20] = "Hello world!\0"; How many bytes are allocated by the definition above?
    • A. 

      10

    • B. 

      11

    • C. 

      14

    • D. 

      20

    • E. 

      21

  • 16. 
    Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?
    • A. 

      Int *ptr = (int *) malloc(10, sizeof(int));

    • B. 

      Int *ptr = (int *) calloc(10, sizeof(int))

    • C. 

      Int *ptr = (int *) malloc(10*sizeof(int)); [Ans]

    • D. 

      Int *ptr = (int *) alloc(10*sizeof(int));

    • E. 

      Int *ptr = (int *) calloc(10*sizeof(int));

  • 17. 
    Short int x; /* assume x is 16 bits in size */ What is the maximum number that can be printed using printf("%d\n", x), assuming that x is initialized as shown above?
    • A. 

      127

    • B. 

      128

    • C. 

      32,767

    • D. 

      65,536

  • 18. 
    How does variable definition differ from variable declaration?
    • A. 

      Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type.

    • B. 

      Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type.

    • C. 

      Variables may be defined many times, but may be declared only once.

    • D. 

      Variable definition must precede variable declaration.

    • E. 

      There is no difference in C between variable declaration and variable definition.

  • 19. 
    What number is equivalent to -4e3?
    • A. 

      -4000

    • B. 

      -400

    • C. 

      .004

    • D. 

      .0004

  • 20. 
    Point out the error in the program? #include<stdio.h> #include<stdlib.h> int main() { unsigned char; FILE *fp; fp=fopen("trial", "r"); if(!fp) { printf("Unable to open file"); exit(1); } fclose(fp); return 0; }
    • A. 

      Error: in unsigned char statement

    • B. 

      Error: unknown file pointer

    • C. 

      No error

    • D. 

      None of the above