C Language quiz questions

C Language interview questions

  • 1.

    On declaring a structure 0 bytes are reserved in memory.

    1. True

    2. False

    Answer
  • 2.

    Point out the error in the program?

    struct emp
    {
        int ecode;
        struct emp *e;
    };
    1. Error: in structure declaration

    2. Linker Error

    3. No Error

    4. None of above

    Answer
  • 3.

    What will be the output of the program ?

    #include<stdio.h>
    
        struct course
        {
            int courseno;
            char coursename[25];
        };
    int main()
    {
        struct course c[] = { {102, "Java"}, 
                              {103, "PHP"}, 
                              {104, "DotNet"}     };
    
        printf("%d ", c[1].courseno);
        printf("%s\n", (*(c+2)).coursename);
        return 0;
    }
    1. 103 DotNet

    2. 102 Java

    3. 103 PHP

    4. 104 DotNet

    Answer
  • 4.

    What will be the output of the program ?

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
        char sentence[80];
        int i;
        printf("Enter a line of text\n");
        gets(sentence);
        for(i=strlen(sentence)-1; i >=0; i--)
            putchar(sentence[i]);
        return 0;
    }
    1. The sentence will get printed in same order as it entered

    2. The sentence will get printed in reverse order

    3. Half of the sentence will get printed

    4. None of above

    Answer
  • 5.

    The library function used to reverse a string is

    1. strstr()

    2. strrev()

    3. revstr()

    4. strreverse()

    Answer
  • 6.

    What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?

    #include<stdio.h>
    
    int main()
    {
        int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
        printf("%u, %u\n", a+1, &a+1);
        return 0;
    }
    1. 65474, 65476

    2. 65480, 65496

    3. 65480, 65488

    4. 65474, 65488

    Answer
  • 7.

    Is this a correct way for NULL pointer assignment?
    int i=0;
    char *q=(char*)i;

    1. Yes

    2. No

    Answer
  • 8.

    What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        char *str;
        str = "%d\n";
        str++;
        str++;
        printf(str-2, 300);
        return 0;
    }
    1. No output

    2. 30

    3. 3

    4. 300

    Answer
  • 9.

    Macros have a local scope.

    1. True

    2. False

    Answer
  • 10.

    Are the following two statement same?

    1. a <= 20 ? (b = 30): (c = 30);
    2. (a <=20) ? b : (c = 30);
    1. Yes

    2. No

    Answer
  • 11.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        int i=4, j=-1, k=0, w, x, y, z;
        w = i || j || k;
        x = i && j && k;
        y = i || j &&k;
        z = i && j || k;
        printf("%d, %d, %d, %d\n", w, x, y, z);
        return 0;
    }
    1. 1, 1, 1, 1

    2. 1, 1, 0, 1

    3. 1, 0, 0, 1

    4. 1, 0, 1, 1

    Answer
  • 12.

    Which of the following statements are correct about the program?

    #include<stdio.h>
    int main()
    {
        int x = 30, y = 40;
        if(x == y)
            printf("x is equal to y\n");
    
        else if(x > y)
            printf("x is greater than y\n");
    
        else if(x < y)
            printf("x is less than y\n")
        return 0;
    }
    1. Error: Statement missing

    2. Error: Expression syntax

    3. Error: Lvalue required

    4. Error: Rvalue required

    Answer
  • 13.

    Point out the error, if any in the program.

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

    2. 200

    3. Error: L value required for b

    4. Garbage value

    Answer
  • 14.

    Which of the following cannot be checked in a switch-case statement?

    1. Character

    2. Integer

    3. Float

    4. enum

    Answer
  • 15.

    What will be the output of the program?

    #include<stdio.h>
    
    int main()
    {
        unsigned int res;
        res = (64 >>(2+1-2)) & (~(1<<2));
        printf("%d\n", res);
        return 0;
    }
    1. 32

    2. 64

    3. 0

    4. 128

    Answer
  • 16.

    What will be the output of the program?

    #define P printf("%d\n", -1^~0);
    #define M(P) int main()\
                 {\
                    P\
                    return 0;\
                 }
    M(P)
    1. 1

    2. 0

    3. -1

    4. 2

    Answer
  • 17.

    To scan a and b given below, which of the following scanf() statement will you use?

    #include<stdio.h>
    
    float a;
    double b;
    1. scanf("%f %f", &a, &b);

    2. scanf("%Lf %Lf", &a, &b);

    3. scanf("%f %Lf", &a, &b);

    4. scanf("%f %lf", &a, &b);

    Answer
  • 18.

    Can we have an array of bit fields?

    1. Yes

    2. No

    Answer
  • 19.

    Nested unions are allowed

    1. True

    2. False

    Answer
  • 20.

    What will be the output of the program ?

    #include<stdio.h>
    
    int main()
    {
        union var
        {
            int a, b;
        };
        union var v;
        v.a=10;
        v.b=20;
        printf("%d\n", v.a);
        return 0;
    }
    1. 10

    2. 20

    3. 30

    4. 0

    Answer

© 2017 QuizBucket.org