C/C /C Multiple Choice Questions C Operators 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


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


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


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


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


Question:
Are logical operators sequence points?

1.True

2.False

3.Depends on the compiler

4.Depends on the standard


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


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


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


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

1.c = 1;

2. c = 2;

3.c = 3;

4. c = 4;


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)


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


Question:
Relational operators cannot be used on:

1.structure

2.long

3.strings

4.float


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


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

1.%, *, /, +, -

2.%, +, /, *, -

3. +, -, %, *, /

4.%, +, -, *, /


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


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


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


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


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


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


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


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


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


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


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


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


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.


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


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


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


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


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


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


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


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


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


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)


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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.=


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

1.char

2.short

3.float

4.int


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

1.a %= 10;

2. a /= 10

3.a |= 10

4.None of the mentioned


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

1.a *= 20;

2.a /= 30;

3.a %= 40;

4.a != 50;


More MCQS

  1. C++ Programming MCQS Set-1
  2. C++ Multiple Choice Questions Set-1
  3. C++ Multiple Choice Questions Set-2
  4. C++ Programming MCQS Set-2
  5. C++ Programming MCQS Set-3
  6. C++ Programming MCQS Set-4
  7. C++ (CPP) MCQ Question with Answer
  8. Advanced c++ multiple choice question(MCQS)
  9. OOPS Quiz Questions and Answers(MCQS)
  10. C Programming - MCQ Questions Set 1
  11. C Programming - MCQ Questions Set 2
  12. C Programming - MCQ Questions Set 3
  13. C Programming - MCQ Questions Set 4
  14. C Programming - MCQ Questions Set 5
  15. C++ programming language MCQ Questions Set 1
  16. C++ programming language MCQ Questions Set 2
  17. C++ programming language MCQ Questions Set 3
  18. C++ programming language MCQ Questions Set 4
  19. C++ programming language MCQ Questions Set 5
  20. C++ Programming -Constructors and Destructors
  21. C++ Programming -OOPS Concepts
  22. C++ Programming - References
  23. C++ Programming - Functions
  24. C MCQS:-The ABC of C
  25. C MCQS Interview Questions
  26. C++ Questions and Answers OOPs Basic Concepts
  27. C++ Questions and Answers Returning Objects
  28. C Programming MCQ Part 1
  29. C Programming MCQ
  30. Computer Science & Engineering C Multiple Choice Questions set 1
  31. Computer Science & Engineering C Multiple Choice Questions set 2
  32. C Multiple Choice Questions C Functions Set 1
  33. C Multiple Choice Questions C Functions Set 2
  34. C Multiple Choice Questions C Operators
  35. C Multiple Choice Questions & AnswersConditional Expressions
  36. C Multiple Choice Questions & Answers Data Types
  37. C Multiple Choice Questions & Answers File Access
  38. Computer Science & Engineering Cloud Computing MCQs Part 1
  39. CPP Programming MCQ Set 1
  40. CPP Programming MCQ Set 2
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!