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
-
0
-
NULL
-
Depends on the scale and precision of the datatype.
-
Without initialization, a variable cannot be used in the executable section of the block.
B
Correct answer
Explanation
In PL/SQL, variables that are declared but not initialized default to NULL when execution begins. They do not default to 0, their default value does not depend on scale/precision, and they can still be used in the executable section.
-
If-Then-Else
-
While loop
-
GOTO
-
DECODE
C
Correct answer
Explanation
GOTO provides unconditional transfer of control to a labeled section within a PL/SQL block, allowing immediate jump to a specific part without any condition. If-Then-Else requires condition evaluation, While loops execute based on a condition, and DECODE is a function for value substitution, not a control structure.
-
Declaration
-
Execution
-
Exception
-
Header
C
Correct answer
Explanation
The Exception section (also called exception handler) is where user-defined and predefined exceptions are trapped and handled using WHEN clauses. The Declaration section declares variables and exceptions, the Execution section contains the main logic, and there is no 'Header' section in PL/SQL block structure.
-
Runtime Exception
-
finally block will be executed
-
finally block will not be executed
-
Compilation error in else block
-
Runtime Exception
-
finally block will be executed
-
finally block will not be executed
-
Compilation error in else block
C
Correct answer
Explanation
System.exit() terminates the JVM immediately, preventing the finally block from executing. Additionally, the while(true) loop in the if branch never exits, so the finally block would never be reached in that case either. Only if neither branch executes would finally run, but the structure guarantees one of them does.
-
Runtime Exception
-
finally block will be executed
-
finally block will not be executed
-
Compilation error in else block
C
Correct answer
Explanation
This is a duplicate of question 149704. System.exit() terminates the JVM immediately, preventing the finally block from executing. The while(true) loop also never exits. In both cases, the finally block is unreachable.
-
A) Parameter type mismatches.
-
B ) Errors in requirements.
-
C ) Undeclared variables.
-
D ) Uncalled functions.
B
Correct answer
Explanation
Static analysis examines code without executing it and can detect syntax errors, undeclared variables, type mismatches, and unreachable code. However, it cannot validate whether requirements are correctly captured or if the software meets user needs; requirements errors require manual review or dynamic testing. Options A, C, and D are all detectable through static code analysis.
-
a) The use of a variable before it has been defined
-
b) Unreachable (“dead”) code
-
c) Whether the value stored in a variable is correct
-
d) The re-definition of a variable before it has been used
-
e) Array bound violations
C
Correct answer
Explanation
Static analysis can detect structural issues like undefined variables (a), unreachable code (b), variable redefinitions (d), and array bounds violations (e) by analyzing code without execution. However, it cannot determine if a stored value is logically correct for the intended computation (c); that requires understanding requirements and dynamic testing.
-
1 test for statement coverage, 3 for branch coverage
-
2 tests for statement coverage, 2 for branch coverage
-
2 tests for statement coverage. 3 for branch coverage
-
3 tests for statement coverage, 2 for branch coverage
B
Correct answer
Explanation
Two test cases are sufficient for both statement and branch coverage. The first test (e.g., A=10, B=5, D=5) covers the true branch of the first IF and the true branch of the second IF. The second test (e.g., A=5, B=10, D=10) covers the false branches, achieving full coverage.
-
The use of a variable before it has been defined
-
Unreachable (“dead”) code
-
Whether the value stored in a variable is correct
-
The re-definition of a variable before it has been used
C
Correct answer
Explanation
Static analysis examines code without executing it, so it can find structural issues like undefined variables, unreachable code, or variable redefinitions. However, it cannot verify semantic correctness - whether the value stored in a variable matches the intended business logic. Static analysis tools don't understand your requirements, so they can't tell if 'x = 5' should have been 'x = 10' - only dynamic testing with known inputs and expected outputs can verify correctness.
-
Equivalence partitioning
-
State transition testing
-
LCSAJ
-
Syntax testing
C
Correct answer
Explanation
Black box techniques test software without examining internal code structure. Equivalence partitioning, state transition testing, and syntax testing are all black box techniques - they focus on inputs, outputs, and external behavior. LCSAJ (Linear Code Sequence and Jump) is a white box structural testing technique that requires analyzing code paths, branches, and control flow within the program's source code.
-
Random testing
-
Data Flow testing.
-
Statement testing.
-
Syntax testing.
D
Correct answer
Explanation
BS7925-II standard for software component testing defines white-box techniques as those examining internal structure like control flow, data flow, and statement coverage. Syntax testing is a black-box technique that validates input format against a grammar without considering internal code implementation. Random testing is also not a white-box technique, but syntax testing is more definitively a structural black-box method.
-
Compiling code is not a form of static analysis.
-
Static analysis need not be performed before imperative code is executed.
-
Static analysis can find faults that are hard to find with
-
Extensive statistic analysis will not be needed if white- Box testing is to be performed.
A
Correct answer
Explanation
When a user-declared constructor is defined, the compiler stops generating the default constructor. This struct has two user-declared constructors: a copy constructor 'A(A& a)' and a converting constructor 'A(double d)'. Because at least one constructor is explicitly declared, the compiler will NOT generate any additional constructors (no default constructor, no copy constructor since one exists, no move constructors). Therefore, the number of implicitly-defined constructors is 0.
B
Correct answer
Explanation
A function call is not always an rvalue in C/C++. Whether it's an rvalue depends on the return type - if a function returns by value, the call is an rvalue, but if it returns a reference, it can be an lvalue. For example, a function returning int& can be used as an lvalue.