Computer Knowledge

Programming Fundamentals

2,611 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. call by reference

  2. call by value

  3. call by address

  4. All the above

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

Using pointers to pass arguments to a function simulates passing by reference because it allows the function to modify the actual arguments in the caller's scope. Call by value copies the actual data, whereas call by address is a synonym but call by reference is the standard curriculum terminology.

Multiple choice technology programming languages
  1. The instance gets garbage collected.

  2. The code on line 33 throws an exception.

  3. . The code on line 35 throws an exception

  4. The code on line 31 throws an exception

  5. The code on line 33 executes successfully

Reveal answer Fill a bubble to check yourself
B,C,E Correct answer
Explanation

The finally block executes in three scenarios: B) when an exception is thrown in the try block, C) when an exception is thrown in the catch block, and E) when the try block completes successfully. Option A is false - garbage collection doesn't trigger finally. Option D is false - code before the try block (line 31) doesn't affect whether this try-catch-finally executes its finally. The finally block ALWAYS executes unless the JVM exits or there's a catastrophic failure.

Multiple choice technology programming languages
  1. strcpy

  2. memcpy

  3. both memcpy and strcpy

  4. none

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

memcpy is theoretically faster because it knows the exact byte count upfront and can optimize the copy accordingly. strcpy must scan for the null terminator to find the length, then copy character by character until it finds it. In the given code, msg is 12 bytes (including null terminator), so memcpy copies exactly 12 bytes directly. strcpy has to first find where the string ends, then copy. Modern compilers may optimize strcpy calls when the size is known, but theoretically memcpy is faster.

Multiple choice technology programming languages
  1. True

  2. False

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

Casting between numeric types (int, long, float, double, short, byte, char) is a fundamental operation in Java. This includes both widening conversions (like int to long) which are implicit, and narrowing conversions (like double to int) which require explicit casting. Primitive numeric types have well-defined conversion rules, making casting between them a common operation.

Multiple choice technology programming languages
  1. int $x
  2. int 123

  3. int _123

  4. int #dim

  5. int %percent

  6. int central_sales_region_Summer_2005_gross_sales

Reveal answer Fill a bubble to check yourself
A,C,F Correct answer
Explanation

Java identifiers can begin with a letter, underscore, or dollar sign. They cannot begin with a number, hash sign, or percent sign. Thus, $x, _123, and central_sales_region_Summer_2005_gross_sales are valid declarations, while 123, #dim, and %percent are invalid.

Multiple choice technology testing
  1. the use of a variable before it has been defined

  2. memory leaks

  3. unreachable (“dead”) code

  4. array bound violations

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

Static analysis analyzes code without executing it, finding issues like unused variables, dead code, or syntax violations. Memory leaks typically occur dynamically during runtime execution, making them impossible for standard static analysis to reliably detect.

Multiple choice technology mainframe
  1. For loop

  2. Do-While loop

  3. Method

  4. All of the above

  5. None of the above

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

The COBOL PERFORM loop with the UNTIL clause executes the paragraph at least once and then tests the condition, which is the same behavior as a do-while loop in Java or C++. A for loop typically initializes and tests before execution, and a method is a completely different construct (a subprogram, not a loop).

Multiple choice technology mainframe
  1. use a standard perform statement

  2. use an in line perform

  3. skillful use of the COBOL reserved word "AFTER"

  4. This is not possible in COBOL

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

In COBOL, specifying PERFORM WITH TEST AFTER guarantees the loop body executes at least once before testing the loop condition, acting as a post-test loop. Standard or inline PERFORM statements default to checking the condition first (TEST BEFORE), while the AFTER option is the precise mechanism to alter this evaluation timing.

Multiple choice technology mainframe
  1. GENERATE

  2. MODIFY

  3. ALTER

  4. MEMBER

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

In JCL utilities like IEHLIST and IEBCOPY, the GENERATE control statement is used to indicate that an editing operation should be performed on the dataset. MODIFY is used for different purposes, ALTER changes attributes, and MEMBER refers to PDS members, not editing control.

Multiple choice technology mainframe
  1. True

  2. False

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

DECLARE CURSOR is a declarative SQL statement, not executable. It only defines the cursor and its associated SELECT statement for later use. The actual execution happens when you OPEN the cursor, not when you declare it.

Multiple choice technology mainframe
  1. True

  2. False

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

Unlike functions like COUNT(column_name), which ignore NULL values, COUNT(*) counts all rows in the target table, including those containing NULL values or duplicate values.