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
  1. calls itself

  2. is equivalent to the loop

  3. has termination condition

  4. does not return a value

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

Recursive functions are capable of returning values, such as the result of a factorial or Fibonacci calculation. The other statements are true: they call themselves, require a termination condition to avoid infinite loops, and can be logically replaced by iterative loops.

Multiple choice
  1. int

  2. char

  3. float

  4. none of these

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

The switch statement in C requires the controlling expression to be of an integral type, such as int, char, or an enumeration. Floating-point values are not allowed because they cannot be reliably checked for exact equality due to precision issues.

Multiple choice
  1. 1-a, 2-b, 3-c, 4-d

  2. 1-a, 2-d, 3-b, 4-c

  3. 1-a, 2-c, 3-b, 4-d

  4. None of these

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

Local variables are stored on the stack, while global and static variables are stored in the data segment of main memory. Register variables are stored in CPU registers for faster access, matching the pairs 1-a, 2-d, 3-b, and 4-c.

Multiple choice
  1. II

  2. I, II

  3. II, III

  4. None of these

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

Command line arguments are always passed to the main function as an array of strings, even if they represent numeric values. Statement I is false because arguments are runtime inputs, and statement III is false because the first argument is the program name.

Multiple choice
  1. It is used to store a direct pointer to the new value, but call release on the old value and retain on the new one.

  2. It uses a direct pointer to the new value.

  3. It increases the retain count of an object by 1.

  4. It decreases the retain count of an object by 1.

  5. It makes a copy of an object and returns it with retain count of 1.

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

Assign is used to set a property's pointer to the address of the object without retaining it or otherwise curating it.

Multiple choice
  1. These exceptions are raised implicitly.

  2. These exceptions can be handled explicitly also.

  3. These are pre-defined exceptions and given a name in Oracle.

  4. EXCEPTION_INIT has associate a predefined Oracle error number to a programmer_defined exception name.

  5. The pragma EXCEPTION_INIT is declared in the declarative part of a PL/SQL block.

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

These are not the exceptions that occur frequently. So, these are not predefined and cannot be given a name in Oracle.

Multiple choice
  1. An user-defined exception must be declared and then raised explicitly.

  2. An user defined exception can be created using a RAISE statement.

  3. The procedure DBMS_STANDARD. RAISE_APPLICATION_ERROR can also throw an user defined exception.

  4. RAISE statements can raise predefined exceptions and also user defined exceptions.

  5. User-defined exceptions are declared in the exception section with their types as exceptions.

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

This is false as user defined exceptions are declared in the declaration section with their types as exception.

Multiple choice
  1. These exceptions are internally defined exceptions with a name.

  2. These exceptions are raised by the system.

  3. The storage error is a predefined exception.

  4. Out of memory is a predefined exception.

  5. ZERO_DIVIDE is an example of predefined exception.

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

This is an internally defined exception and not a predefined exception.

Multiple choice
  1. 0

  2. negative

  3. positive

  4. none of these

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

The code provided is: If(num<=0) { If(num<0) print(negative) Else print(positive) }. If num is 0, the first condition (0<=0) is true. The inner condition (0<0) is false, so the else block executes, printing 'positive'.