C Language quiz questions

C Language interview questions

  • 1.

    Which of the following statements are correct about the program?

    #include<stdio.h>
    
    int main()
    {
        unsigned int num;
        int i;
        scanf("%u", &num);
        for(i=0; i<16; i++)
        {
            printf("%d", (num<<i & 1<<15)?1:0);
        }
        return 0;
    }
    1. It prints all even bits from num

    2. It prints all odd bits from num

    3. It prints binary equivalent num

    4. Error

    Answer
  • 2.

    What will be the output of the program

    #include<stdio.h>
    void fun(int);
    
    int main(int argc)
    {
        printf("%d ", argc);
        fun(argc);
        return 0;
    }
    void fun(int i)
    {
        if(i!=4)
            main(++i);
    }
    1. 1 2 3

    2. 1 2 3 4

    3. 2 3 4

    4. 1

    Answer
  • 3.

    Point out the error/warning in the program?

    #include<stdio.h>
    
    int main()
    {
        unsigned char ch;
        FILE *fp;
        fp=fopen("trial", "r");
        while((ch = getc(fp))!=EOF)
            printf("%c", ch);
        fclose(fp);
        return 0;
    }
    1. Error: in unsigned char declaration

    2. Error: while statement

    3. No error

    4. It prints all characters in file "trial"

    Answer
  • 4.

    If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?

    struct ex
    {
        char ch;
        int i;
        long int a;
    };
    1. Yes

    2. No

    Answer
  • 5.

    What will be the output of the following program in 16 bit platform assuming that 1022 is memory address of the string "Hello1" (in Turbo C under DOS) ?

    #include<stdio.h>
    
    int main()
    {
        printf("%u %s\n", &"Hello1", &"Hello2");
        return 0;
    }
    1. Hello1 1022

    2. 1022 Hello2

    3. Hello1 Hello2

    4. 1022 1022

    5. Error

    Answer
  • 6.

    What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        int i;
        char a[] = "\0";
        if(printf("%s", a))
            printf("The string is empty\n");
        else
            printf("The string is not empty\n");
        return 0;
    }
    1. The string is empty

    2. The string is not empty

    3. No output

    4. 0

    Answer
  • 7.

    What will be the output of the program if the array begins at address 65486?

    #include<stdio.h>
    
    int main()
    {
        int arr[] = {12, 14, 15, 23, 45};
        printf("%u, %u\n", arr, &arr);
        return 0;
    }
    1. 65486, 65488

    2. 65486, 65486

    3. 65486, 65490

    4. 65486, 65487

    Answer
  • 8.

    In the following program add a statement in the function fact() such that the factorial gets stored in j.

    #include<stdio.h>
    void fact(int*);
    
    int main()
    {
        int i=5;
        fact(&i);
        printf("%d\n", i);
        return 0;
    }
    void fact(int *j)
    {
        static int s=1;
        if(*j!=0)
        {
            s = s**j;
            *j = *j-1;
            fact(j);
            /* Add a statement here */
        }
    }
    1. j=s;

    2. *j=s;

    3. *j=&s;

    4. &j=s;

    Answer
  • 9.

    If the size of integer is 4bytes, What will be the output of the program?

    #include<stdio.h>
    
    int main()
    {
        int arr[] = {12, 13, 14, 15, 16};
        printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
        return 0;
    }
    1. 10, 2, 4

    2. 20, 4, 4

    3. 16, 2, 2

    4. 20, 2, 2

    Answer
  • 10.

    What will be the output of the program ?

    #include<stdio.h>
    int *check(static int, static int);
    
    int main()
    {
        int *c;
        c = check(10, 20);
        printf("%d\n", c);
        return 0;
    }
    int *check(static int i, static int j)
    {
        int *p, *q;
        p = &i;
        q = &j;
        if(i >= 45)
            return (p);
        else
            return (q);
    }
    1. 10

    2. 20

    3. Error: Non portable pointer conversion

    4. Error: cannot use static for function parameters

    Answer
  • 11.

    Will the following program print the message infinite number of times?

    #include<stdio.h>
    #define INFINITELOOP while(1)
    
    int main()
    {
        INFINITELOOP
        printf("IndiaBIX");
        return 0;
    }
    1. Yes

    2. No

    Answer
  • 12.

    What will be the output of the program?

    #include<stdio.h>
    
    int addmult(int ii, int jj)
    {
        int kk, ll;
        kk = ii + jj;
        ll = ii * jj;
        return (kk, ll);
    }
    
    int main()
    {
        int i=3, j=4, k, l;
        k = addmult(i, j);
        l = addmult(i, j);
        printf("%d, %d\n", k, l);
        return 0;
    }
    1. 12, 12

    2. 7, 7

    3. 7, 12

    4. 12, 7

    Answer
  • 13.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        int i=-3, j=2, k=0, m;
        m = ++i && ++j || ++k;
        printf("%d, %d, %d, %d\n", i, j, k, m);
        return 0;
    }
    1. 1, 2, 0, 1

    2. -3, 2, 0, 1

    3. -2, 3, 0, 1

    4. 2, 3, 1, 1

    Answer
  • 14.

    How many times "IndiaBIX" is get printed?

    #include<stdio.h>
    int main()
    {
        int x;
        for(x=-1; x<=10; x++)
        {
            if(x < 5)
                continue;
            else
                break;
            printf("IndiaBIX");
        }
        return 0;
    }
    1. Infinite times

    2. 11 times

    3. 0 times

    4. 10 times

    Answer
  • 15.

    Data written into a file using fwrite() can be read back using fscanf()

    1. True

    2. False

    Answer
  • 16.

    Which standard library function will you use to find the last occurance of a character in a string in C?

    1. strnchar()

    2. strchar()

    3. strrchar()

    4. strrchr()

    Answer
  • 17.

    What will be the output of the program?

    #include<stdio.h>
    
    int main()
    {
        const int i=0;
        printf("%d\n", i++);
        return 0;
    }
    1. 10

    2. 11

    3. No output

    4. Error: ++needs a value

    Answer
  • 18.

    What will be the output of the program?

    #include<stdio.h>
    
    typedef struct error {int warning, err, exception;} ERROR;
    int main()
    {
        ERROR e;
        e.err=1;
        printf("%d\n", e.err);
        return 0;
    }
    1. 0

    2. 1

    3. 2

    4. Error

    Answer
  • 19.

    If the different command line arguments are supplied at different times would the output of the following program change?

    #include<stdio.h>
    
    int main(int argc, char **argv)
    {
        printf("%d\n", argv[argc]);
        return 0;
    }
    1. Yes

    2. No

    Answer
  • 20.

    Even if integer/float arguments are supplied at command prompt they are treated as strings.

    1. True

    2. False

    Answer

© 2017 QuizBucket.org