C Language quiz questions

C Language interview questions

  • 1.

    What will be the output of the program (sample.c) given below if it is executed from the command line?
    cmd> sample friday tuesday sunday

    /* sample.c */
    #include<stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("%c", *++argv[2] );
        return 0;
    }
    1. s

    2. f

    3. u

    4. r

    Answer
  • 2.

    What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
    cmd> sample Good Morning

    /* sample.c */
    #include<stdio.h>
    
    int main(int argc, char *argv[])
    {
        printf("%d %s", argc, argv[1]);
        return 0;
    }
    1. 3 Good

    2. 2 Good

    3. Good Morning

    4. 3 Morning

    Answer
  • 3.

    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;
    }
    1. Error: in unsigned char statement

    2. Error: unknown file pointer

    3. No error

    4. None of above

    Answer
  • 4.

    What will be the output of the program if value 25 given to scanf()?

    #include<stdio.h>
    
    int main()
    {
        int i;
        printf("%d\n", scanf("%d", &i));
        return 0;
    }
    1. 25

    2. 2

    3. 1

    4. 5

    Answer
  • 5.

    A structure can contain similar or dissimilar elements

    1. True

    2. False

    Answer
  • 6.

    Point out the error in the program?

    #include<stdio.h>
    
    int main()
    {
        struct emp
        {
            char name[20];
            float sal;
        };
        struct emp e[10];
        int i;
        for(i=0; i<=9; i++)
            scanf("%s %f", e[i].name, &e[i].sal);
        return 0;
    }
    1. Error: invalid structure member

    2. Error: Floating point formats not linked

    3. No error

    4. None of above

    Answer
  • 7.

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

    #include<stdio.h>
    
    int main()
    {
        printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
        return 0;
    }
    1. 8, 1, 4

    2. 4, 2, 8

    3. 4, 2, 4

    4. 10, 3, 4

    Answer
  • 8.

    What will be the output of the program in Turbo-C ?

    #include<stdio.h>
    
    int main()
    {
        int arr[5], i=-1, z;
        while(i<5)
            arr[i]=++i;
    
        for(i=0; i<5; i++)
            printf("%d, ", arr[i]);
    
        return 0;
    }
    1. 1, 2, 3, 4, 5,

    2. -1, 0, 1, 2, 3, 4

    3. 0, 1, 2, 3, 4,

    4. 0, -1, -2, -3, -4,

    Answer
  • 9.

    What does the following declaration mean?
    int (*ptr)[10];

    1. ptr is array of pointers to 10 integers

    2. ptr is a pointer to an array of 10 integers

    3. ptr is an array of 10 integers

    4. ptr is an pointer to array

    Answer
  • 10.

    Which of the following statements correct about k used in the below statement?
    char ****k;

    1. k is a pointer to a pointer to a pointer to a char

    2. k is a pointer to a pointer to a pointer to a pointer to a char

    3. k is a pointer to a char pointer

    4. k is a pointer to a pointer to a char

    Answer
  • 11.

    What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

    int main()
    {
        int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
        printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
        return 0;
    }
    1. 448, 4, 4

    2. 520, 2, 2

    3. 1006, 2, 2

    4. Error

    Answer
  • 12.

    What will be the output of the program?

    #include<stdio.h>
    #define PRINT(i) printf("%d,",i)
    
    int main()
    {
        int x=2, y=3, z=4;
        PRINT(x);
        PRINT(y);
        PRINT(z);
        return 0;
    }
    1. 2, 3, 4,

    2. 3, 3, 3,

    3. 4, 4, 4,

    Answer
  • 13.

    Which statement will you add in the following program to work it correctly?

    #include<stdio.h>
    int main()
    {
        printf("%f\n", log(36.0));
        return 0;
    }
    1. #include<conio.h>

    2. #include<math.h>

    3. #include<stdlib.h>

    4. #include<dos.h>

    Answer
  • 14.

    What do the following declaration signify?

    int (*ptr)[30];
    1. ptr is a pointer to an array of 30 integer pointers.

    2. ptr is a array of 30 integer function pointer.

    3. ptr is a array of 30 integer pointers.

    4. ptr is a array 30 pointers.

    Answer
  • 15.

    Point out the error in the following program.

    #include<stdio.h>
    #include<stdarg.h>
    void display(char *s, ...);
    int fun1();
    int fun2();
    
    int main()
    {
        int (*p1)();
        int (*p2)();
        p1 = fun1;
        p2 = fun2;
        display("IndiaBIX", p1, p2);
        return 0;
    }
    void display(char *s, ...)
    {
        int (*pp1)();
        int (*pp2)();
        va_list ptr;
    
        va_start(ptr, s);
        pp1 = va_arg(ptr, int(*)());
        (*pp1)();
    
        pp2 = va_arg(ptr, int(*)());
        (*pp2)();
    
    }
    int fun1()
    {
        printf("Hello");
    }
    int fun2()
    {
        printf("Hi");
    }
    1. Error: invalid function display() call

    2. Error: invalid va_start(ptr, s);

    3. Error: va_arg cannot extract function pointer from variable argument list.

    4. Error: Rvalue required for t

    Answer
  • 16.

    malloc() allocates memory from the heap and not from the stack.

    1. True

    2. False

    Answer
  • 17.

    Point out the correct statement which correctly allocates memory dynamically for 2D array following program?

    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
        int *p, i, j;
        /* Add statement here */
        for(i=0; i<3; i++)
        {
            for(j=0; j<4; j++)
            {
                p[i*4+j] = i;
                printf("%d", p[i*4+j]);
            }
        }
        return 0;
    }
    1. p = (int*) malloc(3, 4);

    2. p = (int*) malloc(3*sizeof(int));

    3. p = malloc(3*4*sizeof(int));

    4. p = (int*) malloc(3*4*sizeof(int));

    Answer
  • 18.

    What will be the output of the program (myprog.c) given below if it is executed from the command line?
    cmd> myprog one two three

    /* myprog.c */
    #include<stdio.h>
    #include<stdlib.h>
    
    int main(int argc, char **argv)
    {
        printf("%s\n", *++argv);
        return 0;
    }
    1. myprog

    2. one

    3. two

    4. three

    Answer
  • 19.

    According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?

    1. int main(int argc, char *argv[])
    2. int main(argc, argv)
      int argc; char *argv;
    3. int main()
      {
          int argc; char *argv;
      }
    4. None of above

    Answer
  • 20.

    If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program?

    #include<stdio.h>
    
    int main()
    {
        FILE *fs, *ft;
        char c[10];
        fs = fopen("source.txt", "r");
        c[0] = getc(fs);
        fseek(fs, 0, SEEK_END);
        fseek(fs, -3L, SEEK_CUR);
        fgets(c, 5, fs);
        puts(c);
        return 0;
    }
    1. friend

    2. frien

    3. end

    4. Error in fseek();

    Answer

© 2017 QuizBucket.org