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
-
call by reference
-
call by value
-
call by address
-
All the above
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.
-
The instance gets garbage collected.
-
The code on line 33 throws an exception.
-
. The code on line 35 throws an exception
-
The code on line 31 throws an exception
-
The code on line 33 executes successfully
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.
-
strcpy
-
memcpy
-
both memcpy and strcpy
-
none
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.
-
WaitProperty
-
Sync
-
Exit
-
Wait
D
Correct answer
Explanation
The Wait statement in QTP pauses test execution for a specified number of seconds. WaitProperty waits for a property value, Sync waits for navigation, and Exit terminates a loop/action. Only Wait creates a simple time-based pause.
A
Correct answer
Explanation
QTP/UFT allows working with multiple function libraries simultaneously. You can have multiple function library files associated with a test and can edit them concurrently.
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.
-
int $x
-
int 123
-
int _123
-
int #dim
-
int %percent
-
int central_sales_region_Summer_2005_gross_sales
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.
D
Correct answer
Explanation
Single ampersand (&) prompts the user each time it's referenced. Double ampersand (&&) defines the variable once; subsequent references reuse the stored value without prompting.
-
the use of a variable before it has been defined
-
memory leaks
-
unreachable (“dead”) code
-
array bound violations
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.
-
For loop
-
Do-While loop
-
Method
-
All of the above
-
None of the above
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).
-
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
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.
-
GENERATE
-
MODIFY
-
ALTER
-
MEMBER
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.
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.
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.