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

Multiple choice technology programming languages
  1. Header

  2. Declarative

  3. Executable

  4. Exception

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

To solve this question, the user needs to understand the structure of a PL/SQL block and the purpose of each section.

The PL/SQL block is divided into the following sections:

  1. Header: This section is optional and contains comments and declarations of global variables and cursors.

  2. Declarative: This section is optional and contains declarations of local variables, cursors, types, and subprograms.

  3. Executable: This section is mandatory and contains the code that performs the desired operations.

  4. Exception: This section is optional and contains handlers for exceptions that may be raised during the execution of the executable section.

The correct answer is:

D. Exception

Functions for error trapping are contained in the exception section of a PL/SQL block. This section contains handlers for exceptions that may occur during the execution of the executable section. These handlers allow the program to gracefully handle errors and continue executing, rather than crashing or terminating unexpectedly.

Multiple choice technology programming languages
  1. NULL

  2. 0

  3. Results in a compilation error

  4. An exception will be raised

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

In PL/SQL, variables declared without initialization are assigned NULL by default, unlike some languages where primitives default to zero. NULL is a valid value in Oracle, distinct from 0 or empty string. The code compiles successfully; no error occurs until runtime operations on NULL.

Multiple choice technology programming languages
  1. Header

  2. Declarative

  3. Executable

  4. Exception

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

RAISE appears in the executable section to throw exceptions, and in the exception section to re-raise them after custom handling. PL/SQL blocks have DECLARE (declarative), BEGIN (executable), and EXCEPTION sections; there is no 'header' section. RAISE is an executable action.

Multiple choice technology web technology
  1. function myFunction()

  2. function=myFunction()

  3. function:myFunction()

  4. function myFunction

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

Functions in JavaScript are created using the 'function' keyword followed by the function name and parentheses: function myFunction(). The equals sign or colon are not part of function declaration syntax.

Multiple choice technology web technology
  1. call myFunction()

  2. call function myFunction

  3. myFunction()

  4. call function myFunction()

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

To call a function in JavaScript, simply write the function name followed by parentheses: myFunction(). The 'call' keyword is not used in JavaScript - that's a different language. Functions are invoked by using their name directly.

Multiple choice technology web technology
  1. while (i<=10)

  2. while (i<=10;i++)

  3. while i=1 to 10

  4. while (i=0;i<=10;i++)

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

A while loop in C-style syntax requires a condition in parentheses: while (condition). Option B incorrectly adds i++ which is for-loop syntax, and options C and D use Pascal/BASIC style (for i=1 to 10) or full for-loop syntax respectively.

Multiple choice technology programming languages
  1. ACCEPT

  2. MOVE

  3. FIND

  4. STRING

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

In standard COBOL, the verbs ACCEPT, MOVE, and STRING are all valid COBOL verbs. FIND is not a standard COBOL verb - it's typically used in database systems like SQL or in some mainframe query utilities, but not in core COBOL programming. This makes 'FIND' the correct answer to what 'is not a COBOL verb'.

Multiple choice technology mainframe
  1. COMP-1

  2. COMP

  3. COMP-3

  4. DISPLAY

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

COMP-1 (single-precision floating point) in COBOL does not accept a PIC (PICTURE) clause because it uses internal binary representation, not the character-based format that PIC defines. COMP, COMP-3, and DISPLAY can all have PIC clauses to define their data layout. COMP-1 is pre-defined as a 4-byte floating-point format.

Multiple choice technology programming languages
  1. Compilation succeeds

  2. Compilation fails due only to an error on line 15

  3. Compilation fails due only to an error on line 16

  4. Compilation fails due only to an error on line 17

  5. Compilation fails due only to an error on line 18

  6. Compilation fails due to errors on multiple lines

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

The BufferedWriter constructor requires a Writer object as its argument. On line 15, a File object is passed, which does not inherit from Writer, causing a compilation failure. Lines 16, 17, and 18 are valid because FileWriter, PrintWriter, and BufferedWriter all extend Writer.

Multiple choice technology databases
  1. NULL

  2. 0

  3. Results in a compilation error

  4. An exception will be raised

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

The answer to the question is A. NULL.

When a variable is declared in PL/SQL without an initial value, it is initialized to NULL. This means that the variable has no value, and any attempt to use it will result in a NULL value.

Option B is incorrect because the value of a NUMBER variable is not automatically initialized to 0. Option C is incorrect because a compilation error will not occur if a variable is declared without an initial value. Option D is incorrect because an exception will not be raised if a variable is declared without an initial value.

Here is an example of how a NULL value is handled in PL/SQL:

DECLARE
  v_number NUMBER;
BEGIN
  v_number := NULL;
  dbms_output.put_line(v_number); -- This will print 'NULL'
END;

As you can see, the value of v_number is printed as NULL when it is first used in the executable section of the PL/SQL block. This is because the variable was declared without an initial value, and therefore its value is NULL.

Multiple choice technology databases
  1. Header

  2. Declarative

  3. Executable

  4. Exception

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

Error trapping uses EXCEPTION handlers within the EXCEPTION section of a PL/SQL block. The EXECUTABLE section contains the runtime code that may raise exceptions. The EXCEPTION section is where handlers are defined. Header has no error handling. Declarative defines variables/types.