C Language quiz questions

C Language interview questions

  • 1.

    Choose the function that is most appropriate for reading in a multi-word string?

    1. strnset()

    2. scanf()

    3. strchr()

    4. gets()

    Answer
  • 2.

    Choose the correct order from given below options for the calling function of the code “a = f1(23, 14) * f2(12/4) + f3();”?

    1. f1, f2, f3

    2. f3, f2, f1

    3. f2, f1, f3

    4. Order may vary from one compiler to another

    Answer
  • 3.

    What actually get pass when you pass an array as a function argument?

    1. First value of elements in array

    2. Base address of the array

    3. All value of element in array

    4. Address of the last element of array

    Answer
  • 4.

    Similarity between a structure, union and enumeration,

    1. All are helpful in defining new variables

    2. All are helpful in defining new data types

    3. All are helpful in defining new pointers

    4. All are helpful in defining new structures

    Answer
  • 5.

    The prototype of a function can be used to,

    1. Define a function

    2. Declare a function

    3. Erase a function

    4. None of the above

    Answer
  • 6.

    What is the output of the following program?

    #include<stdio.h>
    main()
    { 
       char s[] = "Hello\0Hi";
       printf("%d %d", strlen(s), sizeof(s));
    }

     

    1. 5 9

    2. 7 20

    3. 5 20

    4. 8 20

    Answer
  • 7.

    To store a word/sentence declare a variable of the type ‘string’.

    1. true

    2. false

    Answer
  • 8.

    What is the output of the following program?

    #include<stdio.h>
    main()
    { 
       int i = 13, j = 60;
       i ^= j;
       j ^= i;
       i ^= j;
       printf("%d %d", i, j);
    }

     

    1. 73 73

    2. 60 13

    3. 13 60

    4. 60 60

    Answer
  • 9.

    What is the output of the following program?

    #include<stdio.h>
    main()
    {
       int i = 1;
       while( i++<=5 )
          printf("%d ",i++);
    }

     

    1. 1 3 5

    2. 2 4

    3. 2 4 6

    4. 2

    Answer
  • 10.

    What is the output of the below code snippet?

    #include<stdio.h>
    main() 
    { 
       int a = 1; 
       float b = 1.3; 
       double c;
       c = a + b; 
       printf("%.2lf", c);
    }

     

    1. 2.30

    2. 2.3

    3. Compile error

    4. 2.0

    Answer
  • 11.

    What value is returned by function func?

    float func(){
       int r = 0, d = 0, i=0;
       for (i; i < 2; i++) {
           r += 5 / d;
       }   
       return r;
    }
    1. 0

    2. 1

    3. 5

    4. infiniti

    5. code has undefined behavior

    Answer
  • 12.

    When running the code below, line 7 that increments y will always be executed at runtime.

    1 
      2 int main()
      3 {
      4     int x = 0;
      5     int y = 0;
      6     if (!x){
      7        y++;
      8     }
      9     return 0;
     10 }
    1. true

    2. false

    Answer
  • 13.

    What gets printed?

    01 #include <stdio.h>
    02
    03 int main()
    04 {
    05    int ints[] = { 0, 1, 2, 3 };
    06    int* i1 = ints + 1;
    07    int* i2 = ints + 2;
    08    int a = ++*i1 + *i2++;
    09    int b = *++i1 + *i2--;
    10    printf("%d#%d", a, b);
    11    return 0;
    12 }
    1. 5#6

    2. 4#6

    3. 4#5

    4. Undefined behavior

    5. Compiler error on line 9

    Answer
  • 14.

    What gets printed?

    #include <stdio.h>
    int main()
    {
            int ints[] = { 0, 5, 10, 15 };
            int* i2 = ints + 2;
            int a = *i2++;
            printf("%d#%d\n", a, *i2);
            return 0;
    }
    1. 10#11

    2. 10#15

    3. 11#15

    4. 15#15

    5. ill-formed syntax

    Answer
  • 15.

    what gets printed?

    #include <stdio.h>
    int main()
    {
            int ints[] = { 0, 1, 2, 3 };
            int* i1 = ints + 1;
            int a = ++*i1;
            int b = a + *i1;
            printf("%d\n", b);
            return 0;
    }
    1. 3

    2. 4

    3. 5

    4. 6

    5. code has undefined behavior

    Answer
  • 16.

    What gets printed?

    printf("%d\n", 4 ?: 8);
    1. 4

    2. 0

    3. 8

    4. NULL

    5. program has a compiler error

    Answer
  • 17.

    What gets printed?

    int i = 3;
    if (!i)
        i++;
        i++;
    if (i==3)
        i+=2;
        i+=2;
    printf("%d\n", i);
    1. 3

    2. 5

    3. 6

    4. 7

    5. 9

    Answer
  • 18.

    What gets printed?

    int array[2][2] = {0, 1, 2, 3};
    int i;
    int sum = 0;
    for (i =0; i < 4; ++i){
        int x, y;
        x = i % 2;
        if (x){
            y = 0;
        }
        else{
            y = 1;
        }
        sum += array[x][y];
    }
    printf("%d\n", sum);
    1. 6

    2. 7

    3. 8

    4. 9

    5. 10

    Answer
  • 19.

    What gets printed by the code below? (Assume 1 byte characters)

    char array[] = "foo";
    printf("%lu\n", sizeof(array[1]));
    
    1. 0

    2. 1

    3. 2

    4. 3

    5. 4

    Answer
  • 20.

    What value gets printed by the program below?

    int w = 3;
    int x = 31;
    int y = 10;
    double z =  x / y % w;
    printf("%f\n", z);
    1. 0

    2. 1

    3. 3

    4. undefined

    5. machine dependent

    Answer

© 2017 QuizBucket.org