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

Expressions Questions and Answers

1.

What is the output of the following pseudocode ?

x = 5
y = x++
z = ++x
print(x + y + z)

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: B

The output is 19.

Trace the variables line by line:

  1. x = 5, so x is 5.
  2. y = x++ is post-increment: y takes the old value 5, then x becomes 6.
  3. z = ++x is pre-increment: x becomes 7 first, then z takes 7.
  4. x + y + z = 7 + 5 + 7 = 19.

18 comes from forgetting the final increment and using x = 6 (6 + 5 + 7). 20 and 21 come from treating x++ as if it also gave the new value to y.

Please log in or register to report this question.

2.

What is the output of printf ("%d", 5 > 3 + 2) ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: A

The output is 0.

Arithmetic operators have higher precedence than relational ones, so 3 + 2 is worked out first, giving 5 > 5. That comparison is false, and in C a relational expression evaluates to the int 0 when false and 1 when true. printf with %d prints that integer: 0.

1 is the trap of reading 5 > 3 on its own and ignoring the + 2. printf prints the integer value of the expression, never the word 'False', and since the output is well defined, 'None of these' does not apply.

Please log in or register to report this question.

3.

What will be the output of

int x=5; printf("%d", x++);

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: A

The output is 5.

x++ is the post-increment operator: the expression's value is the current value of x, and x is increased only afterwards. So printf receives 5 and prints 5, and x becomes 6 once the statement is done.

6 would be printed by the pre-increment ++x, which increments first and then uses the new value. 4 would need a decrement, and the code is valid C, so there is no error.

Please log in or register to report this question.

4.

In a 'C' language expression, if the following expressions appear, which will be evaluated first ?

Exam Year(s)

UGC NET - 2012,

Answer: C

An expression in brackets is evaluated first, so (x + y) is evaluated first (option C). Parentheses have the highest precedence and override the normal order.

Without brackets, multiplication and division (x \(\cdot\) y and x/y) are evaluated before the addition x + y, but all of them wait for the parenthesised expression. Of the four, only the bracketed one comes first.

Please log in or register to report this question.

5.

Which of the following statements will post increment the variable by 1 ?

I. a = a + 1; II. a + = 1;
III. a + +; IV. a = + 1;

Exam Year(s)

UGC NET - 2012,

Answer: A

In C, the statements a = a + 1, a += 1 and a++ each add 1 to the variable, so statements I, II and III increment it. The statement a = +1 assigns the value +1 to a and does not increment it, because the plus sign there is a unary operator on the constant 1 and the previous value of a is lost. So the options containing IV are wrong, and the option with only I and II leaves out a++, which is the post increment operator. The answer is that I, II and III are correct.

Please log in or register to report this question.

6.

The correct sequence of hierarchy of operators is _____. from highest to lowest.

(i) – or + (ii) ( )
(iii) / or * (iv) * *

Exam Year(s)

UGC NET - 2012,

Answer: B

The hierarchy of operators in an arithmetic expression, from the highest priority to the lowest, is first the parentheses, then exponentiation, then multiplication and division, and last addition and subtraction. With the symbols in the question, ( ) is item (ii), the exponent operator is item (iv), the multiplication or division is item (iii), and the plus or minus is item (i). So the sequence is (ii), (iv), (iii), which is the second option, and the unary or binary minus and plus are at the bottom. The other options put plus and minus, or the exponent, above the parentheses. The answer is (ii), (iv), (iii).

Please log in or register to report this question.

7.

Match List – I with List – II and select the correct answer using codes given below :

List – IList – II
a. if-then1. hex-data
b. % x2. garbage to calling function
c. gets( )3. on-off controller
d. return;4. multi word string

Codes : a b c d

Exam Year(s)

UGC NET - 2012,

Answer: A

The if-then construct is the on-off controller, so a matches 3. The format code %x is used for hexadecimal data, so b matches 1. The function gets( ) reads a multi word string, including spaces, so c matches 4. The statement return; in a function that should return a value hands back garbage to the calling function, so d matches 2. The code is 3 1 4 2. The codes 2 3 4 1, 1 2 3 4 and 4 3 2 1 each mismatch the first pair. The answer is 3 1 4 2.

Please log in or register to report this question.

8.

The expression a = 7/22 ∗ (3.14 + 2) ∗ 3/5 evaluates to

Exam Year(s)

UGC NET - 2012,

Answer: D

The expression evaluates to 0, option (D). In C, the operands 7 and 22 are both integers, so 7/22 is integer division and gives 0, because the fractional part is dropped. Multiplying 0 by (3.14 + 2) gives 0, and multiplying by 3 and dividing by 5 keep it at 0, so the whole expression is 0. If the division were done in floating point, the value would be about 0.98, which is not among the options. The values 8.28, 6.28 and 3.14, options (A), (B) and (C), come from treating the expression as a real number formula, which C does not do when both operands of the division are integers.

Please log in or register to report this question.

9.

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);
    }

 

Answer: C

Correct answer: 1

Pointer subtraction returns the number of elements between the two pointers, not the number of bytes. k holds the value p had before the increment, and p++ moved p on by one int, so p - k is 1. The compiler divides the 4-byte gap by sizeof(int) for you.

Please log in or register to report this question.

10.

What is the output of this C code?    

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

 

Answer: B

Correct answer: -1

In C the result of % takes the sign of the dividend, and the language requires that (a/b)*b + a%b == a. Since -5 / 4 truncates toward zero to \(-1\), we need \(-1 \times 4 + r = -5\), giving \(r = -1\). So the program prints -1.

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