CS Atlas GATE 2027
PDS course
0 / 103 complete

PDS/Phase 7 · Integration & Final Test

Chapter review L0.1 · Item 5 of 103

What a program is

Read at your own pace. Try the questions before opening the answers.

On this page

ACompressed recap

🧾

A program is a list of instructions. You write source code in C; the compiler checks it and translates it into an executable of machine code. Every program starts inside main, runs its statements top to bottom (each ends with ;), and finishes with return 0;. printf prints exactly the characters of its string literal; escape sequences such as \n are single characters; comments vanish, except inside quotes.

Memory is a row of one-byte boxes numbered by address. A variable is a named box (an int takes 4 bytes here). = evaluates the right side with current values and overwrites the box. %d prints a whole-number value.

BMerged rule card

0.1.1 Programs and instructions; source code → compiler → executable; the shape of a first C program (main, printf, return)

  • Program = list of instructions; processor runs machine code (0s and 1s).
  • Source code (.c) → compiler → executable. Rule broken → compile-time error, nothing runs.
  • Shape: #include <stdio.h> · int main(void) { … return 0; }.
  • Statements run top to bottom; each ends with ;.
  • printf("…") prints exactly the string literal; it never adds a new line.
  • Escapes (one character each): \n new line, \t tab, \\ backslash, \" quote.
  • Comments: /* … */ (not nestable) and // …; inside quotes they are plain text.

0.1.2 Memory as numbered boxes: bits, bytes, addresses; a variable as a named box

  • bit = 0 or 1; byte = 8 bits; n bits → patterns double with each bit (8 bits → 256).
  • Memory = numbered one-byte boxes; number = address; multi-byte value’s address = its first byte.
  • int = whole number, 4 bytes here; int x = 5; creates and fills a box.
  • x = expr; evaluate right side with current values, then overwrite x.
  • Unfilled local variable = unpredictable value.
  • %d in printf = placeholder for the next value, as a whole number.
  • Identifier: letters, digits, _; not starting with a digit; not a keyword; case-sensitive.
  • Swap needs a third variable: t = a; a = b; b = t;

CInterleaved GATE-style questions

Q1MCQ1 markOutput

What does this print?

printf("1\t2\n3");
printf("4\n");
  • (A) 1 2 3 4 on one line
  • (B) 12 on line 1; 34 on line 2
  • (C) 1, tab, 2, 3 on line 1; 4 on line 2
  • (D) 1, tab, 2 on line 1; 34 on line 2

Q2NAT1 markEscape sequences

How many characters are printed by printf("\\n\n");?

Numerical answer: ________

Q3MCQ1 markCompiler

Which problem stops the program from being built into an executable?

  • (A) Printing the same text twice
  • (B) Writing Printf instead of printf
  • (C) Forgetting \n at the end of a printf
  • (D) A comment containing the word main

Q4MCQ2 marksOutput

What does this print?

int a = 7;
int b = 2;
a = a + b;
b = a - b;
a = a - b;
printf("%d %d\n", a, b);
  • (A) 7 2
  • (B) 2 7
  • (C) 9 7
  • (D) 2 2

Q5NAT1 markAddresses

Three ints are stored one after another starting at address 500 (4 bytes each). What is the address of the third int?

Numerical answer: ________

Q6MSQ1 markVariables

Which statements are true?

  • (A) = in C asks whether two values are equal.
  • (B) A variable created without a first value may hold any value.
  • (C) x = x + 1; is valid C and increases x by 1.
  • (D) The name Total refers to the same variable as total.

Q7NAT1 markBits

How many different patterns can one byte hold?

Numerical answer: ________

Q8MCQ1 markComments

How many times is the word OK printed?

printf("OK\n"); /* printf("OK\n");
printf("OK\n"); */ printf("OK\n");
// printf("OK\n");
  • (A) 4
  • (B) 1
  • (C) 2
  • (D) 3

Q9MCQ2 marksOutput

What does this print?

int k = 4;
printf("%d", k);
k = k + k;
printf("%d\n", k + 1);
  • (A) 49
  • (B) 4 then 9 on the next line
  • (C) 48
  • (D) 4 9

DAnswer Vault

Answer Vault

Try the questions first. Open when you are ready to check.

Q1 Answer: (D)1 mark

The \n after 2 ends line 1; 3 and 4 share line 2.

Output

1	2
34
  • (A) is wrong: There are a tab and a new line, not spaces.
  • (B) is wrong: \t prints a tab between 1 and 2.
  • (C) is wrong: The new line comes after 2, not after 3.

Re-read: Lesson 0.1.1 — Programs and instructions; source code → compiler → executable; the shape of a first C program (main, printf, return)

Q2 Answer: 31 mark

The string holds \\ (one backslash), the letter n, and \n (new line): 3 characters. On screen you see \n followed by a line break.

Output

\n

Re-read: Lesson 0.1.1 — Programs and instructions; source code → compiler → executable; the shape of a first C program (main, printf, return)

Q3 Answer: (B)1 mark

C is case-sensitive: Printf is not the name of any known function, so no executable can be built: there is no function with that name.

  • (A) is wrong: Allowed; it simply prints twice.
  • (C) is wrong: Allowed; the output just lacks a new line.
  • (D) is wrong: Comments are ignored.

Re-read: Lesson 0.1.1 — Programs and instructions; source code → compiler → executable; the shape of a first C program (main, printf, return)

Q4 Answer: (B)2 marks

a = 9; b = 9 − 2 = 7; a = 9 − 7 = 2. This swaps without a third variable.

Output

2 7
  • (A) is wrong: The three lines swap the values.
  • (C) is wrong: a is changed again on the last line.
  • (D) is wrong: b becomes 7.

Re-read: Lesson 0.1.2 — Memory as numbered boxes: bits, bytes, addresses; a variable as a named box

Q5 Answer: 5081 mark

500, 504, 508.

Re-read: Lesson 0.1.2 — Memory as numbered boxes: bits, bytes, addresses; a variable as a named box

Q6 Answer: (B) (C)1 mark

Assignment stores; names are case-sensitive.

  • (A) is wrong: = stores a value; it does not compare.
  • (D) is wrong: Names are case-sensitive.

Re-read: Lesson 0.1.2 — Memory as numbered boxes: bits, bytes, addresses; a variable as a named box

Q7 Answer: 2561 mark

8 bits; doubling 8 times from 1: 256.

Re-read: Lesson 0.1.2 — Memory as numbered boxes: bits, bytes, addresses; a variable as a named box

Q8 Answer: (C)1 mark

The /* … */ comment spans two lines and hides two printf calls; the // line is also a comment. Only the first and the last printf on line 2 run.

Output

OK
OK
  • (A) is wrong: Comments never run.
  • (B) is wrong: The printf after */ on line 2 runs too.
  • (D) is wrong: Two calls are inside the /* */ comment.

Re-read: Lesson 0.1.1 — Programs and instructions; source code → compiler → executable; the shape of a first C program (main, printf, return)

Q9 Answer: (A)2 marks

No space or new line after the first %d, so 4 and 9 run together.

Output

49
  • (B) is wrong: There is no \n after the first value.
  • (C) is wrong: k + 1 = 9 is printed, not k.
  • (D) is wrong: printf adds no space.

Re-read: Lesson 0.1.2 — Memory as numbered boxes: bits, bytes, addresses; a variable as a named box

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.