C Language quiz questions

C Language interview questions

  • 1.

    Which files will get closed through the fclose() in the following program?

    #include<stdio.h>
    
    int main()
    {
        FILE *fs, *ft, *fp;
        fp = fopen("A.C", "r");
        fs = fopen("B.C", "r");
        ft = fopen("C.C", "r");
        fclose(fp, fs, ft);
        return 0;
    }
    1. "A.C" "B.C" "C.C"

    2. "B.C" "C.C"

    3. "A.C"

    4. Error in fclose()

    Answer
  • 2.

    In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?

    1. "I am a boy\r\n\0"

    2. "I am a boy\r\0"

    3. "I am a boy\n\0"

    4. "I am a boy"

    Answer
  • 3.

    How will you free the allocated memory?

    1. remove(var-name);

    2. free(var-name);

    3. delete(var-name);

    4. dalloc(var-name);

    Answer
  • 4.

    What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        char *p;
        p="hello";
        printf("%s\n", *&*&p);
        return 0;
    }
    1. llo

    2. hello

    3. ello

    4. h

    Answer
  • 5.

    A preprocessor directive is a message from programmer to the preprocessor.

    1. True

    2. False

    Answer
  • 6.

    What will be the output of the program?

    #include<stdio.h>
    #define SQR(x)(x*x)
    
    int main()
    {
        int a, b=3;
        a = SQR(b+2);
        printf("%d\n", a);
        return 0;
    }
    1. 25

    2. 11

    3. Error

    4. Garbage value

    Answer
  • 7.

    How many times the program will print "IndiaBIX" ?

    #include<stdio.h>
    
    int main()
    {
        printf("IndiaBIX");
        main();
        return 0;
    }
    1. Infinite times

    2. 32767 times

    3. 65535 times

    4. Till stack overflows

    Answer
  • 8.

    What is the notation for following functions?

    1.  int f(int a, float b)
        {
            /* Some code */
        }
    
    2.  int f(a, b)
        int a; float b;
        {
            /* Some code */
        }
    1. 1. KR Notation 
      2. ANSI Notation

    2. 1. Pre ANSI C Notation 
      2. KR Notation

    3. 1. ANSI Notation 
      2. KR Notation

    4. 1. ANSI Notation 
      2. Pre ANSI Notation

    Answer
  • 9.

    In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators

     

    1. True

    2. False

    Answer
  • 10.

    What will be the output of the program?

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

    2. 4, 3

    3. 4, 4

    4. Output may vary from compiler to compiler

    Answer
  • 11.

    Point out the error, if any in the program.

    #include<stdio.h>
    int main()
    {
        int P = 10;
        switch(P)
        {
           case 10:
           printf("Case 1");
    
           case 20:
           printf("Case 2");
           break;
    
           case P:
           printf("Case 2");
           break;
        }
        return 0;
    }
    1. Error: No default value is specified

    2. Error: Constant expression required at line case P:

    3. Error: There is no break statement in each case.

    4. No error will be reported.

    Answer
  • 12.

    Which of the following errors would be reported by the compiler on compiling the program given below?

    #include<stdio.h>
    int main()
    {
        int a = 5;
        switch(a)
        {
        case 1:
        printf("First");
    
        case 2:
        printf("Second");
    
        case 3 + 2:
        printf("Third");
    
        case 5:
        printf("Final");
        break;
    
        }
        return 0;
    }
    1. There is no break statement in each case.

    2. Expression as in case 3 + 2 is not allowed.

    3. Duplicate case case 5:

    4. No error will be reported.

    Answer
  • 13.

    How many times the while loop will get executed if a short int is 2 byte wide?

    #include<stdio.h>
    int main()
    {
        int j=1;
        while(j <= 255)
        {
            printf("%c %d\n", j, j);
            j++;
        }
        return 0;
    }
    1. Infinite times

    2. 255 times

    3. 256 times

    4. 254 times

    Answer
  • 14.

    va_list is an array that holds information needed by va_arg and va_end

    1. True

    2. False

    Answer
  • 15.

    Point out the error in the following program.

    #include<stdio.h>
    #include<stdarg.h>
    void varfun(int n, ...);
    
    int main()
    {
        varfun(3, 7, -11.2, 0.66);
        return 0;
    }
    void varfun(int n, ...)
    {
        float *ptr;
        int num;
        va_start(ptr, n);
        num = va_arg(ptr, int);
        printf("%d", num);
    }
    1. Error: too many parameters

    2. Error: invalid access to list member

    3. Error: ptr must be type of va_list

    4. No error

    Answer
  • 16.

    Which header file should you include, if you are going to develop a function, which can accept variable number of arguments?

    1. varagrg.h

    2. stdlib.h

    3. stdio.h

    4. stdarg.h

    Answer
  • 17.

    What is the output of the program?

    typedef struct data;
    {
        int x;
        sdata *b;
    }sdata;
    1. Error: Declaration missing ';'

    2. Error: in typedef

    3. No error

    4. None of above

    Answer
  • 18.

    What will be the output of the program?

    #include<stdio.h>
    
    int main()
    {
        char c=48;
        int i, mask=01;
        for(i=1; i<=5; i++)
        {
            printf("%c", c|mask);
            mask = mask<<1;
        }
        return 0;
    }
    1. 12400

    2. 12480

    3. 12500

    4. 12556

    Answer
  • 19.

    The first argument to be supplied at command-line must always be count of total arguments.

    1. True

    2. False

    Answer
  • 20.

    Which of the following statement is correct about the program?

    #include<stdio.h>
    
    int main()
    {
        FILE *fp;
        char ch;
        int i=1;
        fp = fopen("myfile.c", "r");
        while((ch=getc(fp))!=EOF)
        {
            if(ch == '\n')
                i++;
        }
        fclose(fp);
        return 0;
    }
    1. The code counts number of characters in the file

    2. The code counts number of words in the file

    3. The code counts number of blank lines in the file

    4. The code counts number of lines in the file

    Answer

© 2017 QuizBucket.org