Computer Knowledge

Programming Fundamentals

2,381 Questions

Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.

Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references

Programming Fundamentals Questions

Multiple choice technology programming languages
  1. int i = 0XCAFE;

  2. boolean b = 0;

  3. char c = A;

  4. byte b = 128;

  5. char c = "A";

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Option A is valid: '0XCAFE' is a hexadecimal literal (hex digits start with 0X or 0x). Option B is invalid: boolean can only be 'true' or 'false', not 0. Option C is invalid: 'A' must be quoted as a character literal. Option D is invalid: byte range is -128 to 127, 128 overflows. Option E is invalid: char can't take a String literal.

Multiple choice technology programming languages
  1. a. The switch and case statement

  2. b. ternary operator

  3. c. nested if statement

  4. d. The #endif statement

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The switch-case statement replaces multiple if-else statements when comparing a single expression against many constant values. This improves readability and can be more efficient. Ternary operators only replace simple if-else, and nested ifs are the opposite of simplification.

Multiple choice technology programming languages
  1. a. continue;

  2. b. break;

  3. c. return "Infant";

  4. d. return 0;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The function declares a string return type but has no return statement for ages 4 and below. Adding 'return "Infant";' as the last line ensures all execution paths return a string, satisfying the compiler's requirement that non-void functions must return a value on all paths.

Multiple choice technology programming languages
  1. a. true

  2. b. false

  3. c. an exception is thrown

  4. d. depends

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Unboxing extracts a value type from an object reference. If that reference is null, there's nothing to extract, causing a runtime exception (NullReferenceException in C#). You cannot unbox null because unboxing requires an actual boxed value to retrieve.

Multiple choice technology programming languages
  1. a. Yes

  2. b. No

  3. c. Under certain conditions

  4. d. May be

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Only ONE catch block executes for a given exception. Exception handlers are evaluated in order, and the first matching catch block handles the exception. Once executed, control jumps to the finally block (if any) and then continues after the try-catch structure. No other catch blocks run for that same exception.

Multiple choice technology programming languages
  1. a. readonly value can be changed later

  2. b. const items are dealt at compile time however readonly is dealt at runtime

  3. c. const value can be changed later

  4. d. const items are dealt at runtime however readonly is dealt at compile time

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

const is a compile-time constant - the value is embedded at compile time and cannot change. readonly is a runtime constant that can be assigned once (at declaration or in a constructor) and then becomes immutable. This is why const can only be used for value types and string literals, while readonly can reference any type.

Multiple choice technology
  1. memory

  2. register

  3. variable

  4. assembler

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Operands are the data values that instructions operate on. Memory locations, registers, and variables can all serve as operands as they hold or reference data values. An assembler is a software tool that converts assembly language to machine code - it is not an operand but rather a program that processes instructions containing operands.

Multiple choice technology
  1. Address of the array

  2. Values of the first elements of the array

  3. Address of the first element of the array

  4. Number of element of the array

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When an array is passed to a function, it decays to a pointer to its first element. This is why array parameters are often declared as pointers, and why sizeof() returns the pointer size not the array size inside functions. Option C correctly states this: arrays are passed as the address of their first element.

Multiple choice technology
  1. float ptr;

  2. float *ptr;

  3. *float ptr;

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In C, a pointer to float is declared using an asterisk (*) before the variable name: float *ptr;. Option A (float ptr;) declares a regular float variable, not a pointer. Option C (*float ptr;) has incorrect syntax - the asterisk must come after the type, not before it.

Multiple choice technology programming languages
  1. exception

  2. harness

  3. assertion

  4. expression

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

An assertion is a statement that a programmer believes should always be true at a specific point in code execution. Assertions are used as debugging and testing aids to check assumptions during development, and typically trigger an error or exception if the condition evaluates to false.

Multiple choice technology platforms and products
  1. At least one variable must be added to a Global Variable group

  2. The predefined value of a Global Variable cannot be overridden from the command line

  3. The predefined value of a Global Variable for individual services can be changed at deployment time

  4. When using a Global Variable in the fields of a resource, enter the name surrounded by $
Reveal answer Fill a bubble to check yourself
A,C Correct answer
Explanation

A Global Variable group must contain at least one variable to be valid. Global Variable values can be overridden at deployment time for individual services. Global Variables can be overridden from the command line using the -var option, and they are referenced in resources using the syntax %%globalVariableName%%, not with $.