Programming Fundamentals Aptitude Questions with Solutions
40 Programming Fundamentals questions with hints, worked solutions and time targets — 11 easy · 20 medium · 9 hard.
- Section: Programming MCQs
- Questions: 40
- By difficulty: 11 easy · 20 medium · 9 hard
- Cost: Free, unlimited on every plan
Operators, control flow, functions, pointers and output prediction in C, Java and Python.
Programming Fundamentals: the essentials
Output questions test a handful of rules that differ between languages.
C and Java
- Integer division truncates towards zero:
7 / 2is 3,-7 / 2is −3 and-7 % 2is −1. One floating operand gives real division:7 / 2.0is 3.5. - Precedence, high to low: unary, then
* / %, then+ -, shifts, relational, equality, bitwise,&&,||,?:and assignment. Equal operators group left to right, except?:and assignment. i++yields the old value,++ithe new one.&&and||short-circuit, so a side effect on the right may never happen. Aswitchfalls through until abreak.- C: arguments are copied, so a swap needs pointers;
*(p + i)isp[i]; an array parameter is a pointer, sosizeofgives the pointer's size;strlenomits the terminating null thatsizeofcounts; astaticlocal keeps its value between calls. - Java:
==compares references andequalscontents; strings are immutable;intoverflow wraps, soInteger.MAX_VALUE + 1isInteger.MIN_VALUE;1 + 2 + "3"is 33;finallyruns even after areturn.
Python
7 / 2is 3.5,7 // 2is 3 and-7 // 2is −4: floor division rounds towards minus infinity.b = ashares one list anda[:]copies it;[[0] * 3] * 2holds one inner list twice.- A mutable default argument is shared between calls, and a loop's
elseruns only when nobreakfired.
Questions
- Two kinds of division in C Easy
What does this C program print? - Pre-increment against post-increment Medium
What does this C program print? - Precedence of the arithmetic operators Medium
What does this C program print? - Short-circuit evaluation Medium
What does this C program print? - A static local variable Medium
What does this C program print? - A swap that does not swap Easy
What does this C program print? - Pointer arithmetic against value arithmetic Medium
What does this C program print? - sizeof on an array parameter Hard
Assume a machine where int occupies 4 bytes and a pointer occupies 8 bytes. What does this C program print? - strlen against sizeof Medium
What does this C program print? - Falling through a switch Easy
What does this C program print? - A nested conditional expression Medium
What does this C program print? - Comparing a signed value with an unsigned one Hard
What does this C program print? - A character used in arithmetic Easy
Assume the ASCII character set, in which 'A' has the value 65. What does this C program print? - Subscripting written backwards Hard
What does this C program print? - A local that hides a global Easy
What does this C program print? - Dividing a negative number Medium
What does this C program print? Assume a C99 or later compiler. - Comparing strings with == and equals Easy
What does this Java program print? - Comparing boxed integers Hard
What does this Java program print? - String methods return new strings Easy
What does this Java program print? - Integer and floating-point division in Java Easy
What does this Java program print? - When + means concatenation Medium
What does this Java program print? - A static field shared by every object Medium
What does this Java program print? - What a method can and cannot change Medium
What does this Java program print? - String against StringBuilder as a parameter Medium
What does this Java program print? - The type of a conditional expression Hard
What does this Java program print? - Grouped labels and a missing break Medium
What does this Java program print? - finally runs after the return value is fixed Hard
What does this Java program print? - Adding one to the largest int Medium
What does this Java program print? - Three divisions in Python Medium
What does this Python program print? - Aliasing against slicing Medium
What does this Python program print? - A default argument that remembers Hard
What does this Python program print? - Python strings are immutable too Easy
What does this Python program print? - Building a grid with the repetition operator Hard
What does this Python program print? - Equality against identity Easy
What does this Python program print? - Three slices of one string Medium
What does this Python program print? - The else clause of a for loop Hard
What does this Python program print? - Mutating against rebinding Medium
What does this Python program print? - Assignment makes a name local Easy
What does this Python program print? - A generator and a comprehension in one line Medium
What does this Python program print? - Short-circuiting past a function call Medium
What does this Python program print?
Placement tests that ask programming fundamentals
- Full-Length Aptitude Paper CodeKairo
- Big Tech Screen — Theory Drill CodeKairo
- Accenture — Cognitive & Technical Accenture
- Capgemini — Technical & English Capgemini
- HCLTech — Written Test HCLTech
- Tech Mahindra — Aptitude & Technical Tech Mahindra
- Amazon — SDE Online Assessment Amazon
- LTIMindtree — Online Assessment LTIMindtree
- Mphasis — AMCAT Assessment Mphasis
- Virtusa — Online Test & Coder Challenge Virtusa
- Deloitte — Online Assessment Deloitte
- Zoho — Round 1 Zoho