C Programming
C is the programming language in the RRB JE CS/IT and NIELIT syllabi. Exams ask data types and format specifiers, operator precedence and integer division, increment operators, loops, arrays and strings, pointers, functions, storage classes, structures and unions, often as "what does this code print?".
What should you know about C Programming?
- share the same memory, so its size is that of the largest member: A structure gives each member its own space (size at least the sum); a union overlays them.
- new line: \n new line, \t horizontal tab, \0 NUL, \b backspace, \\ backslash.
- keeps its value between calls: Storage classes: auto (default local), register (hint for speed), static (lasting), extern (defined in another file).
- stdlib.h: malloc and calloc allocate memory on the heap, realloc resizes it, free releases it.
Which formulas and rules are used in C Programming?
a / b drops the fraction; a % b = remainder
e.g. integer division (positive operands)
* / % before + −; left to right
e.g. precedence
y = x++ → y gets old x; y = ++x → y gets new x
e.g. increment
What are the shortcuts for C Programming questions?
- Count loop passes as ⌈(end − start) ÷ step⌉ for i < end.
- A string of n letters needs n + 1 bytes (the final '\0').
- Characters are small integers: 'A' = 65, 'a' = 97, '0' = 48.
- The three wrong options are always of the same kind as the answer (four Articles, four years, four names). Recall one firm fact about each option and strike out the ones you are sure of.
How do you solve C Programming questions? Worked examples
Example 1
p->x in C is the same as:
Options: (*p).x; *p.x; &p.x; p.x
Solution
The arrow operator accesses a structure member through a pointer; *p.x would mean *(p.x) because . binds tighter.
Answer: (*p).x
Example 2
Which operator gives the address of a variable in C?
Options: ->; *; &; %
Solution
& gives the address; * (dereference) gives the value stored at an address held in a pointer.
Answer: &
Example 3
What does printf("%d", 17 % 5); print?
Solution
- 17 = 5 × 3 + 2.
- The remainder is 2.
Answer: 2
What mistakes should you avoid in C Programming?
- 5 / 2 is 2 in C when both are int, not 2.5.
- if (x = 0) assigns and is false; == compares.
- Read the question word carefully: NOT, FIRST, LAST, "correct" and "incorrect" turn the answer around.
C Programming question book: practice each sub-topic
- C Programming
Question book · 1 chapters
C Programming
What does this C code print? int x = 9; int y = x++; printf("%d %d", x, y);
Solution
x++ gives the old value (9) to y, then x becomes 10
Answer: 10 9
Open the book to turn the pages: every question with its answer and full solution.
Ready? Take a mock: fresh questions every time, each with a step-by-step solution.