UP Police Computer Operator study materials
UP Police Computer Operator study resources

UP Police Computer Operator: Programming Concepts and Logic (C, C++, Java Basics)

UP Police Computer Operator · Work through your exam, one topic at a time.

All guide sections

Programming Concepts and Logic (C, C++, Java Basics)

Programming Concepts and Logic tests C, C++ and Java fundamentals: data types, operators, control flow, arrays, functions, pointers/references, OOP and dry-run output. The exam usually asks what a short snippet prints.

Core rules

  • C: integer division truncates; the % operator works on integers; arrays are 0-indexed; strings are char arrays ending with a null character; pointers store addresses; & gives an address and * dereferences.
  • C++ adds classes, references, function overloading, constructors and destructors; cout << and cin >> perform output and input.
  • Java: bytecode runs on the JVM; String is immutable; == compares references while .equals() compares content; main is public static void main(String[] args).
  • Precedence: postfix ++/-- > unary > multiplicative > additive > relational > logical. && and || short-circuit.
  • OOP concepts: encapsulation, inheritance, polymorphism and abstraction.

Worked example

int i = 0, s = 0; while (i < 4) { s += i; i++; } printf("%d", s); The loop adds 0 + 1 + 2 + 3 = 6, then i becomes 4 and the condition fails. Output is 6. Reasoning: the condition is checked before each iteration, so the value 4 is not added.

Traps

= is assignment, == is comparison. i++ uses the old value and then increments. An array index equal to size n is out of bounds. In Java, == may fail for equal String content created separately; use equals.