C Language quiz questions

C Language interview questions

  • 1.

    What function should be used to free the memory allocated by calloc() ?

    1. dealloc();

    2. malloc(variable_name, 0)

    3. free();

    4. memalloc(variable_name, 0)

    Answer
  • 2.

    Point out the error in the program.

    #include<stdio.h>
    #include<stdlib.h>
    int fun(const union employee *e);
    union employee
    {
        char name[15];
        int age;
        float salary;
    };
    const union employee e1;
    int main()
    {
        strcpy(e1.name, "A");
        fun(&e1);
        printf("%s %d %f", e1.name, e1.age, e1.salary);
        return 0;
    }
    int fun(const union employee *e)
    {
        strcpy((*e).name, "B");
        return 0;
    }
    1. Error: RValue required

    2. Error: cannot convert parameter 1 from 'const char[15]' to 'char *'

    3. Error: LValue required in strcpy

    4. No error

    Answer
  • 3.

    What will be the output of the program?

    #include<stdio.h>
    int get();
    int main()
    {
        const int x = get();
        printf("%d", x);
        return 0;
    }
    int get()
    {
        return 20;
    }
    1. Garbage value

    2. Error

    3. 20

    4. 0

    Answer
  • 4.

    Does there exist any way to make the command-line arguments available to other functions without passing them as arguments to the function?

    1. Yes

    2. No

    Answer
  • 5.

    Which of the following statements correct about the below program?

    #include<stdio.h>
    int main()
    {
        union a
        {
            int i;
            char ch[2];
        };
        union a u1 = {512};
        union a u2 = {0, 2};
        return 0;
    }
    
    1: u2 CANNOT be initialized as shown.
    2: u1 can be initialized as shown.
    3: To initialize char ch[] of u2 '.' operator should be used.
    4: The code causes an error 'Declaration syntax error'
    1. 1, 2

    2. 2, 3

    3. 1, 2, 3

    4. 1, 3, 4

    Answer
  • 6.

    What will be the output of the program (Turbo C in 16 bit platform DOS) ?

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char *str1 = "India";
        char *str2 = "BIX";
        char *str3;
        str3 = strcat(str1, str2);
        printf("%s %s\n", str3, str1);
        return 0;
    }
    1. IndiaBIX India

    2. IndiaBIX IndiaBIX

    3. India India

    4. Error

    Answer
  • 7.

    Is there any difference int the following declarations?
    int fun(int arr[]);
    int fun(int arr[2]);

    1. Yes

    2. No

    Answer
  • 8.

    What will be the output of the program ?

    #include<stdio.h>
    int main()
    {
        float arr[] = {12.4, 2.3, 4.5, 6.7};
        printf("%d\n", sizeof(arr)/sizeof(arr[0]));
        return 0;
    }
    1. 5

    2. 4

    3. 6

    4. 7

    Answer
  • 9.

    Point out the error in the program

    #include<stdio.h>
    int main()
    {
        int i;
        #if A
            printf("Enter any number:");
            scanf("%d", &i);
        #elif B
            printf("The number is odd");
        return 0;
    }
    1. Error: unexpected end of file because there is no matching #endif

    2. The number is odd

    3. Garbage values

    4. None of above

    Answer
  • 10.

    If a function contains two return statements successively, the compiler will generate warnings. Yes/No ?

    1. Yes

    2. No

    Answer
  • 11.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        float d=2.25;
        printf("%e,", d);
        printf("%f,", d);
        printf("%g,", d);
        printf("%lf", d);
        return 0;
    }
    1. 2.2, 2.50, 2.50, 2.5

    2. 2.2e, 2.25f, 2.00, 2.25

    3. 2.250000e+000, 2.250000, 2.25, 2.250000

    4. Error

    Answer
  • 12.

    What will be the output of the program?

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        float n=1.54;
        printf("%f, %f\n", ceil(n), floor(n));
        return 0;
    }
    1. 2.000000, 1.000000

    2. 1.500000, 1.500000

    3. 1.550000, 2.000000

    4. 1.000000, 2.000000

    Answer
  • 13.

    Which of the following is the correct usage of conditional operators used in C?

    1. a>b ? c=30 : c=40;

    2. a>b ? c=30;

    3. max = a>b ? a>c?a:c:b>c?b:c

    4. return (a>b)?(a:b)

    Answer
  • 14.

    Point out the correct statements are correct about the program below?

    #include<stdio.h>
    int main()
    {
        char ch;
        while(x=0;x<=255;x++)
            printf("ASCII value of %d character %c\n", x, x);
        return 0;
    }
    1. The code generates an infinite loop

    2. The code prints all ASCII values and its characters

    3. Error: x undeclared identifier

    4. Error: while statement missing

    Answer
  • 15.

    Point out the error in the following program.

    #include<stdio.h>
    int main()
    {
        char str[] = "IndiaBIX";
        printf("%.#s %2s", str, str);
        return 0;
    }
    1. Error: in Array declaration

    2. Error: printf statement

    3. Error: unspecified character in printf

    4. No error

    Answer
  • 16.

    Point out the error in the following program.

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char str1[] = "Learn through IndiaBIX\0.com",  str2[120];
        char *p;
        p = (char*) memccpy(str2, str1, 'i', strlen(str1));
        *p = '\0';
        printf("%s", str2);
        return 0;
    }
    1. Error: in memccpy statement

    2. Error: invalid pointer conversion

    3. Error: invalid variable declaration

    4. No error and prints "Learn through Indi"

    Answer
  • 17.

    What do the following declaration signify?

    char *arr[10];
    1. arr is a array of 10 character pointers.

    2. arr is a array of function pointer.

    3. arr is a array of characters.

    4. arr is a pointer to array of characters.

    Answer
  • 18.

    Point out the correct statement will let you access the elements of the array using 'p' in the following program?

    #include<stdio.h>
    #include<stdlib.h>
    int main()
    {
        int i, j;
        int(*p)[3];
        p = (int(*)[3])malloc(3*sizeof(*p));
        return 0;
    }
    1. for(i=0; i<3; i++)
      {
          for(j=0; j<3; j++)
              printf("%d", p[i+j]);
      }
    2. for(i=0; i<3; i++)
          printf("%d", p[i]);
    3. for(i=0; i<3; i++)
      {
          for(j=0; j<3; j++)
              printf("%d", p[i][j]);
      }
    4. for(j=0; j<3; j++)
          printf("%d", p[i][j]);
    Answer
  • 19.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        const c = -11;
        const int d = 34;
        printf("%d, %d\n", c, d);
        return 0;
    }
    1. Error

    2. -11, 34

    3. 11, 34

    4. None of these

    Answer
  • 20.

    Which of the following statements are correct about the program?

    #include<stdio.h>
    char *fun(unsigned int num, int base);
    int main()
    {
        char *s;
        s=fun(128, 2);
        s=fun(128, 16);
        printf("%s\n",s);
        return 0;
    }
    char *fun(unsigned int num, int base)
    {
        static char buff[33];
        char *ptr = &buff[sizeof(buff)-1];
        *ptr = '\0';
        do
        {
            *--ptr = "0123456789abcdef"[num %base];
            num /=base;
        }while(num!=0);
        return ptr;
    }
    1. It converts a number to a given base.

    2. It converts a number to its equivalent binary.

    3. It converts a number to its equivalent hexadecimal.

    4. It converts a number to its equivalent octal.

    Answer

© 2017 QuizBucket.org