COMPUTER SCIENCE
Computer Science Mcqs with Answers
Practice Computer Science MCQs with answers covering programming, databases, networks, operating systems, algorithms, cybersecurity, web development and IT for FPSC, PPSC, SPSC, NTS, CSS and PMS exams.
47
Total MCQs
17
Topics
40
Past Papers
Q21
Divided logical memory into blocks with the same size as frames are called:
Explanation
In paging, logical memory is divided into fixed-size blocks called pages, while physical memory is divided into fixed-size blocks called frames. Pages and frames have the same size, allowing pages to be mapped to available frames.
Q22
Which memory allocation policy allocates the largest hole to the process?
Explanation
Worst-Fit is a memory allocation strategy that searches for and allocates the largest available free memory block, or hole, to a process. It is intended to leave relatively large remaining holes for future allocations.
Q23
When there is enough memory to fit a process in memory, but the space is not contiguous, we need:
Explanation
External Fragmentation occurs when enough total free memory is available to satisfy a process request, but the free space is scattered across separate non-contiguous blocks. Therefore, the process cannot be allocated despite sufficient total free memory.
Q24
A time-sharing system implies:
Explanation
A time-sharing system allows multiple users or programs to share CPU time. Multiple programs are kept in memory, and the CPU rapidly switches among them to provide interactive execution. It does not require multiple processors.
Q25
In C/C++ Programming, the strcmp() function is used to:
Explanation
The strcmp() function in C/C++ compares two null-terminated strings character by character. It returns 0 when the strings are equal, a negative value when the first string is smaller, and a positive value when the first string is larger.
Q26
In C/C++ Programming, "a" is used for:
Explanation
In C and C++, \a is an escape sequence that produces an alert or alarm character. On systems that support it, this may produce an audible beep or other alert.
Q27
Which of the following is the correct statement?
Explanation
In C/C++, an identifier such as a variable name must begin with a letter or underscore. It may contain letters, digits, and underscores afterward, but it cannot contain whitespace or be a reserved keyword.
Q28
While coding in C/C++, for "Call by Reference" we pass:
Explanation
In traditional C, call by reference is achieved by passing the address of a variable using a pointer. In C++, references can also be used to allow a function to operate directly on the original variable.
Q29
Which of the following is the symbol for the AND operator?
Explanation
The && operator is the logical AND operator in C and C++. It returns true when both conditions are true. The single & symbol is the bitwise AND operator.
Q30
Which of the following is not a type of variable?
Explanation
Extern and register are storage-related classifications in C/C++, while global describes a variable with global scope. Therefore, none of the listed choices is excluded as a variable type or classification.
Q31
Which of the following is the incorrect statement?
Explanation
An array is a collection of elements of the same data type. Its individual elements can be accessed using an index. Therefore, the statement that an array is simply a collection of variables is considered incorrect in this context.
Q32
To initialize an array of objects, only ______ will be called.
Explanation
When an array of objects is created without constructor arguments, the default constructor is invoked for each object. If constructor arguments are required, appropriate initialization must be provided.
Q33
What type of relationship exists between the Account class and the SavingAccount class?
Explanation
If SavingAccount is a specialized type of Account, then SavingAccount derives from the Account class. This represents an inheritance relationship, commonly expressed using public inheritance in C++.
Q34
A copy constructor is called when:
Explanation
A copy constructor is used to create and initialize a new object from an existing object of the same class. It is commonly invoked when an object is copied during initialization or passed by value.
Q35
In ______, a pointer or reference to an object is created inside a class.
Explanation
The question as written does not provide the standard relationship name for a class containing a pointer or reference to an object. Therefore, among the given choices, None of the given is the intended answer.
Q36
Select the correct line of code for the inheritance relationship between the Person class and the Supervisor class.
Explanation
In C++, the syntax class Supervisor : public Person declares Supervisor as a derived class of Person. This establishes a public inheritance relationship where Supervisor inherits accessible public and protected members of Person.
Q37
In ______, a pointer or reference to an object is created inside a class.
Explanation
Aggregation is a relationship in which one class contains a reference or pointer to an object of another class, while the contained object can exist independently of the containing object.
Q38
Select the correct line of code for the inheritance relationship between the Gender class and the Male class.
Explanation
The statement class Male : public Gender declares Male as a derived class of Gender. The colon followed by public specifies public inheritance in C++.
Q39
For the statement std3 = std1 - std2 to work correctly, the overloaded - operator must:
Explanation
When the binary - operator is overloaded as a member function, the left operand is the calling object and the right operand is passed as one argument. Therefore, the overloaded operator function takes a single explicit argument.
Q40
Select the correct line of code for the inheritance relationship between the Keys class and the SpecialKeys class.
Explanation
The statement class SpecialKeys : public Keys declares SpecialKeys as a derived class of Keys. It means SpecialKeys inherits the accessible public and protected members of Keys.
COMPUTER SCIENCE
Computer Science MCQs cover important concepts in programming, databases, computer networks, operating systems, data structures, algorithms, software engineering, cybersecurity, web technologies and information technology. This collection helps students and candidates revise essential computer concepts and prepare for FPSC, PPSC, SPSC, NTS, CSS, PMS and other competitive examinations.