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
-
These are lines read and processed by the preprocessor.
-
They do not produce any code by themselves.
-
These must be written within the main program.
-
They end with a colon.
A
Correct answer
Explanation
Preprocessor directives are lines processed by the preprocessor before compilation. They begin with # and include commands like #include, #define, #ifdef. Option A correctly states this. Option B is incorrect because directives like #define DO produce code (macro expansion). Option C is wrong because directives must be written BEFORE main, not within it. Option D is incorrect because directives don't end with colons - they're line-based.
-
string that varies during program execution
-
portion of memory to store a determined value
-
number that is frequently required in a program
-
fixed value
B
Correct answer
Explanation
A variable is a named portion of memory that stores a value that can change during program execution. The key aspects are: 1) It occupies memory space, 2) It holds a value, 3) The value can vary (hence "variable"). Option A is incorrect because variables are not strings themselves - they have names and store values. Option C describes constants, not variables. Option D describes constants/literals, which are fixed values.
-
compilation error
-
warning when the program is compiled
-
warning when the program is executed
-
error at link time
A
Correct answer
Explanation
Missing a header file like math.h means the compiler cannot find function declarations for math functions. In modern C/C++ standards (C99+, C++), this causes a compilation error because implicit function declarations are not allowed. The compiler needs to see function prototypes to validate function calls.
D
Correct answer
Explanation
A selection statement allows the program to choose between different execution paths based on a condition. In C++, 'switch' is a selection statement that selects one of many code blocks to execute. 'break' is used within loops and switch to exit, 'goto' is an unconditional jump, and 'exit' is a library function that terminates the program.
-
the value of the variable is passed to the function so that it can manipulate it
-
the location of variable in memory is passed to the function so that it can use the same memory area for its processing
-
the value of the variable cannot be changed within the calling function
-
the calling function cannot return the manipulated value
B
Correct answer
Explanation
Pass by reference means passing the memory address (location) of the variable to the function. This allows the function to directly access and modify the original variable in memory, rather than working with a copy. Changes made inside the called function affect the original variable in the calling function.
-
a void area in memory is returned so that you can populate it
-
no data type is returned
-
void is not a valid data type
-
integer data type is returned
B
Correct answer
Explanation
The 'void' return type specifically indicates that a function does not return any value to the caller. It is a valid and commonly used data type in C/C++ for functions that perform actions without producing a return value. Option A incorrectly describes void as a memory area, void is not about returning a memory area to populate.
-
address of the number of elements of the array
-
values of the first elements of the array
-
address of the first element of the array
-
number of elements of the array
C
Correct answer
Explanation
When an array is passed as an argument to a function, it 'decays' into a pointer to its first element. The function receives the memory address of element [0], not a copy of all elements or the count. This is why array parameters are often accompanied by a separate size parameter - the pointer alone doesn't convey array length.
-
num[1] is same as p+1
-
num[2] is same as &(p+2)
-
num[3] is same as *(p+3)
-
num is same as *p
C
Correct answer
Explanation
When p = num, p points to the first element. Array indexing num[i] is equivalent to *(num + i) or *(p + i). Option A is wrong because p+1 is an address, not a value. Option B is syntactically invalid - &(p+2) doesn't make sense. Option C is correct: num[3] = *(p+3) dereferences the pointer to get the value. Option D is wrong: *p gives the first element's value (3), not the array itself.
C
Correct answer
Explanation
Pop is the standard term for removing an element from a stack, operating on the top element following LIFO (Last-In-First-Out) order. Delete is too generic, peek views without removing, and remove is not the conventional terminology for stack operations in computer science.
-
To re-define built-in operators in a programming language (i.e. C++) to work with objects.
-
An event that arises when a computer is overheated.
-
A C++ program to process data in parallel.
-
A strategy in C++ to avoid deadlock.
A
Correct answer
Explanation
Operator overloading allows programmers to redefine how built-in operators (like +, -, *, etc.) work with user-defined objects or data types. This enables intuitive syntax (e.g., adding complex numbers with a+b) and is a key feature of C++ polymorphism. It has nothing to do with overheating, parallel processing, or deadlock avoidance.
-
Web form
-
Stack walk
-
Private
-
Public
-
Internal
E
Correct answer
Explanation
In this access modifier, access is limited to the current assembly.
-
INTn no operand
-
RET no operand
-
CALL subroutine/procedure
-
IRET no operands
-
INTO no operand
B
Correct answer
Explanation
This branch instruction is encountered by a microprocessor at the end of subroutine and it returns the control to the main program.
-
SIGNAL
-
WAIT
-
Both 1 and 2
-
None of these
B
Correct answer
Explanation
WAIT operation decrements the semaphore value. If the result is negative, the process is blocked. SIGNAL increments the semaphore. This is the fundamental semaphore operation pair for process synchronization.
-
SIGNAL
-
WAIT
-
Both 1 and 2
-
None of these
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.
-
binary
-
unary
-
general
-
none of these
A
Correct answer
Explanation
A binary semaphore can only take values 0 and 1, acting like a mutex lock. It's used for mutual exclusion. General (counting) semaphores can take non-negative integer values and manage multiple resource instances.