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.

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.

5.

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.

6.

What is the value of the below assignment expression
      (x = foo()) in the statement (x = foo()) != 1, considering that foo() returns 2?

Answer: A

Correct answer: 2

The value of an assignment expression is the value assigned. foo() returns 2, so x becomes 2 and the expression (x = foo()) itself has the value 2. That value is then what the surrounding != 1 compares against - and the comparison, being a separate expression, would yield 1.

Please log in or register to report this question.

7.

What will be the output of the following program?
 

#include <stdio.h>
int main()
{
int num = 0, z = 3;
if ( ! (num <= 0) || ++z )
printf( "%d %d ", ++num + z++, ++z );
else
printf( "%d %d", --num + z--, --z);
return 0;
}

 

Answer: B

Correct answer: 6 5

num is 0, so num <= 0 is true and !(num <= 0) is 0. The || must therefore evaluate its right operand: ++z takes z to 4 and is non-zero, so the if branch runs.

In printf("%d %d ", ++num + z++, ++z) the arguments are evaluated right to left on the usual compilers: ++z makes z 5 and yields 5; then ++num gives 1 and z++ yields 5, so the first argument is 6. Output: 6 5. Note that the order of argument evaluation is unspecified, so this particular pairing is compiler-dependent.

Please log in or register to report this question.

8.

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

Answer: D

Correct answer: c = 4;

<<= shifts left and assigns. Shifting left by one position doubles the value, because each bit moves to the next higher power of two:

\[ 2 = 10_2 \;\rightarrow\; 100_2 = 4 \]

So c becomes 4.

Please log in or register to report this question.

9.

What will be the output of the following program?

#include <stdio.h>

int main()
{
static unsigned int a = 23;
register unsigned char c = 'R';
auto long unsigned q = 345L;
static long signed p = 345L;
printf("a = %u c = %c", a ,c);
printf("\nq = %ld p = %ld", q, p);
return 0;
}

 

Answer: A

Correct answer: a=23 c=R q = 345 p = 345

Each variable prints its own value, and the storage classes affect only lifetime and placement, not the values: a is 23, and c printed with %c shows the character R. The two long variables both hold 345 and print with %ld as 345. The only real trap is the case of the letters in the options - the format string writes a lower-case a.

Please log in or register to report this question.

10.

Relational operators cannot be used on:

Answer: A

Correct answer: structure

Relational operators work on scalars - arithmetic types and pointers - because comparison needs a single value to order. A struct is an aggregate of several members, so s1 < s2 has no meaning and is rejected; even == is not defined for structures, since padding bytes would make a byte-wise comparison unreliable. Comparing them means comparing their members one by one.

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