Courses / HEC NSCT – National Skill Competency Test: Complete Preparation for Computing Graduates
2.1 Programming Basics – Data Types, Operators and Control Flow
Area 2 – Programming (C++ / Java / Python) (10%) · 45 min read · 24 MCQs to check yourself
Coding basics – variables (Transcode)
Data types at a glance
| Idea | C++ | Java | Python |
|---|---|---|---|
| Whole number | int (4 bytes) |
int (4 bytes), long (8) |
int (unlimited size) |
| Decimal | float, double |
float, double |
float |
| True/false | bool |
boolean |
bool (True/False) |
| Character | char (1 byte) |
char (2 bytes, Unicode) |
single-character str |
| Text | std::string |
String (immutable) |
str (immutable) |
| Typing | static | static | dynamic (type decided at run time) |
Operators that trick students
| Expression | C++ / Java | Python |
|---|---|---|
7 / 2 |
3 (integer division) |
3.5 |
7 // 2 |
– | 3 (floor division) |
7 % 2 |
1 |
1 |
-7 / 2 |
-3 (truncates toward zero) |
-3.5; -7 // 2 = -4 (floors) |
2 ** 3 |
– | 8 |
x++ vs ++x |
post-increment uses the old value, pre-increment the new value | not available |
== on objects |
Java compares references; use .equals() for content |
== compares values, is compares identity |
Short-circuit: in A && B (Python A and B), B is not evaluated if A is false; in A || B, B is skipped if A is true.
Control flow
if / else if / else,switch(C++/Java – rememberbreak, otherwise execution falls through).- Loops:
for,while,do-while(runs at least once).breakleaves the loop;continueskips to the next iteration.
This lesson ends with a quiz of 24 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: Area 1 Review, Checklist and Area Test · Next: 2.2 Functions, Arrays, Strings and Recursion