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. True

  2. False

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

The statement is false because 'final' and 'static' are NOT access specifiers - they are modifiers. Access specifiers in Java are public, private, protected, and default (package-private). Additionally, 'static' cannot be used for local variables, and 'final' has different semantics depending on context.

Multiple choice technology programming languages
  1. Code compiles

  2. If line 1 is removed the code compiles

  3. If line 3 is removed the code compiles

  4. If line 5 is removed the code compiles

  5. If line 1,3 are removed the code compiles

  6. If line 1,3,5 are removed the code compiles

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

In Java, enums can only be declared at the top level or within a class, but NOT within a method. Line 5's enum D is declared inside method C(), which is illegal and causes compilation failure. Removing line 5 (option D) fixes this. Enum A at line 1 (top-level) and enum B at line 3 (inside class E2 but outside method) are both legal. Option F works because removing all enums leaves valid code.

Multiple choice technology programming languages
  1. once

  2. twice

  3. the program will go on into infinite loop

  4. None of the above

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

The Perl code reads inpput.txt line-by-line using a while loop. The entire content of the file is printed line-by-line, meaning the file's contents are printed exactly once. Other options like printing twice or entering an infinite loop are incorrect because the loop terminates once the end of the file is reached.

Multiple choice technology programming languages
  1. A File Handle

  2. A List

  3. A Code variable

  4. A Tyleglob

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

INPUT in Perl is conventionally used as a file handle name (all uppercase identifiers typically indicate file handles). File handles are used for input/output operations with files, pipes, or sockets. This follows Perl's naming convention where uppercase names are reserved for file handles like STDIN, STDOUT, etc.

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

  2. unreachable (“dead”) code

  3. memory leaks

  4. array bound violations

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

Static analysis examines source code without executing it, finding issues like unused variables, dead code, and potential array bounds violations. Memory leaks are dynamic runtime anomalies caused by improper allocation/deallocation during execution, which are detected via dynamic testing rather than static analysis.

Multiple choice technology mainframe
  1. 1

  2. 2

  3. There is no limit

  4. COBOL if statements are not used to compare variable values

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

A COBOL IF statement evaluates a single condition at a time. While you can combine conditions using AND/OR connectors, the fundamental IF construct makes one comparison decision. For multiple independent comparisons, you need nested IFs.

Multiple choice technology mainframe
  1. Infinite loop

  2. Logical Error

  3. Runtime Error

  4. All of the above

  5. None of the above

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

COBOL IF statements can encounter logical errors (wrong condition logic), runtime errors (invalid data type comparison), and infinite loops (when combined with PERFORM or if condition never becomes false due to state changes). All three error types are possible in IF-based control flow.

Multiple choice technology mainframe
  1. For loop

  2. Do-While loop

  3. Method

  4. None of the Above

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

COBOL's PERFORM...UNTIL structure is analogous to a do-while loop in languages like Java and C++ - it executes the code block, then checks the condition, repeating until the condition becomes true. It's not a for loop (fixed iteration) or a method call.

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

The AFTER clause in COBOL PERFORM statements allows condition checking after initial execution, enabling the loop to run once before evaluation. Standard PERFORM checks first, inline PERFORM is about code placement, and the functionality is definitely possible in COBOL.

Multiple choice technology mainframe
  1. Exits the statement

  2. Executes the function

  3. Exits the Program

  4. Executes the If statement again

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

When an IF condition evaluates to true, the first action is executing the code or function within the IF block. Only after execution does flow continue to any ELSE or statement exit. It doesn't exit immediately, exit the program, or re-execute.

Multiple choice technology programming languages
  1. No,pointers can not be used here

  2. by using unsafe block

  3. by compiling using /unsafe option in command line only

  4. Both B and C

  5. None

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

Pointers in C# can only be used within unsafe blocks, and the code must be compiled with the /unsafe option either in the IDE or command line. Both conditions are required, making 'Both B and C' correct.

Multiple choice technology mainframe
  1. True

  2. False

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

The FOR loop is specifically designed for situations where the number of iterations IS fixed or known in advance. For dynamic condition-based termination where the count isn't predetermined, you would use REPEAT...UNTIL or WHILE...ENDWHILE loops instead. The statement reverses the actual use case.

Multiple choice technology mainframe
  1. True

  2. False

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

PERFORM is a versatile Natural statement that can execute both external subprograms (separately compiled objects) and inline subroutines (defined within the same program using the SUBROUTINE statement). This dual capability provides flexibility in code organization and reuse.