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
  1. A function that takes an integer pointer as argument and returns an integer

  2. A function that takes an integer pointer as argument and returns an integer pointer

  3. A pointer to a function that takes an integer pointer as argument an returns

  4. A function that takes an integer pointer as argument returns a function pointer

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

Multiple choice
  1. always be evaluated

  2. be evaluated only if the definition is L-attributed

  3. be evaluated only if the definition has synthesized attributes

  4. never be evaluated

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

Every S (synthesized) -attributed definitions is L- attributed. So in a bottom-up evaluation of SDD inherited attributes can be evaluated only if the definition has synthesized attributes.

Multiple choice
  1. In statically typed languages, each variable in a program has a fixed type

  2. In un-typed languages, values do not have any types

  3. In dynamically typed languages, variables have no types

  4. In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program

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

(1) True for statically typed languages where each variable has fixed type. Similarly (4) is also correct. (2) True, in un-typed languages types of values are not defined. But option (3) is false, since in dynamically typed language variables have dynamically changing types but not that they have no type.

Multiple choice
  1. 115, 220

  2. 25, 220

  3. 25, 15

  4. 115, 105

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

Multiple choice
  1. 115, 220

  2. 25, 220

  3. 25, 15

  4. 115, 105

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

Multiple choice
  1. Smaller sizes of executable files

  2. Lesser overall page fault rate in the system

  3. Faster program startup

  4. Existing programs need not be re-linked to take advantage of newer versions of libraries

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

The advantages of shared dynamically linked libraries include. (1) smaller size of executable since less data (2) lesser overall page fault rate. (3) No need for re-linking if newer versions of libraries are there. But since compilation time doesn't include linking so a long linking time required during runtime in DLL' s so slow startup.

Multiple choice
  1. X = Y + Z

  2. t1 = Y + Z; X = t1

  3. t1 = Y; t2 = t1 + Z; X = t2

  4. t1 = Y; t2 = Z; t3 = t1 + t2; X = t3

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

Multiple choice
  1. II and V only

  2. I, III and IV only

  3. I, II and V only

  4. II, III and V only

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

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. 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.