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
-
Encapuslation
-
Abstraction
-
Information Hiding
-
Polymorphism
B
Correct answer
Explanation
Abstraction focuses on exposing only essential features while hiding implementation details. It's about showing what an object does rather than how it does it. Encapsulation is about bundling data and methods together, while information hiding is a related concept about restricting access to internal details.
-
Virtual functions
-
Inline functions
-
Static functions
-
Friend functions
B
Correct answer
Explanation
Inline functions are expanded at compile time - the compiler replaces the function call with the actual function code, eliminating the overhead of function call mechanism. Virtual functions use dynamic binding, static functions have class scope, and friend functions are non-member functions with special access rights.
C
Correct answer
Explanation
A Null pointer is a pointer of any data type that does not point to any valid memory location and generally holds a value of zero. Vptr is a virtual table pointer, Void represents a pointer to an unspecified data type, and Zero is not a standard pointer type.
-
Automatic
-
Global
-
Static
-
External
A,C,D
Correct answer
Explanation
Storage classes in C are auto (default for local variables, stored on stack), static (retains value between calls, stored in data segment), extern (variables defined in another file), and register (stored in CPU registers). 'Global' is not a storage class - global variables use extern or static storage classes.
-
Static
-
Virtual
-
Void
-
Friend
D
Correct answer
Explanation
Friend functions are granted special access to private and protected members of a class. They're not member functions themselves but can access non-public data. This provides controlled way to expose private data to specific external functions without making it public.
-
Void
-
Int
-
Bool
-
none of the above
B
Correct answer
Explanation
In C++, if no return type is specified for a function, the default return type is 'int'. This is a legacy feature from C. However, it's considered poor practice - always explicitly specify the return type. The 'void' return type means the function returns nothing, while 'bool' is for boolean return values.
-
Reference types are stored on stack and value types are stored on heap area.
-
Boxing allows you to convert value types to reference types.
-
For boxing, during runtime it creates a temporary reference type box for the object on the heap
-
Unboxing allows you to convert reference type to value type
B,C,D
Correct answer
Explanation
In C#, boxing converts value types to reference types, and unboxing reverses this. During boxing, the runtime creates a temporary reference type object on the heap to hold the value type. Reference types are stored on the heap, not the stack (option A is wrong), and identifiers can contain numeric characters (option D is wrong).
-
In C#, we can define one and only one main( ) method .
-
If there is more than one main( ) method defined in your programme ,the compiler will return compile time error.
-
If there is more than one main( ) method defined you can explicitely tell the compiler which main( ) method is to be used as the entry point.
-
All the statements are wrong
B,C
Correct answer
Explanation
C# allows multiple Main() methods in different classes, but you must specify which one is the entry point using compiler options. The compiler returns an error if multiple Main() methods exist without an explicit entry point specification. Option A is wrong because you CAN define multiple Main() methods.
-
These are the names that one user gives to variables such as the user defined types(eg;classes and structs)
-
These are not case sensitive.
-
Their names must begin with a letter or with a underscore .
-
They must not contain any numeric characters
A,C
Correct answer
Explanation
C# identifiers are names for variables, classes, structs, etc. They must begin with a letter or underscore, are case-sensitive (option B is wrong), and can contain numeric characters after the first character (option D is wrong).
-
Infinite loop
-
Logical Error
-
Runtime Error
-
All of the above
-
For loop
-
Do-while loop
-
method
-
None of the above
B
Correct answer
Explanation
COBOL's PERFORM...UNTIL executes the loop body first, then checks the condition - similar to do-while in Java/C++ (condition checked at bottom, guaranteed at least one iteration). PERFORM...VARYING is more like a for loop.
-
Use a standard perform statement
-
Use an in line perform
-
Skillful use of the COBOL reserved word "AFTER"
-
This is not possible in COBOL
C
Correct answer
Explanation
The PERFORM statement with the AFTER clause in COBOL creates a loop that executes the body first, then checks the condition for subsequent iterations. This is equivalent to a do-while loop in other languages.
-
Exits the statement
-
Executes the function
-
Exits the Program
-
Executes the If statement again
B
Correct answer
Explanation
When an IF condition evaluates to true, the statements within the THEN branch (the code block associated with the true condition) are executed as part of normal program flow.
-
Gives control to the verb following the next period & gives control to the next verb after the explicit scope terminator.
-
Gives control to the next verb after the explicit scope terminator & gives control to the verb following the next period.
-
Both are same.
-
Control goes to the next paragraph & control goes to next section
A
Correct answer
Explanation
NEXT SENTENCE transfers control to the statement immediately after the next period (sentence terminator), while CONTINUE transfers control to the statement after the explicit scope terminator (like END-IF or END-PERFORM). They are not equivalent.
-
Bad coding. The loop will not be executed.
-
5 times.
-
10 times.
-
15 times.
B
Correct answer
Explanation
WS-N starts at 0, gets set to 5, then PERFORM B-PARA WS-N TIMES executes B-PARA exactly 5 times. The fact that B-PARA changes WS-N to 10 doesn't affect the loop count - PERFORM TIMES evaluates the count once at the start.