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. float, int pointer

  2. float pointer, int pointer

  3. float, int

  4. float pointer, int

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

The macro floatptr expands to float , so floatptr f1,f2 becomes float *f1,f2. Due to precedence, this declares f1 as float but f2 as float (only f1 gets the asterisk). For intptr (defined as int ), intptr p1,p2 becomes int *p1,p2, declaring p1 as int and p2 as int. Therefore f2 is float and p2 is int.

Multiple choice
  1. only from the innermost loop

  2. only from the innermost switch

  3. from all loops and switches

  4. from the innermost loop or switch

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

The break statement in C++ exits from the innermost loop or switch statement that contains it. It does not exit from all nested loops or switches simultaneously - only the immediately enclosing one. To exit from multiple levels, you would need multiple break statements or a different control structure like goto.

Multiple choice
  1. Missing parentheses in return statement.

  2. The function should be defined as int f(int a, int b).

  3. Redeclaration of 'a'.

  4. None of the above

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

The function has a parameter named 'a', and then inside the function body, 'a' is redeclared as a local variable with 'int a;'. This creates a redeclaration error because you cannot declare a variable with the same name as a parameter in the same scope. Option C correctly identifies this as 'Redeclaration of a'. The parameter 'a' is already declared in the function signature, so declaring it again inside is a compilation error.

Multiple choice
  1. an operator

  2. a label

  3. a variable

  4. a function

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

The goto statement transfers control to a labeled statement within the same function. You use goto with a label like 'my_label:' and then 'goto my_label;' to jump to that point. Option B correctly states that goto causes control to go to 'a label'. It cannot jump to operators (A), variables (C), or functions (D) - only to labeled statements within the current function.

Multiple choice
  1. the loop in which it occurs

  2. the block in which it occurs

  3. the function in which it occurs

  4. the program in which it occurs

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

The exit() function in C++ terminates the entire program immediately, not just the current function or loop. It performs cleanup and ends program execution. Option D correctly states it causes exit from 'the program in which it occurs'. This is different from return, which only exits from the current function. The exit() function is defined in header and affects the whole program.

Multiple choice
  1. Dim i as integerPrivate Sub Command1_Click ()i = 1Do until i > 5Print computer; ii = i + 1LoopEnd Sub

  2. Dim i as integerPrivate Sub Command1_Click ()i = 1Do while i <= 5Print computer; ii = i + 1LoopEnd Sub

  3. Dim i as integerPrivate Sub Command1_Click ()i = 1Do while i <= 8Print computer; ii = i + 1LoopEnd Sub

  4. Dim i as integerPrivate Sub Command1_Click ()i = 1Do while i <= 8Print computer; ii = i + 1;LoopEnd Sub

  5. Dim i as integerPrivate Sub Command1_Click ()i = 1Do while i <= 3Print computer; ii = i + 1;LoopEnd Sub

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

This is the correct code.

Multiple choice
  1. IF-ELSE

  2. DO-WHILE

  3. FOR-NEXT

  4. WHILE

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

IF-ELSE is a conditional branching structure that executes different code blocks based on a condition. It does not repeat code execution. DO-WHILE, FOR-NEXT, and WHILE are all looping constructs that repeatedly execute code blocks.