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
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.
A
Correct answer
Explanation
Inline functions eliminate the function call and return overhead by replacing the call site with the actual function body at compile time. This avoids stack frame creation, parameter passing, and jump instructions, which can improve execution speed for small, frequently called functions.
B
Correct answer
Explanation
In C++, default arguments must be specified from right to left. If a parameter has a default value, all parameters to its right must also have default values. Here, parameter 'a' has a default value but parameter 'b' (to its right) does not, making this declaration invalid.
-
Array
-
Pointer
-
Union
-
Function
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.
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.
-
Sequences of actual & formal parameters may differ.
-
Numbers of actual & formal parameters must be the same.
-
Types of actual & formal parameters must be the same.
-
None of these
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.
-
local variables
-
formal variables
-
global variables
-
actual variables
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.
-
1
-
0
-
Multiple
-
They don't return any value
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.
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.
-
End of link list
-
Empty pointer field of structure
-
The link list is empty
-
None of these
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.
-
*p.mem
-
(*p).mem
-
*(p.mem)
-
None of these
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.
-
Integer
-
Character
-
Structure
-
String
-
Traversing
-
Searching
-
Merging
-
None of these
D
Correct answer
Explanation
Traversing (visiting each element), searching (finding specific elements), and merging (combining structures) are all valid, fundamental data structure operations. Since all options A-C are valid operations, the correct answer is D - 'None of these' represents that there is no invalid operation in the list.
-
frame check sequence
-
error detecting code
-
checksum
-
flow control
A
Correct answer
Explanation
Frame Check Sequence (FCS) is the error-detecting code added to data frames at the data link layer. It uses mechanisms like CRC (Cyclic Redundancy Check) to detect transmission errors. Checksum is a specific type of error-detecting code, but FCS is the broader, more accurate term for the field in network frames. Flow control is a separate function for managing data transmission rates, not error detection.
-
semi-static
-
static
-
semi-dynamic
-
dynamic
-
None of these
A
Correct answer
Explanation
This is the right answer.