C Language quiz questions

C Language interview questions

  • 1.

    What will be the output of the program ?

    #include<stdio.h>
    void swap(char *, char *);
    int main()
    {
        char *pstr[2] = {"Hello", "IndiaBIX"};
        swap(pstr[0], pstr[1]);
        printf("%s\n%s", pstr[0], pstr[1]);
        return 0;
    }
    void swap(char *t1, char *t2)
    {
        char *t;
        t=t1;
        t1=t2;
        t2=t;
    }
    1. IndiaBIX
      Hello

    2. Address of "Hello" and "IndiaBIX"

    3. Hello
      IndiaBIX

    4. Iello
      HndiaBIX

    Answer
  • 2.

    What will be the output of the program ?

    #include<stdio.h>
    int main()
    {
        char p[] = "%d\n";
        p[1] = 'c';
        printf(p, 65);
        return 0;
    }
    1. A

    2. a

    3. c

    4. 65

    Answer
  • 3.

    What will be the output of the program ?

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char str1[20] = "Hello", str2[20] = " World";
        printf("%s\n", strcpy(str2, strcat(str1, str2)));
        return 0;
    }
    1. Hello

    2. World

    3. Hello World

    4. WorldHello

    Answer
  • 4.

    Which statement will you add to the following program to ensure that the program outputs "IndiaBIX" on execution?

    #include<stdio.h>
    int main()
    {
        char s[] = "IndiaBIX";
        char t[25];
        char *ps, *pt;
        ps = s;
        pt = t;
        while(*ps)
            *pt++ = *ps++;
        /* Add a statement here */
        printf("%s\n", t);
        return 0;
    }
    1. *pt='';

    2. pt='\0';

    3. pt='\n';

    4. *pt='\0';

    Answer
  • 5.

    Preprocessor directive #undef can be used only on a macro that has been #define earlier

    1. True

    2. False

    Answer
  • 6.

    What will be the output of the program?

    #include<stdio.h>
    #define SQUARE(x) x*x
    int main()
    {
        float s=10, u=30, t=2, a;
        a = 2*(s-u*t)/SQUARE(t);
        printf("Result = %f", a);
        return 0;
    }
    1. Result = -100.000000

    2. Result = -25.000000

    3. Result = 0.000000

    4. Result = 100.000000

    Answer
  • 7.

    Point out the error in the program

    
    f(int a, int b)
    {
        int a;
        a = 20;
        return a;
    }
    1. Missing parenthesis in return statement

    2. The function should be defined as int f(int a, int b)

    3. Redeclaration of a

    4. None of above

    Answer
  • 8.

    What will be the output of the program?

    #include<stdio.h>
    int sumdig(int);
    int main()
    {
        int a, b;
        a = sumdig(123);
        b = sumdig(123);
        printf("%d, %d\n", a, b);
        return 0;
    }
    int sumdig(int n)
    {
        int s, d;
        if(n!=0)
        {
            d = n%10;
            n = n/10;
            s = d+sumdig(n);
        }
        else
            return 0;
        return s;
    }
    1. 4, 4

    2. 3, 3

    3. 6, 6

    4. 12, 12

    Answer
  • 9.

    float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?

    1. ABCD

    2. DCBA

    3. 0xABCD

    4. Depends on big endian or little endian architecture

    Answer
  • 10.

    If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)?

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        float a=5.375;
        char *p;
        int i;
        p = (char*)&a;
        for(i=0; i<=3; i++)
            printf("%02x\n", (unsigned char)p[i]);
        return 0;
    }
    1. 40 AC 00 00

    2. 04 CA 00 00

    3. 00 00 AC 40

    4. 00 00 CA 04

    Answer
  • 11.

    Associativity has no role to play unless the precedence of operator is same.

    1. True

    2. False

    Answer
  • 12.

    In which order do the following gets evaluated

    1. Relational
    2. Arithmetic
    3. Logical
    4. Assignment
    1. 2134

    2. 1234

    3. 4321

    4. 3214

    Answer
  • 13.

    Which of the following correctly shows the hierarchy of arithmetic operations in C?

    1. / + * -

    2. * - / +

    3. / * + -

    4. + - / *

    Answer
  • 14.

    short integer is at least 16 bits wide and a long integer is at least 32 bits wide.

    1. True

    2. False

    Answer
  • 15.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        int i;
        char c;
        for(i=1; i<=5; i++)
        {
            scanf("%c", &c); /* given input is 'a' */
            printf("%c", c);
            ungetc(c, stdin);
        }
        return 0;
    }
    1. aaaa

    2. aaaaa

    3. Garbage value.

    4. Error in ungetc statement.

    Answer
  • 16.

    Input/output function prototypes and macros are defined in which header file?

    1. conio.h

    2. stdlib.h

    3. stdio.h

    4. dos.h

    Answer
  • 17.

    Point out the error in the program.

    #include<stdio.h>
    const char *fun();
    int main()
    {
        char *ptr = fun();
        return 0;
    }
    const char *fun()
    {
        return "Hello";
    }
    1. Error: Lvalue required

    2. Error: cannot convert 'const char *' to 'char *'.

    3. No error and No output

    4. None of above

    Answer
  • 18.

    Point out the error in the program (in Turbo-C).

    #include<stdio.h>
    #define MAX 128
    int main()
    {
        const int max=128;
        char array[max];
        char string[MAX];
        array[0] = string[0] = 'A';
        printf("%c %c\n", array[0], string[0]);
        return 0;
    }
    1. Error: unknown max in declaration/Constant expression required

    2. Error: invalid array string

    3. None of above

    4. No error. It prints A A

    Answer
  • 19.

    What will be the output of the program?

    #include<stdio.h>
    int main()
    {
        const int x=5;
        const int *ptrx;
        ptrx = &x;
        *ptrx = 10;
        printf("%d\n", x);
        return 0;
    }
    1. 5

    2. 10

    3. Error

    4. Garbage value

    Answer
  • 20.

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

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

    2. f

    3. m

    4. y

    Answer

© 2017 QuizBucket.org