C/C / Sample Test,Sample questions

Question:
 What is the output of this C code?

    int main()
    {
        int a = 1, b = 1, d = 1;
        printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);
    }

1.15, 4, 5

2.9, 6, 9

3. 9, 3, 5

4.6, 4, 6

Posted Date:-2022-03-21 06:15:56


Question:
 What is the output of this C code?

    int main()
    {
        int a = 20, b = 15, c = 5;
        int d;
        d = a == (b + c);
        printf("%d", d);
    }
A. 1

1.1

2. 40

3.10

4.5

Posted Date:-2022-03-21 05:35:17


Question:
 What is the output of this C code?

    int main()
    {
        int a = 20;
        double b = 15.6;
        int c;
        c = a + b;
        printf("%d", c);
    }

1.35

2.36

3.35.6

4.30

Posted Date:-2022-03-21 05:34:27


Question:
 What is the output of this C code?

    void main()
    {
        char a = 'a';
        int x = (a % 10)++;
        printf("%d
", x);
    }

1.6

2.Junk value

3.Compile time error

4.7

Posted Date:-2022-03-21 05:38:14


Question:
 What is the output of this C code?

    void main()
    {
        int x = 4;
        int *p = &x;
        int *k = p++;
        int r = p - k;
        printf("%d", r);
    }

1.4

2.8

3.1

4.Run time error

Posted Date:-2022-03-21 06:02:54


Question:
Are logical operators sequence points?

1.True

2.False

3.Depends on the compiler

4.Depends on the standard

Posted Date:-2022-03-21 07:02:50


Question:
Comment on the output of this C code?

    int main()
    {
        int i = 2;
        int i = i++ + i;
        printf("%d
", i);
    }

1.= operator is not a sequence point

2.++ operator may return value with or without side effects

3. it can be evaluated as (i++)+i or i+(++i)

4.Both a and b

Posted Date:-2022-03-21 06:21:14


Question:
Comment on the output of this C code?

    int main()
    {
        int i, n, a = 4;
        scanf("%d", &n);
        for (i = 0; i < n; i++)
            a = a * 2;
    }

1.Logical Shift left

2.No output

3.Arithmetic Shift right

4.bitwise exclusive OR

Posted Date:-2022-03-21 06:00:22


Question:
Does logical operators in C language are evaluated with short circuit?

1.True

2.False

3.Depends on the compiler

4.depends on the standard

Posted Date:-2022-03-21 07:03:17


Question:
for c = 2, value of c after c <<= 1;

1.c = 1;

2. c = 2;

3.c = 3;

4. c = 4;

Posted Date:-2022-03-21 05:48:32


Question:
For which of the following, "PI++; code will fail?

1.#define PI 3.14

2.char *PI = A";

3.float PI = 3.14;

4.Both (A) and (B)

Posted Date:-2022-03-21 06:16:52


Question:
Operation "a = a * b + a can also be written as:

1. a *= b + 1

2.(c = a * b)!=(a = c + a)

3.a = (b + 1)* a;

4.All of the mentioned

Posted Date:-2022-03-21 05:47:41


Question:
Relational operators cannot be used on:

1.structure

2.long

3.strings

4.float

Posted Date:-2022-03-21 07:27:01


Question:
Result of a logical or relational expression in C is?

1.True or False

2.0 or 1

3.0 if expression is false and any positive number if expression is true

4.None of the mentioned

Posted Date:-2022-03-21 07:04:04


Question:
The precedence of arithmetic operators is (from highest to lowest)?

1.%, *, /, +, -

2.%, +, /, *, -

3. +, -, %, *, /

4.%, +, -, *, /

Posted Date:-2022-03-21 05:29:31


Question:
What is the difference between the following 2 codes?

//Program 1
    int main()
    {
        int d, a = 1, b = 2;
        d =  a++ + ++b;
        printf("%d %d %d", d, a, b);
    }


 //Program 2
    int main()
    {
        int d, a = 1, b = 2;
        d =  a++ + ++b;
        printf("%d %d %d", d, a, b);
    }

1.No difference as space doesn't make any difference, values of a, b, d are same in both the case

2.No difference as space doesn't make any difference, values of a, b, d are different

3.Program 1 has syntax error, program 2 is not

4.Program 2 has syntax error, program 1 is not

Posted Date:-2022-03-21 06:12:06


Question:
What is the final value of j in the below code?

    int main()
    {
        int i = 0, j = 0;
        if (i && (j = i + 10))
            //do something
            ;
    }

1.0

2.10

3.Depends on the compiler

4.Depends on language standard

Posted Date:-2022-03-21 07:01:35


Question:
What is the output of this C code?


    int main()
    {
        int i = 0;
        int x = i++, y = ++i;
        printf("%d % d
", x, y);
        return 0;
    }

1.0, 2

2.0, 1

3.1, 2

4.Undefined

Posted Date:-2022-03-21 06:24:55


Question:
What is the output of this C code?

    int main()
    {
        if (~0 == 1)
            printf("yes
");
        else
            printf("no
");
    }

1.Yes

2.No

3.Compile time error

4.undefined

Posted Date:-2022-03-21 06:07:39


Question:
What is the output of this C code?

    int main()
    {
        if (7 & 8)
        printf("Honesty");
            if ((~7 & 0x000f) == 8)
                printf("is the best policy
");
    }

1.Honesty is the best policy

2.Honesty

3.is the best policy

4. No output

Posted Date:-2022-03-21 05:54:47


Question:
What is the output of this C code?

    int main()
    {
        int a = 1, b = 1, c;
        c = a++ + b;
        printf("%d, %d", a, b);
    }

1.a = 1, b = 1

2.a = 2, b = 1

3.a = 1, b = 2

4. a = 2, b = 2

Posted Date:-2022-03-21 06:13:19


Question:
What is the output of this C code?

    int main()
    {
        int a = 1, b = 2;
        a += b -= a;
        printf("%d %d", a, b);
    }

1.1 1

2.1 2

3. 2 1

4.2 2

Posted Date:-2022-03-21 05:49:21


Question:
What is the output of this C code?

    int main()
    {
        int a = 10, b = 10;
        if (a = 5)
        b--;
        printf("%d, %d", a, b--);
    }

1.a = 10, b = 9

2.a = 10, b = 8

3.a = 5, b = 9

4.a = 5, b = 8

Posted Date:-2022-03-21 06:17:51


Question:
What is the output of this C code?

    int main()
    {
        int a = 10, b = 5, c = 3;
        b != !a;
        c = !!a;
        printf("%d	%d", b, c);
    }

1.5 1

2.0 3

3.5 3

4.1 1

Posted Date:-2022-03-21 07:05:39


Question:
What is the output of this C code?

    int main()
    {
        int a = 10;
        if (a == a--)
            printf("TRUE 1	");
        a = 10;
        if (a == --a)
            printf("TRUE 2	");
    }

1.TRUE 1

2.TRUE 2

3.TRUE 1 TRUE 2

4.No output

Posted Date:-2022-03-21 07:09:00


Question:
What is the output of this C code?

    int main()
    {
        int a = 2;
        if (a >> 1)
           printf("%d
", a);
    }

1.0

2.1

3.2

4.No output

Posted Date:-2022-03-21 05:57:17


Question:
What is the output of this C code?

    int main()
    {
        int a = 2;
        if (a >> 1)
           printf("%d
", a);
    }

1.0

2.0

3.1

4.No output

Posted Date:-2022-03-21 05:59:25


Question:
What is the output of this C code?

    int main()
    {
        int a = 4, n, i, result = 0;
        scanf("%d", n);
        for (i = 0;i < n; i++)
        result += a;
    }

1.Addition of a and n

2.Subtraction of a and n.

3.Multiplication of a and n

4.Division of a and n.

Posted Date:-2022-03-21 05:50:27


Question:
What is the output of this C code?

    int main()
    {
        int c = 2 ^ 3;
        printf("%d
", c);
    }

1.1

2.8

3.9

4.0

Posted Date:-2022-03-21 05:52:04


Question:
What is the output of this C code?

    int main()
    {
        int i = -5;
        int k = i %4;
        printf("%d
", k);
    }

1. Compile time error

2.-1

3.1

4.None

Posted Date:-2022-03-21 05:21:24


Question:
What is the output of this C code?

    int main()
    {
        int i = 0;
        int j = i++ + i;
        printf("%d
", j);
    }

1.0

2.1

3.2

4.Compile time error

Posted Date:-2022-03-21 06:18:40


Question:
What is the output of this C code?

    int main()
    {
        int i = 1;
        if (i++ && (i == 1))
            printf("Yes
");
        else
            printf("No
");
    }

1.Yes

2.No

3.Depends on the compiler

4.Depends on the standard

Posted Date:-2022-03-21 07:02:13


Question:
What is the output of this C code?

    int main()
    {
        int i = 10;
        int *p = &i;
        printf("%d
", *p++);
    }

1.10

2.11

3.Garbage value

4.Address of i

Posted Date:-2022-03-21 06:27:04


Question:
What is the output of this C code?

    int main()
    {
        int i = 2;
        int j = ++i + i;
        printf("%d
", j);
    }

1.6

2.5

3.4

4.Compile time error

Posted Date:-2022-03-21 06:19:12


Question:
What is the output of this C code?

    int main()
    {
        int i = 5;
        int l = i / -4;
        int k = i % -4;
        printf("%d %d
", l, k);
        return 0;
    }

1.Compile time error

2. -1 1

3.1 -1

4.Run time error

Posted Date:-2022-03-21 05:22:15


Question:
What is the output of this C code?

    int main()
    {
        int i = 7;
        i = i / 4;
        printf("%d
", i);
       return 0;
    }

1.Run time error

2.1

3.3

4.Compile time error

Posted Date:-2022-03-21 05:23:35


Question:
What is the output of this C code?

    int main()
    {
        int x = -2;
        if (!0 == 1)
            printf("yes
");
        else
            printf("no
");
    }

1.Yes

2.No

3.Run time error

4.undefined

Posted Date:-2022-03-21 06:08:43


Question:
What is the output of this C code?

    int main()
    {
        int x = -2;
        x = x >> 1;
        printf("%d
", x);
    }

1.1

2. -1

3. 2 ^ 31 "“ 1 considering int to be 4 bytes

4.Either (b) or (c)

Posted Date:-2022-03-21 06:06:50


Question:
What is the output of this C code?

    int main()
    {
        int x = 1, y = 0, z = 3;
        x > y ? printf("%d", z) : return z;
    }

1.3

2.1

3.Compile time error

4.Run time error

Posted Date:-2022-03-21 06:54:56


Question:
What is the output of this C code?

    int main()
    {
        int x = 2, y = 1;
        x *= x + y;
        printf("%d
", x);
        return 0;
    }

1.5

2.6

3.Undefined behaviour

4.Compile time error

Posted Date:-2022-03-21 05:42:40


Question:
What is the output of this C code?

    int main()
    {
        int x = 2, y = 2;
        x /= x / y;
        printf("%d
", x);
        return 0;
    }

1.2

2.1

3.0.5

4.Undefined behaviour

Posted Date:-2022-03-21 05:43:48


Question:
What is the output of this C code?

    int main()
    {
        int x = 2;
        x = x << 1;
        printf("%d
", x);

1.4

2.1

3.Depends on the compiler

4.Depends on the endianness of the machine

Posted Date:-2022-03-21 06:06:04


Question:
What is the output of this C code?

    int main()
    {
        int y = 0;
        if (1 |(y = 1))
            printf("y is %d
", y);
        else
            printf("%d
", y);
 
    }

1.1

2.0

3.Run time error

4.undefined

Posted Date:-2022-03-21 06:09:34


Question:
What is the output of this C code?

    int main()
    {
        int y = 1;
        if (y & (y = 2))
            printf("true %d
");
        else
            printf("false %d
");
 
    }

1.true 2

2.false 2

3. Either option a or option b

4.true 1

Posted Date:-2022-03-21 06:11:07


Question:
What is the output of this C code?

    int main()
    {
        unsigned int a = 10;
        a = ~a;
        printf("%d
", a);
    }

1.-9

2.-10

3.-11

4.10

Posted Date:-2022-03-21 05:52:37


Question:
What is the output of this C code?

    void main()
    {
        1 < 2 ? return 1: return 2;
    }

1.returns 1

2.returns 2

3.varies

4.Compile time error

Posted Date:-2022-03-21 05:39:36


Question:
What is the output of this C code?

    void main()
    {
        int a = -5;
        int k = (a++, ++a);
        printf("%d
", k);
    }

1.-3

2.-5

3.4

4.Undefined

Posted Date:-2022-03-21 06:05:02


Question:
What is the output of this C code?

    void main()
    {
        int a = -5;
        int k = (a++, ++a);
        printf("%d
", k);
    }
A. -4B. -5C. 4D. -3

1.4

2.8

3.1

4.Run time error

Posted Date:-2022-03-21 06:47:09


Question:
What is the output of this C code?

    void main()
    {
        int a = 5, b = -7, c = 0, d;
        d = ++a && ++b || ++c;
        printf("
%d%d%d%d", a,  b, c, d);
    }

1.6 -6 0 0

2.6 -5 0 1

3.-6 -6 0 1

4. 6 -6 0 1

Posted Date:-2022-03-21 06:37:32


Question:
What is the output of this C code?

    void main()
    {
        int a = 5, b = -7, c = 0, d;
        d = ++a && ++b || ++c;
        printf("
%d%d%d%d", a, b, c, d);
    }

1.6 -6 0 0

2.6 -5 0 1

3.-6 -6 0 1

4.6 -6 0 1

Posted Date:-2022-03-21 06:04:08


Question:
What is the output of this C code?

    void main()
    {
        int a = 5;
        int b = ++a + a++ + --a;
        printf("Value of b is %d", b);
    }

1. Value of x is 16

2.Value of x is 21

3.Value of x is 15

4.Undefined behaviour

Posted Date:-2022-03-21 05:28:33


Question:
What is the output of this C code?

    void main()
    {
        int k = 8;
        int x = 0 == 1 && k++;
        printf("%d%d
", x, k);
    }

1.0 9

2. 0 8

3. 1 9

4. 1 8

Posted Date:-2022-03-21 05:37:12


Question:
What is the output of this C code?

    void main()
    {
        int x = 0, y = 2, z = 3;
        int a = x & y | z;
        printf("%d", a);
    }

1.3

2.0

3.2

4.Run time error

Posted Date:-2022-03-21 06:56:10


Question:
What is the output of this C code?

    void main()
    {
        int x = 0;
        if (x = 0)
            printf("Its zero
");
        else
            printf("Its not zero
");
    }

1.ts not zero

2. Its zero

3.Run time error

4.None

Posted Date:-2022-03-21 05:36:18


Question:
What is the output of this C code?

    void main()
    {
        int x = 1, y = 0, z = 5;
        int a = x && y && z++;
        printf("%d", z);
    }

1.6

2.5

3.0

4.Varies

Posted Date:-2022-03-21 06:53:57


Question:
What is the output of this C code?

    void main()
    {
        int x = 1, y = 0, z = 5;
        int a = x && y || z++;
        printf("%d", z);
    }

1.6

2.5

3.0

4.Varies

Posted Date:-2022-03-21 06:50:55


Question:
What is the output of this C code?

    void main()
    {
        int x = 1, z = 3;
        int y = x << 3;
        printf(" %d
", y);
    }

1.-2147483648

2.-1

3.Run time error

4. 8

Posted Date:-2022-03-21 06:55:36


Question:
What is the output of this C code?

    void main()
    {
        int x = 4, y, z;
        y = --x;
        z = x--;
        printf("%d%d%d", x,  y, z);
    }

1. 3 2 3

2. 2 3 3

3.3 2 .3

4. 2 3 4

Posted Date:-2022-03-21 06:31:02


Question:
What is the output of this C code?

    void main()
    {
        int x = 4, y, z;
        y = --x;
        z = x--;
        printf("%d%d%d", x, y, z);
    }

1.3 2 3

2.2 2 3

3.3 2 2

4.2 3 3

Posted Date:-2022-03-21 06:02:12


Question:
What is the output of this C code?

    void main()
    {
        int x = 4;
        int *p = &x;
        int *k = p++;
        int r = p - k;
        printf("%d", r);
    }

1.48

2.8

3.1

4.Run time error

Posted Date:-2022-03-21 06:33:32


Question:
What is the output of this C code?

    void main()
    {
        int x = 4.3 % 2;
        printf("Value of x is %d", x);
    }

1.Value of x is 1.3

2. Value of x is 2

3.Value of x is 0.3

4.Compile time error

Posted Date:-2022-03-21 05:26:20


Question:
What is the output of this C code?

    void main()
    {
        int x = 97;
        int y = sizeof(x++);
        printf("X is %d", x);
    }

1.X is 97

2. X is 94

3. X is 99

4.Run time error

Posted Date:-2022-03-21 06:28:12


Question:
What is the output of this C code?

    void main()
    {
        int x = 97;
        int y = sizeof(x++);
        printf("x is %d", x);
    }

1. x is 97

2. x is 98

3. x is 99

4.Run time error

Posted Date:-2022-03-21 06:01:19


Question:
What is the output of this C code?

    void main()
    {
        int y = 3;
        int x = 7 % 4 * 3 / 2;
        printf("Value of x is %d", x);
    }

1.Value of x is 1

2.Value of x is 2

3.Value of x is 3

4.Compile time error

Posted Date:-2022-03-21 05:27:27


Question:
What is the output of this C code?

    void main()
    {
        unsigned int x = -5;
        printf("%d", x);
    }

1.Run time error

2.Varies

3.-5

4.5

Posted Date:-2022-03-21 05:41:06


Question:
What is the output of this C code?

    void main()
    {
        unsigned int x = -5;
        printf("%d", x);
    }

1.Run time error

2.Varies

3.-5

4.5

Posted Date:-2022-03-21 05:41:30


Question:
What is the type of the below assignment expression if x is of type float, y is of type int?
        y = x + y;

1. int

2. float

3.There is no type for an assignment expression

4.double

Posted Date:-2022-03-21 05:46:06


Question:
What is the value of the below assignment expression
      (x = foo())!= 1 considering foo() returns 2

1.2

2.True

3.1

4.0

Posted Date:-2022-03-21 05:46:50


Question:
What is the value of x in this C code?

    void main()
    {
        int x = 4 *5 / 2 + 9;
    }

1.6.75

2.1.85

3.19

4.3

Posted Date:-2022-03-21 05:25:33


Question:
What will be the value of d in the following program?

    int main()
    {
        int a = 10, b = 5, c = 5;
        int d;
        d = b + c == a;
        printf("%d", d);
    }
A

1.Syntax error

2.1

3.5

4.10

Posted Date:-2022-03-21 07:05:06


Question:
Which among the following is NOT a logical or relational operator?
A. !=B. ==C. ||D. =
Which among the following is NOT a logical or relational operator?

1.!=

2.==

3.||

4.=

Posted Date:-2022-03-21 07:07:06


Question:
Which of the following data type will throw an error on modulus operation(%)?

1.char

2.short

3.float

4.int

Posted Date:-2022-03-21 05:32:36


Question:
Which of the following is an invalid assignment operator?

1.a %= 10;

2. a /= 10

3.a |= 10

4.None of the mentioned

Posted Date:-2022-03-21 05:51:16


Question:
Which of the following is not an arithmetic operation?

1.a *= 20;

2.a /= 30;

3.a %= 40;

4.a != 50;

Posted Date:-2022-03-21 05:30:23


More MCQS

  1. help4info.com
  2. help4info.com
  3. help4info.com
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!