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
C Correct answer
Explanation

The macro floatptr expands to 'float *', so 'floatptr f1,f2' becomes 'float *f1,f2'. This declares f1 as a pointer to float, but f2 as a regular float (the * only binds to f1). Similarly, 'intptr p1,p2' becomes 'int *p1,p2', making p2 a regular int. This is a classic macro pitfall.

Multiple choice
  1. It will work correctly since the for loop covers the entire list.

  2. It may fail since each node “nptr” is freed before its next address can be accessed.

  3. This is invalid syntax for freeing memory.

  4. The loop will never end.

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

The loop frees nptr BEFORE reading nptr->next in the next iteration. After free(nptr), accessing nptr->next is undefined behavior - the memory has been deallocated. The correct approach is to save nptr->next BEFORE freeing nptr: next = nptr->next; free(nptr); nptr = next;

Multiple choice
  1. 3 0

  2. 5 3

  3. 3 5

  4. 5 0

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

The macro big(a,b) returns the larger value, so big(3,5) returns 5. The condition (3+5)>5 evaluates to true (8>5). When swap(a,b) expands, it executes temp=a; a=b; b=temp; making a=5 and b=3. The printf outputs "5 3". The key point is that the swap macro lacks braces, but it still executes sequentially.

Multiple choice
  1. Breaks out of the if statement

  2. Exits the function

  3. Compiler error

  4. Nothing

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

The break statement can only be used inside loops (for, while, do-while) or switch statements. Using break inside an if statement that is not inside a loop or switch causes a compilation error. The compiler will reject this code because break has no valid target to break out of.