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
-
It is just a fancy keyword, No purpose here
-
Prevents the compiler from assigning the function as an rvalue
-
Prevents the compiler from assigning the function as an lvalue
-
It makes sure that the return value is a const and is not changed by anyone else
C
Correct answer
Explanation
The const keyword before a function's return type (const int f(...)) prevents the function result from being used as an lvalue - you cannot assign to it. This means expressions like f() = 5 would be compile errors. The const refers to the return value being treated as read-only, not that it cannot be modified by others (option D is misleading - the returned value can still be modified if it's a reference/pointer).
-
Nothing is wrong. You are wrong.
-
Loops are not allowed inside the function scope, Since it degrades performance
-
My friend tried to return a pointer to a local function variable , which is invalid once the function call compltes.
-
The value i is not properly initialised, SO it may contain some garbage .
C
Correct answer
Explanation
The function returns a pointer to a local variable i. Local variables have automatic storage duration and are destroyed when the function returns. The returned pointer becomes a dangling pointer pointing to invalid memory. Using this pointer causes undefined behavior. This is a classic C/C++ error - never return pointers to local variables.
-
const int* ptr
-
const* int ptr
-
There is no such declaration like that
-
const int* const ptr
D
Correct answer
Explanation
The syntax const int* const ptr declares a pointer to a const int where both the pointer and the pointed-to value are const. The first const (before int) makes the value unchangeable through this pointer. The second const (after the *) makes the pointer itself unchangeable (it cannot point to a different address). Option A only protects the value, not the pointer.
-
vp=&f;
-
c=(char*)&i;
-
c=vp;
-
*i++;
-
f++;
C
Correct answer
Explanation
In C++, assigning a void* to a char* without an explicit cast is not allowed. While this is valid in C (where void* can be implicitly converted to any other pointer type), C++ requires an explicit cast: c = (char*)vp; or c = static_cast(vp);. The other assignments are valid - void* can receive any pointer, and casts between pointer types are allowed.
-
They tell the C++ compiler that they are functions compiled by a C compiler , So that they can be used in C++
-
they mean that the function are declared somewhere and defined somewhere
-
They improve performance
-
They are used with extern variables.
A
Correct answer
Explanation
The extern C linkage specification tells the C++ compiler that the enclosed functions were compiled by a C compiler and should use C linkage rules. This disables C++ name mangling, allowing C++ code to link with C functions. Without this, C++ would mangle the function names, and the linker couldn't find the C functions.
-
TRUE.
-
FALSE
-
Cant say.
-
Depends on the valuetype used.
B
Correct answer
Explanation
Value types in C# cannot normally represent null. However, the introduction of Nullable value types (e.g., int? or Nullable) allows them to hold null values. Because value types can be assigned null under these conditions, the statement is false.
-
int[,] testArray;
-
int[][] testArray;
-
int[2] testArray;
-
System.Array[2] testArray;
A
Correct answer
Explanation
In C#, a two-dimensional array is declared using the syntax 'type[,] arrayName' where the comma indicates the number of dimensions. 'int[,]' declares a 2D array, while 'int[][]' would be a jagged array (array of arrays).
-
A strongly typed function pointer.
-
A light weight thread or process that can call a single method.
-
A reference to an object in a different process.
-
An inter-process message channel.
A
Correct answer
Explanation
A delegate in .NET is a type-safe object-oriented function pointer. Delegates hold references to methods (static or instance) and can be used to pass methods as parameters, implement callback mechanisms, and define events. Unlike raw function pointers, delegates are type-safe and can reference multiple methods (multicast delegates).
-
The runtime checks to see that only one version of an assembly is on the machine at any one time.
-
.NET allows assemblies to specify the name AND the version of any assemblies they need to run.
-
The compiler offers compile time checking for backward compatibility.
-
It doesn't
B
Correct answer
Explanation
.NET prevents DLL Hell by allowing assemblies to specify both the name AND exact version of their dependencies in the manifest. This ensures that an application loads the specific versions of assemblies it was built and tested against, rather than whatever arbitrary version happens to be present. The runtime can then enforce versioning policy and redirect binding if configured.
-
Subscript Checking
-
Efficiently handling Array
-
No Such Option exists
-
Array bound Checking
D
Correct answer
Explanation
The SSRANGE compiler option in COBOL generates code to check whether subscripts, indexes, or reference modifiers exceed the declared boundaries of an array at runtime, ensuring array bound checking. If subscripts are out of bounds, a runtime error is raised, preventing memory corruption or access to invalid locations.
A
Correct answer
Explanation
In COBOL, array indexes (also called subscripts) are internal working-storage variables used to access table elements. These indexes are defined in the WORKING-STORAGE section and can be displayed using standard DISPLAY statements like other data items, but the question's wording suggests it refers to internal implementation details not directly visible.
-
For one tab
-
For all tabs of the Report
-
Depends how it is defined as global or Private
-
None of the above
B
Correct answer
Explanation
Variables defined in a report are accessible across all tabs within that report by default. This global scope allows for consistent calculations and references throughout the document. The option about 'global or Private' is misleading terminology in this context.
-
For one tab
-
For all tabs of the Report
-
Depends how it is defined as global or Private
-
None of the above
B
Correct answer
Explanation
Report-level variables have global scope within the report, making them accessible from all tabs. Tab-specific variables would be local to that tab only. Options A and C confuse variable scope with declaration type.
-
Infinite loop
-
Logical Error
-
Runtime Error
-
All the above
D
Correct answer
Explanation
A COBOL IF statement can experience logical errors (incorrect condition formulation), runtime errors (type mismatches or invalid comparisons), and can potentially contribute to infinite loops if condition evaluation never becomes false. These represent the major categories of programming errors that can manifest within conditional logic.
-
for loop
-
do while loop
-
nested loop
-
none of the above
B
Correct answer
Explanation
The COBOL PERFORM loop is equivalent to a do-while loop found in languages like Java and C++. Both structures execute the loop body at least once before testing the continuation condition, making them different from while loops which test the condition before the first iteration.