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. The code contains loop invariant computation

  2. There is scope of common sub-expression elimination in this code

  3. There is scope of strength reduction in this code

  4. There is scope of dead code elimination in this code

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

All the statements are true except option (4) since there is no dead code to get eliminated

Multiple choice
  1. S1 and S2

  2. S1 and S4

  3. S3

  4. S1 and S5

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

Multiple choice
  1. Takes $\Theta$(3n) and $\Omega$(2n) time if hashing is permitted
  2. Takes $\Theta$(n3) and $\Omega$ (n2.5) time in the key comparison model
  3. Takes $\Theta$(n3) time and space
  4. Takes $\Theta$($\sqrt{n}$) time only if the sum of the 2n elements is an even number
Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Multiple choice
  1. One stack is enough

  2. Two stack are needed

  3. As many stacks as the height of the expression tree are needed

  4. A Turning machine is needed in the general case

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

To evaluate an expression we need only 1 stack in which the operands & operators are pushed into, & then evaluated using pop operations.

Multiple choice
  1. u = x + 10 and v = y

  2. u = x + 10 and v $\ne$ y
  3. u + 10= x and v = y

  4. u + 10 = x and v $\ne$ y
Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Initial value of a is 10 and its address and the value of 'a' would be different for both the parent and child processes. So, (1) and (2) are incorrect. Also, parent process executes a = a − 5 = 5 = u and child executes a = a + 5 = 15 = x. Therefore, u + 10 = x.

Multiple choice
  1. The implementation may not work if context switching is disabled in P

  2. Instead of using fetch-and -set, a pair of normal load/store can be used

  3. The implementation of V is wrong

  4. The code does not implement a binary semaphore

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

If there are more than two processes and context & switching processes is disabled in P then this implementation doesn't work properly and can't synchronize the processes.

Multiple choice
  1. Variable name should start with alphabet.

  2. Variable name contains the space.

  3. Variable name should be different from the keywords.

  4. Variable name contains underscore(_).

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

Space is not allowed in variable name. For example, RollNum is valid and Roll Num is invalid variable name.

Multiple choice
  1. value and types of variable

  2. name and location in the memory

  3. its value can change during execution.

  4. all of these

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

All of these are the characteristics of Variable. Variables must have its name, data type and value. Without data type variables cannot be declared. Variables also have some location in memory. And variables' value can be changed during the execution of a program.

Multiple choice
  1. 29

  2. 24

  3. 23

  4. 20

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

The clock cycles are per block; if an instruction size is 2 then it requires twice no. of clock cycles.

So answer is (2). 

Multiple choice
  1. <font size="2">I</font>t allocates space for the literals.

  2. <font size="2">I</font>t compute<font size="2">s</font> the total length of the program.

  3. <font size="2">I</font>t builds the symbol table for the symbols and their value.

  4. <font size="2">A</font>ll of these

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

The first pass of a two-pass assembler performs three key tasks: allocating space for literals/pool table, computing the total program length (for address calculation), and building the symbol table with symbol addresses. All options are correct.

Multiple choice
  1. Global common subexpression

  2. Copy propagation

  3. Register allocation

  4. Code motion

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

a, b and d are ways of code optimization, register allocation happens in code generation stage, so the option c is the odd one.