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

  2. WAIT

  3. Both 1 and 2

  4. None of these

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

SIGNAL operation increments the semaphore value, potentially waking up waiting processes. WAIT decrements it. These are the two primitive semaphore operations used for inter-process synchronization.

Multiple choice
  1. True

  2. False

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

In programming, functions can return various data types including primitive values (numbers, strings, booleans) and complex objects. Objects are a valid return type in languages like JavaScript, Python, and many others.

Multiple choice
  1. Array

  2. Pointer

  3. Union

  4. Function

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

Union is a user-defined data type that allows different data types to share the same memory location. Arrays and pointers are built-in types provided by the language, while functions are program constructs, not data types. Union, along with struct, enum, and class, must be defined by the programmer before use.

Multiple choice
  1. i=*p

  2. *p=i

  3. p=&i

  4. *p=&i

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

Assignment D (*p=&i) is invalid. The left side *p dereferences the pointer to access the integer value it points to, while &i gives the address of i. You cannot assign an address to an integer value. Assignments A and B require p to point to valid memory first, and C correctly stores i's address in p.

Multiple choice
  1. Sequences of actual & formal parameters may differ.

  2. Numbers of actual & formal parameters must be the same.

  3. Types of actual & formal parameters must be the same.

  4. None of these

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

During function calls, the sequence (order) of actual and formal parameters must match exactly. You cannot rearrange the order of arguments - the first actual parameter maps to the first formal parameter, the second to the second, and so on. This is why option A is the incorrect statement.

Multiple choice
  1. local variables

  2. formal variables

  3. global variables

  4. actual variables

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

The variables passed to a function during a function call are called actual parameters (or actual arguments). They are the values or expressions provided by the caller. Formal parameters are the variables declared in the function definition that receive these values. Local and global variables are storage duration specifiers, not call-related terms.

Multiple choice
  1. 1

  2. 0

  3. Multiple

  4. They don't return any value

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

In most programming languages including C/C++, functions can only return exactly one value. While there are workarounds like returning pointers/arrays or using reference parameters, the formal return statement itself returns only one value. This is a fundamental limitation.

Multiple choice
  1. True

  2. False

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

C++ allows variables to be declared anywhere in the program, not just at the beginning of a block. This is a key difference from C89. Variables can be declared at their point of first use, which improves code readability and allows initialization closer to where values are needed.

Multiple choice
  1. End of link list

  2. Empty pointer field of structure

  3. The link list is empty

  4. None of these

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

In linked lists, a null pointer (NULL in C/C++) marks the end of the list. When traversing, encountering a null next pointer signals there are no more nodes to follow. This is different from an empty list (where the head pointer itself is null) or an empty structure field.

Multiple choice
  1. *p.mem

  2. (*p).mem

  3. *(p.mem)

  4. None of these

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

To access a structure member through a pointer, you must dereference the pointer first before applying the dot operator. (*p).mem correctly dereferences p to get the structure, then accesses mem. The shorthand p->mem is equivalent and more commonly used. *p.mem would try to dereference a non-existent p.mem, and *(p.mem) is invalid.