High yield ●●●

🔢 Types, Operators & Expressions

Why it matters: Every output question depends on exact integer behaviour: wrap-around, integer division, precedence, side effects, and bitwise tricks.

Subtopics

Each subtopic has its own page: idea, why, how, example, play, check. Mark each one understood when it clicks. 0 of 5 done.

Formulas

Signed n-bit range
−2^(n−1) … 2^(n−1) − 1 (int: −2147483648 … 2147483647)
Unsigned n-bit range
0 … 2^n − 1 (unsigned int max 4294967295)
Unsigned wrap
result = value mod 2^n (so (unsigned)−1 = 2^32 − 1)
Shifts
x << k = x · 2^k x >> k = ⌊x / 2^k⌋
Clear lowest set bit
x & (x − 1) isolate it: x & (−x)
Division and remainder
a == (a / b) * b + a % b, with / truncating toward 0
Masks
n low ones = (1 << n) − 1

What GATE asks from this

Question types seen repeatedly in past papers. More stars means more frequent.

★★★
Bitwise operators on characters or integers
Apply & | ^ to ASCII codes, then add or subtract and print as a char.
★★★
Loop with integer division or overflow
Does the loop terminate? Does x = x + x + y exceed a power of two?
★★★
Unsigned subtraction in a comparison
strlen(a) − strlen(b) is unsigned and never negative.

Ratings are approximate, based on recurring patterns in past GATE CSE papers.

Previous year questions

2 real questions from the official GATE CSE papers (2022 to 2024), newest first, each with the official answer key and a worked solution. Questions are the property of the GATE organising institutes; this copy is for your personal study.

2 questions · 0 correct of 0 attempted · marks 0 / 4

Year:
GATE 2024 CS1 · Q48MSQ2 marks
Consider the following C function definition.
int f(int x, int y) {
  for (int i=0; i<y; i++) {
    x=x+x+y;
  }
  return x;
}
Which of the following statements is/are TRUE about the above function?

One or more options may be correct. Select all that apply, then submit.

GATE 2022 · Q44MCQ2 marks
What is printed by the following ANSI C program? ASCII: P = 80, x = 120, * = 42, - = 45, + = 43, z = 122, K = 75, S = 83.
#include<stdio.h>
int main(int argc, char *argv[]){
  char a = 'P';
  char b = 'x';
  char c = (a & b) + '*';
  char d = (a | b) - '-';
  char e = (a ^ b) + '+';
  printf("%c %c %c\n", c, d, e);
  return 0;
}

Common traps

strlen and sizeof return unsigned: strlen(a) - strlen(b) > 0 is true whenever a ≠ b in length.
Precedence of & versus ==: x & 1 == 0 means x & (1 == 0).
5/2 = 2 but 5/2.0 = 2.5; and 1/2*4 = 0.
Superscripts in exam text matter: 220 and 220 are different numbers.