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

Multiple choice technology programming languages
  1. Initialization

  2. Loop Body

  3. Test statement

  4. The word "while"

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To solve this question, the user needs to know the basic structure of loops. Every loop has three main sections:

  1. Initialization
  2. Loop Body
  3. 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

Multiple choice technology programming languages
  1. Initialization

  2. Loop Body

  3. Test statement

  4. Update

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. A group of code lines that performs a specific task

  2. A group of code lines that performs a whole program

  3. Something that contains an ‘init’

  4. The purpose of Java

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology mainframe
  1. CHAR

  2. ORD

  3. REM

  4. REVERSE

  5. ANNUITY

  6. None

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology mainframe
  1. Compilation Error

  2. Executes successfully

  3. Run time Error

  4. Logical Error

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. %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;

  2. %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;

  3. %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;

  4. %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;

Reveal answer Fill a bubble to check yourself
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).

Multiple choice technology programming languages
  1. A %MACRO statement must always be paired with a %MEND statement.

  2. A macro definition can include macro variable references, but it cannot include SAS language statements.

  3. Only macro language statements are checked for syntax errors when the macro is compiled.

  4. Compiled macros are stored in a temporary SAS catalog by default.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. you must place %DO and %END statements around code that describes the conditional action, if that code contains multiple statements.

  2. the %ELSE statement is optional.

  3. you cannot refer to DATA step variables in the logical expression of the %IF statement.

  4. all of the above.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology databases
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. All Blank values

  2. Zeroes to INT and spaces to ALPHA

  3. Spaces to INT and Zeroes to ALPHA

  4. Zeroes to INT and BLANK to ALPHA

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. CONTINUE statement gives control to the verb following the next period.

  2. NEXT SENTENCE gives control to the verb after the explicit scope terminator.

  3. CONTINUE gives control to the verb after the explicit scope terminator.

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. EXAMINE

  2. IF THEN ELSE

  3. EXHIBIT

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.