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 mainframe
  1. True

  2. False

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

Including DCLGEN (Declaration Generator) in COBOL-DB2 programs is not mandatory. DCLGEN generates COBOL data structure declarations matching DB2 table definitions, which provides type safety and simplifies host variable declarations. However, programmers can manually declare host variables without DCLGEN, making it optional despite being a best practice.

Multiple choice technology programming languages
  1. int i[][];

  2. int i[5][5];

  3. int []i[];

  4. int[][] a;

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

Java array declarations can use brackets on the type, after the variable name, or both. 'int i[][]' (C), 'int[]i[]' (D), and 'int[][] a' (D) are all legal. However, 'int i[5][5]' (B) is illegal because Java doesn't allow size specification in declarations - array sizes are set at initialization, not declaration.

Multiple choice technology databases
  1. True

  2. False

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

A CURSOR returns a set of rows (a result set), not a single scalar value. Scalar data types like NUMBER, VARCHAR2, or DATE can hold individual values, but a cursor is inherently a multi-row construct. To use a cursor, you must FETCH rows into appropriate variables or data structures. Therefore, a scalar data type cannot be the return type for a CURSOR.

Multiple choice technology databases
  1. True

  2. False

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

Functions cannot take OUT parameters as actual arguments. OUT parameters are used to return values from procedures or functions, so they must be variables with l-values (storage locations). A function call itself is an expression that returns a value and cannot be used as an OUT parameter destination. This is a fundamental constraint in parameter passing modes.

Multiple choice technology databases
  1. True

  2. False

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

Default values can be assigned to formal parameters in a function/procedure declaration. When the function is called without providing those arguments, the default values are used for the actual parameters. This allows optional parameters with sensible defaults. The statement refers to this common language feature.

Multiple choice technology databases
  1. Substitute( )

  2. Place value ( )

  3. NVL ( )

  4. Place( )

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

NVL is a standard SQL function (Oracle, DB2, PostgreSQL COALESCE similar) that replaces NULL values with a specified substitute value. Syntax is NVL(column, replacement_value) - if column is NULL, it returns replacement_value. Substitute, Place value, and Place are not standard SQL functions for NULL handling.

Multiple choice technology programming languages
  1. COBOL if statements are not used to compare variable values

  2. 1

  3. 2

  4. 3

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

A single COBOL IF statement can make exactly one comparison. The syntax is 'IF condition THEN...' where the condition is a single relational expression comparing two values. To evaluate multiple conditions, you must use nested IF statements or combine conditions with AND/OR within a single conditional expression, but the IF statement itself makes one logical comparison. This is a fundamental aspect of COBOL's conditional syntax.

Multiple choice technology programming languages
  1. Infinite loop

  2. logical error

  3. runtime error

  4. All of the above

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

All three error types are possible in a COBOL IF statement. Logical errors occur when the condition or logic is incorrect (e.g., wrong operator). Runtime errors can happen if a variable in the condition is uninitialized or has invalid data. Infinite loops can occur if an IF within a PERFORM loop or other looping construct never allows exit due to flawed logic. Therefore 'All of the above' is correct as each represents a valid category of error.

Multiple choice technology programming languages
  1. For Loop

  2. Do-While Loop

  3. Nested Loop

  4. While Loop

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

The COBOL PERFORM loop with UNTIL condition is equivalent to a Do-While loop in languages like Java or C++. Both execute the loop body at least once before checking the continuation condition. 'PERFORM paragraph-name UNTIL condition' will execute the paragraph first, then test the condition - this is exactly how Do-While works. While loops check condition before execution, and FOR loops are iteration-based with counters.

Multiple choice technology enterprise content management
  1. All blanks in the string value are removed

  2. First and Last blank is removed

  3. Only the first blank is removed

  4. Only the last blank is removed

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

Trim operations remove leading and trailing whitespace from strings. This means the first blank (leading) and last blank (trailing) are removed, but blanks within the string content remain unchanged. The trim operation does not remove all blanks from the entire string value.

Multiple choice technology mainframe
  1. Exits the paragraph

  2. Does Nothing

  3. Bring pointer back to starting point

  4. None of the Above

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

In COBOL, the EXIT statement is a paragraph terminator that performs no executable operation. It is typically used to end a paragraph without any processing, making 'Does Nothing' the correct answer.

Multiple choice technology programming languages
  1. Database Operations

  2. Delegate Operations

  3. File Handling Operations

  4. Memory Stream Operations

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

The lambda operator (=>) in C# is primarily used for creating anonymous functions that work with delegates and expression trees. Lambda expressions are extensively used with LINQ queries, event handlers, and functional programming patterns. While they can be used in various contexts, their main purpose is delegate manipulation.

Multiple choice technology programming languages
  1. String s=#”\teststring”;

  2. String s=”’\n teststring”;

  3. String s=@”\teststring”;

  4. none of above

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

In C#, prepending a string literal with the @ symbol creates a verbatim string literal. In verbatim strings, escape sequences such as backslashes are not processed, allowing backslashes to be written directly. The # symbol has no such function in C# string syntax.

Multiple choice technology programming languages
  1. int[,] myarray;

  2. int[][] myarray

  3. int[2] myarray

  4. none of above

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

In C#, a two-dimensional array is declared using the syntax int[,] myarray - the comma inside the brackets indicates a multidimensional array. Option B (int[][]) declares a jagged array (array of arrays), which is different from a true 2D array. Option C is invalid syntax.