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
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.
-
Code compiles
-
If line 1 is removed the code compiles
-
If line 3 is removed the code compiles
-
If line 5 is removed the code compiles
-
If line 1,3 are removed the code compiles
-
If line 1,3,5 are removed the code compiles
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.
-
once
-
twice
-
the program will go on into infinite loop
-
None of the above
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.
-
A File Handle
-
A List
-
A Code variable
-
A Tyleglob
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.
-
the use of a variable before it has been defined
-
unreachable (“dead”) code
-
memory leaks
-
array bound violations
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.
-
1
-
2
-
There is no limit
-
COBOL if statements are not used to compare variable values
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.
-
Infinite loop
-
Logical Error
-
Runtime Error
-
All of the above
-
None of the above
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.
-
For loop
-
Do-While loop
-
Method
-
None of the Above
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.
-
Use a standard perform statement
-
Use an in line perform
-
Skillful use of the COBOL reserved word "AFTER"
-
This is not possible in COBOL
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.
-
Exits the statement
-
Executes the function
-
Exits the Program
-
Executes the If statement again
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.
B
Correct answer
Explanation
PERFORM UNTIL executes until a condition becomes true, making the number of iterations unknown at the start. Unlike PERFORM VARYING or times-based loops, UNTIL loops continue based on runtime condition evaluation, not a predetermined count.
-
Arrays
-
Strings
-
Enums
-
None
-
All the Above
C
Correct answer
Explanation
In C#, enum is a value type. Conversely, arrays and strings are reference types. Therefore, 'Enums' is the correct option representing a value type.
-
No,pointers can not be used here
-
by using unsafe block
-
by compiling using /unsafe option in command line only
-
Both B and C
-
None
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.
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.
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.