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
-
Initialization
-
Loop Body
-
Test statement
-
The word "while"
D
Correct answer
Explanation
To solve this question, the user needs to know the basic structure of loops. Every loop has three main sections:
- Initialization
- Loop Body
- Test Statement
The initialization section is used to initialize the loop variable, while the test statement is used to evaluate a condition that determines whether the loop should continue or terminate. The loop body contains the code that is executed repeatedly until the test statement evaluates to false.
Option D is not a section of all types of loops. "While" is a keyword that is used to define a type of loop known as a "while loop". However, not all types of loops use the keyword "while". For example, the "for loop" uses a different syntax to define the loop.
Therefore, the correct answer is:
The Answer is: D
-
Initialization
-
Loop Body
-
Test statement
-
Update
B
Correct answer
Explanation
In a for loop, the parentheses contain initialization, test condition, and update sections separated by semicolons. The loop body (the code to execute) is outside these parentheses, typically in curly braces. Options A, C, and D are all part of the for loop declaration within the parentheses.
-
A group of code lines that performs a specific task
-
A group of code lines that performs a whole program
-
Something that contains an ‘init’
-
The purpose of Java
A
Correct answer
Explanation
A function is a modular, reusable block of code that performs a specific task. Option A correctly captures this definition. Option B is incorrect because a function typically performs a sub-task, not an entire program. Option C is too specific (not all functions have 'init'), and Option D is wrong because functions exist in all programming languages, not just Java.
-
CHAR
-
ORD
-
REM
-
REVERSE
-
ANNUITY
-
None
F
Correct answer
Explanation
All listed functions are valid COBOL intrinsic functions: CHAR converts numeric to character, ORD returns ASCII ordinal value, REM calculates remainder of division, REVERSE reverses character strings, and ANNUITY calculates financial annuity values. Therefore 'None' correctly indicates that none of these is NOT an intrinsic function.
-
Compilation Error
-
Executes successfully
-
Run time Error
-
Logical Error
B
Correct answer
Explanation
When you redefine a field with a larger picture clause, you're creating an alternate view of storage. Most systems allow this and the code executes, though there may be overlapping memory concerns. Option A (Compilation Error) would occur for syntax violations, and Option C (Run time Error) typically happens during execution for invalid operations.
B
Correct answer
Explanation
Pega's declarative rules are specifically designed for property calculations and validations because they execute automatically when dependencies change, improve performance, and reduce manual coding. The statement incorrectly advises against using them.
-
%macro hex(start=1, stop=10, incr=1); %local i; data null; %do i=&start to &stop by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; %end; run; %mend hex;
-
%macro hex(start=1, stop=10, incr=1); %local i; data null; %do i=&start %to &stop %by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; %end; run; %mend hex;
-
%macro hex(start=1, stop=10, incr=1); %local i; data null; %do i=&start to &stop by &incr; value=&i; put "Hexadecimal form of &i is " value hex6.; run; %mend hex;
-
%macro hex(start=1, stop=10, incr=1); %local i; data null; %do i=&start to &stop by &incr; value=&i; put "Hexadeciaml form of &i is " value hex6.; %end run; %mend hex;
B
Correct answer
Explanation
In SAS macro loops, the iteration syntax requires percent signs before TO and BY: %DO variable=start %TO stop %BY increment. Options A, C, and D use the incorrect DATA step syntax (to, by without %). Option B correctly uses %TO and %BY, and properly structures the macro with %LOCAL for the loop variable and matching %END. The other options either use wrong syntax or have structural errors (missing %END, misspelling, wrong placement of RUN).
-
A %MACRO statement must always be paired with a %MEND statement.
-
A macro definition can include macro variable references, but it cannot include SAS language statements.
-
Only macro language statements are checked for syntax errors when the macro is compiled.
-
Compiled macros are stored in a temporary SAS catalog by default.
B
Correct answer
Explanation
A %MACRO must always be terminated by %MEND, so that statement is true. Macro definitions can contain SAS language statements, making the claim that they cannot include such statements false. The other statements about syntax checking and temporary catalog storage are true, so the false option is the one marked correct.
-
you must place %DO and %END statements around code that describes the conditional action, if that code contains multiple statements.
-
the %ELSE statement is optional.
-
you cannot refer to DATA step variables in the logical expression of the %IF statement.
-
all of the above.
D
Correct answer
Explanation
In SAS macro programming, multiple statements in a conditional block require %DO and %END. The %ELSE clause is optional, and DATA step variables cannot be directly referenced in macro %IF conditions because macros execute before the DATA step compiler runs. Thus, all statements are correct.
B
Correct answer
Explanation
TEMPLATE is a utility control statement that provides a template mechanism for specifying utility parameters, but it is not specific to the REPAIR utility. It can be used with various DB2 utilities, not exclusively REPAIR. The statement in the question incorrectly suggests a specific relationship that doesn't exist.
A
Correct answer
Explanation
The finally block always executes when an exception is thrown, regardless of whether a catch block handles it. This is guaranteed behavior except in extreme cases like System.exit() or JVM crash. It ensures cleanup code runs.
-
All Blank values
-
Zeroes to INT and spaces to ALPHA
-
Spaces to INT and Zeroes to ALPHA
-
Zeroes to INT and BLANK to ALPHA
B
Correct answer
Explanation
The INITIALIZE action in Master Craft sets default values for component properties. The default behavior assigns zeroes to integer (INT) type fields and spaces to alphanumeric (ALPHA) type fields, providing clean initial values that can be overwritten during component execution.
B
Correct answer
Explanation
The REPLACE keyword in a COPY statement allows you to substitute specific words or literals, overriding default values supplied by the copied program‑unit. INIT, ASSIGN, and SET do not provide this overriding capability, making REPLACE the correct answer.
-
CONTINUE statement gives control to the verb following the next period.
-
NEXT SENTENCE gives control to the verb after the explicit scope terminator.
-
CONTINUE gives control to the verb after the explicit scope terminator.
-
None of the above
C
Correct answer
Explanation
In COBOL the CONTINUE verb is a no‑operation that passes control to the next executable statement after the current scope terminator, such as the end of a paragraph or section. Therefore the statement that describes CONTINUE giving control after the explicit scope terminator is true.
-
EXAMINE
-
IF THEN ELSE
-
EXHIBIT
-
None of the above
B
Correct answer
Explanation
The COBOL II EVALUATE construct was introduced to replace nested IF‑THEN‑ELSE logic, providing a clearer, multi‑way selection mechanism. It does not relate to EXAMINE or EXHIBIT statements, so the correct choice is IF THEN ELSE. It simplifies complex condition handling by allowing multiple WHEN clauses, thereby serving the same purpose as the traditional IF‑THEN‑ELSE chain.