Machine-translated by Google. Questions are authored in English.
Top

Expressions Questions and Answers

71.

What is the value of x after executing the following statement?

int x = 011 | 0x10;

Answer: C

Correct answer: 25

The two literals are in different bases: a leading 0 marks octal and 0x marks hexadecimal.

\[ 011_8 = 9 = 01001_2, \quad 0x10 = 16 = 10000_2 \]

The bitwise OR sets every bit that is set in either, giving \(11001_2 = 25\).

Please log in or register to report this question.

72.

What is the output of this C code?    

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

 

Answer: D

Correct answer: 6 -6 0 1

Evaluate left to right, remembering that any non-zero value is true.

  • ++a makes a 6, which is true.
  • ++b makes b -6 - non-zero, so also true.
  • The && is therefore true, so || short-circuits and ++c never runs: c stays 0.
  • d gets the value of the whole expression, 1.

Output: 6 -6 0 1.

Please log in or register to report this question.

73.

Which is not a storage class?

Answer: B

Correct answer: Struct

The storage classes in C are auto, register, static, extern and typedef - typedef being grouped with them by the grammar even though it names a type rather than allocating storage. struct is not among them: it introduces a type, and a structure variable still needs a storage class of its own.

Please log in or register to report this question.

74.

For the following statement find the values generated for p and q?

int p = 0, q = 1;
p = q++;
p = ++q;
p = q--;
p = --q;

Value of p & q are

Answer: A

Correct answer: 1 1

Follow the four statements from p = 0, q = 1:

  • p = q++; - p gets the old 1; q becomes 2.
  • p = ++q; - q becomes 3 and p gets 3.
  • p = q--; - p gets the old 3; q becomes 2.
  • p = --q; - q becomes 1 and p gets 1.

So both end at 1.

Please log in or register to report this question.

75.

What is the output of this C code?    

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

 

Answer: A

Correct answer: -3

The comma operator evaluates its left operand, discards the result, then evaluates the right operand and yields that. So a++ takes a to -4, then ++a takes it to -3 and produces -3. k is therefore -3. There is a sequence point at the comma, so this is well defined.

Please log in or register to report this question.

76.

What is the output of this C code? 

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

 

Answer: B

Correct answer: -1

-2 is all ones followed by a zero: \(\ldots 1110\). Shifting right on a signed negative value is an arithmetic shift in every mainstream implementation, so the sign bit is copied in from the left and the result is \(\ldots 1111 = -1\). Arithmetically it is a division by two, rounding toward negative infinity.

Please log in or register to report this question.

77.

What is the output of this C code?

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

 

Answer: D

Correct answer: Compile time error

The % operator is defined only for integer operands. 4.3 is a double, so 4.3 % 2 is rejected at compile time - there is no implicit conversion to rescue it. For a floating-point remainder you would call fmod(4.3, 2) from <math.h>.

Please log in or register to report this question.

78.

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

Answer: A

Correct answer: int

The type of an assignment expression is the type of its left operand, after the right-hand side has been converted to it. Here x + y is computed as a float, then converted to int for the assignment to y - so the expression y = x + y has type int, and the fractional part is lost.

Please log in or register to report this question.

79.

What will be the output of the following program?

#include <stdio.h>

Void f(static int*, extern int);
Static int b = 12;
Int main()
{
Static int a[5];
Register int I;
For(I = 0; I < 2> A[i++] = 2 * i++;
F(a, b);
For(I = 0; I < 2> Printf(“%d”, b++);
Return 0;
}
Void f (static int *x, extern int y)
{
Register int I;
For(I = 0; I < 2> *(++x +1) + = 2;
Y + = 2;
}

 

Answer: C

Correct answer: 0 12, though the listing this depends on has been destroyed

The program text in this record cannot be trusted. Every identifier has been capitalised - Void, Static, Int, For, Printf - which alone would stop it compiling, since C is case sensitive; the quotation marks in the printf call have become typographic quotes; and each of the three for loops has lost its body, ending at I < 2> where the loop condition, the increment and the statement should be. That last damage is characteristic: a stray < in stored HTML swallows everything up to the next >, and here it has taken the working part of every loop with it. One thing can still be said about the original. It declares void f(static int*, extern int);, and neither of those storage classes may be applied to a function parameter - C permits only register there - so the program the question was built on would not have compiled either. The keyed answer is “0 12”, which is consistent with a program whose array elements are never usefully assigned and whose file-scope b is unchanged by the call, since y += 2 inside f alters only the local copy of the argument. Beyond that the item cannot be worked until the original listing is restored.

Please log in or register to report this question.

80.

What is the value of X in the sample code given below?

double X; X = ( 2 + 3) * 2 + 3;

Answer: B

Correct answer: 13

The parentheses force the addition first, then multiplication precedes the final addition:

\[ (2 + 3) \times 2 + 3 = 5 \times 2 + 3 = 10 + 3 = 13 \]

X is a double, so it stores 13.0, but the value is 13.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Expressions Questions and Answers || Expressions MCQ Questions and Answers || Expressions GK Questions and Answers || Expressions GK MCQ Questions || Expressions Multiple Choice Questions and Answers || Expressions GK || GK on Expressions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming