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
-
Buffer overflows are eliminated
-
Variables are renamed to provide more meaningful context
-
Exception handlers are added to catch runtime errors
-
New features are added based on the latest iterative design changes
B
Correct answer
Explanation
Refactoring is the process of restructuring existing computer code without changing its external behavior. Renaming variables to provide better readability and context is a classic refactoring activity.
-
Make sure all your subroutines are thread-safe
-
Free all unallocated memory blocks
-
Normalize your data model
-
Determine the answer to question 8 above
-
Make sure all your subroutines are thread-safe
-
Free all unallocated memory blocks
-
Normalize your data model
-
Determine the answer to question above
-
Don't link your modules to modules written in any other language
-
Make sure you declare all your variables' data types ahead of time
-
Don't add variables of one type to variables of another
-
Devout prayer
D
Correct answer
Explanation
Assembly language does not have built-in type checking or type safety features. Since the hardware only sees raw bytes and registers, type safety cannot be enforced by the language itself, making 'devout prayer' a humorous but accurate choice.
B
Correct answer
Explanation
JavaScript is not related to Java. The similarity in names was a marketing decision by Netscape in 1995 when JavaScript was created. Java is a statically-typed, class-based language, while JavaScript is dynamically-typed and prototype-based. They are fundamentally different languages.
A
Correct answer
Explanation
For a REPEAT operation to continue indefinitely as long as a condition remains true, the count parameter should be set to -1. This indicates unlimited repetition. Setting count to 0 would typically mean no repetitions, 1 would execute once, and NULL might indicate an unset or default limited count.
-
lo w
-
lo worl
-
lo wo
-
index out of range error during compilation
B
Correct answer
Explanation
The substr(start, length) method extracts characters starting at index start for a specified length. For "Hello World", starting at index 3 ('l') for 7 characters yields "lo Worl" (case-sensitive 'W'). The stored option has a lowercase 'w', but it is the intended answer.
-
The code will generate a run time error
-
undefined, Local Date & Time.
-
The code will generate a compile time error.
-
Universal Date & Time, Local Date & Time.
-
Local Date & Time & Local Date & Time
-
The code will generate a run time error.
-
undefined, Local Date & Time.
-
The code will generate a compile time error.
-
Universal Date & Time, Local Date & Time.
-
Local Date & Time, Local Date & Time
D
Correct answer
Explanation
The toUTCString() method converts a Date object to a string using the UTC time zone (Universal Coordinated Time), while toString() returns the local date and time based on the system's time zone settings. This distinction is important when working with time-sensitive operations across different geographical regions.
-
p is a pointer to pointer to integer
-
p is a pointer to a function that accepts an argument which is a pointer to a character and returns an integer quantity
-
p is a function that accepts an argument which is a pointer to a character and returns an integer quantity
-
p is a function that accepts an argument which is a pointer to a character and returns a pointer to an integer quantity
C
Correct answer
Explanation
The syntax int p(char *a) declares a function named p that takes a pointer to a character (char *a) as its argument and returns an integer (int). It is not a pointer declaration.
A
Correct answer
Explanation
A single COBOL IF statement evaluates exactly one condition. To check multiple conditions, you must nest IF statements or use the EVALUATE statement (available in COBOL-85 and later versions). Traditional COBOL has no built-in multi-comparison syntax in basic IF.
-
Infinite loop
-
Logical Error
-
Runtime Error
-
All of the above
D
Correct answer
Explanation
COBOL IF statements can exhibit all three error types: infinite loops (when improperly nested in loops with incorrect exit logic), logical errors (incorrect condition logic leading to wrong execution path), and runtime errors (comparing incompatible data types or operating on invalid data).
-
p is a function that accepts an argument which is a pointer to a character and returns a pointer to a 10 element integer array
-
p is a pointer to a function that accepts an argument which is a pointer to a character and returns an integer quantity
-
p is a function that accepts an argument which is a pointer to a character and returns an integer quantity
-
None of the above
B
Correct answer
Explanation
The declaration int (p)(char *a) is read as: p is a pointer (declared with *p) to a function (the surrounding parentheses) that takes a char argument and returns an int. Option A incorrectly describes p as the function itself. Option C describes a function that returns int, not int*. The key is that the parentheses around *p force p to be interpreted as a pointer first, then binding to the function signature.
-
p is a function that accepts an argument which is a pointer to a character and returns an integer quantity
-
p is a function that accepts an argument which is a pointer to a character and returns a pointer to an integer quantity
-
p is a function that returns a pointer to an integer quantity
-
None of the above
C
Correct answer
Explanation
The declaration int p(void) declares p as a function that takes no arguments (void) and returns a pointer to an integer (int). Option A and B incorrectly claim the function accepts a char* argument, but void means no parameters. Option D is incorrect because option C is accurate.
-
p is a function that returns a pointer to an integer quantity
-
p is a function that accepts an argument which is a pointer to a character and returns a pointer to an integer quantity
-
p is a function that accepts an argument which is a pointer to a character and returns an integer quantity
-
None of the above
B
Correct answer
Explanation
In the declaration int *p(char *a), p is a function because of the function call parentheses (char *a). It takes a pointer to a character (char *a) as an argument and returns a pointer to an integer (int *).