C Language quiz questions

C Language interview questions

  • 1.

    Bit fields CANNOT be used in union.

    1. True

    2. False

    Answer
  • 2.

    What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        int i=4, j=8;
        printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
        return 0;
    }
    1. 12, 12, 12

    2. 112, 1, 12

    3. 32, 1, 12

    4. -64, 1, 12

    Answer
  • 3.

    What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        char str[] = "Nagpur";
        str[0]='K';
        printf("%s, ", str);
        str = "Kanpur";
        printf("%s", str+1);
        return 0;
    }
    1. Kagpur, Kanpur

    2. Nagpur, Kanpur

    3. Kagpur, anpur

    4. Error

    Answer
  • 4.

    If char=1, int=4, and float=4 bytes size, What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        char ch = 'A';
        printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
        return 0;
    }
    1. 1, 2, 4

    2. 1, 4, 4

    3. 2, 2, 4

    4. 2, 4, 8

    Answer
  • 5.

    The library function used to find the last occurrence of a character in a string is

    1. strnstr()

    2. laststr()

    3. strrchr()

    4. strstr()

    Answer
  • 6.

    Which of the following statements are correct about an array?

    1: The array int num[26]; can store 26 elements.
    2: The expression num[1] designates the very first element in the array.
    3: It is necessary to initialize the array at the time of declaration.
    4: The declaration num[SIZE] is allowed if SIZE is a macro.
    1. 1

    2. 1,4

    3. 2,3

    4. 2,4

    Answer
  • 7.

    Will the program compile in Turbo C?

    #include<stdio.h>
    int main()
    {
        int a=10, *j;
        void *k;
        j=k=&a;
        j++;
        k++;
        printf("%u %u\n", j, k);
        return 0;
    }
    1. Yes

    2. No

    Answer
  • 8.

    Which of the statements is correct about the program?

    #include<stdio.h>
    
    int main()
    {
        float a=3.14;
        char *j;
        j = (char*)&a;
        printf("%d\n", *j);
        return 0;
    }
    1. It prints ASCII value of the binary number present in the first byte of a float variable a.

    2. It prints character equivalent of the binary number present in the first byte of a float variable a.

    3. It will print 3

    4. It will print a garbage value

    Answer
  • 9.

    Which of the following statements are correct about the function?

    long fun(int num)
    {
        int i;
        long f=1;
        for(i=1; i<=num; i++)
            f = f * i;
        return f;
    }
    1. The function calculates the value of 1 raised to power num.

    2. The function calculates the square root of an integer

    3. The function calculates the factorial value of an integer

    4. None of above

    Answer
  • 10.

    The keyword used to transfer control from a function back to the calling function is

    1. switch

    2. goto

    3. go back

    4. return

    Answer
  • 11.

    Point out the error in the following 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. Suspicious pointer conversion

    2. Floating point formats not linked (Run time error)

    3. Cannot use scanf() for structures

    4. Strings cannot be nested inside structures

    Answer
  • 12.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        int k, num=30;
        k = (num>5 ? (num <=10 ? 100 : 200): 500);
        printf("%d\n", num);
        return 0;
    }
    1. 200

    2. 30

    3. 100

    4. 500

    Answer
  • 13.

    Which of the following statements are correct about the below C-program?

    #include<stdio.h>
    int main()
    {
        int x = 10, y = 100%90, i;
        for(i=1; i<10; i++)
        if(x != y);
            printf("x = %d y = %d\n", x, y);
        return 0;
    }
    1. The printf() function is called 10 times.

    2. The program will produce the output x = 10 y = 10

    3. The ; after the if(x!=y) will NOT produce an error.

    4. The program will not produce output.

    Answer
  • 14.

    In the given below code, the function fopen()uses "r" to open the file “source.txt” in binary mode for which purpose?

    #include<stdio.h>
    
    int main ()
    {
       FILE *fp;
       
       fp = fopen("source.txt", "r");
       return 0;
    }

     

    1. For reading

    2. For reading and writing

    3. For creating a new file "source.txt" for reading

    4. For creating a new file "source.txt" for writing

    Answer
  • 15.

    What is the output of the following program?

    #include<stdio.h>
    
    void main()
    {
       char s[] = "C++";
       
       printf("%s ",s);
       s++;
       printf("%s",s);
    }

     

    1. C++ C++

    2. C++ ++

    3. ++ ++

    4. Compile error

    Answer
  • 16.

    Does both the loops in the following programs prints the correct string length?

    #include<stdio.h>
    
    main()
    {
       int i;
       char s[] = "hello";
    
       for(i=0; s[i]; ++i);
          printf("%d ", i);
    
       i=0; 
       while(s[i++]);
          printf("%d ", i);
    }

     

    1. Yes, both the loops prints the correct length

    2. Only for loop prints the correct length

    3. Only while loop prints the correct length

    4. Compile error in the program.

    Answer
  • 17.

    Identify the invalid constant used in fseek() function as ‘whence’ reference.

    1. SEEK_SET

    2. SEEK_CUR

    3. SEEK_BEG

    4. SEEK_END

    Answer
  • 18.

    What is the size of the following union definition?

    #include<stdio.h>
    
    union abc { 
        char a,b,c,d,e,f,g,h; 
        int i;
    }abc;
    
    main()
    {
       printf( "%d", sizeof( abc ));
    }

     

    1. 1

    2. 2

    3. 4

    4. 8

    Answer
  • 19.

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

    1. strnset()

    2. scanf()

    3. strchr()

    4. gets()

    Answer
  • 20.

    What will be the resultant of the given below program?

    #include<stdio.h>
    #include<stdarg.h>
    
    Void fun(char *msg, ...);
    int main ()
    {
       fun("IndiaMAX", 1, 4, 7, 11, 0);
       return 0;
    }
       void fun(char *msg, ...)  
    {
    va_list ptr;{
       int num;
       va_start(ptr, msg);
       num = va_arg(ptr, int);    
       num = va_arg(ptr, int);
       printf("%d", num);
    }

     

    1. IndiaMAX 1, 7, 11, 0

    2. IndiaMAX 1, 7

    3. Only 4

    4. 1, 7, 11, 0

    Answer

© 2017 QuizBucket.org