Home MCQs COMPUTER SCIENCE
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.

Practice MCQs Solved Questions Exam Preparation
47 Total MCQs
17 Topics
40 Past Papers
Q21
Divided logical memory into blocks with the same size as frames are called:
A Pages
B Frames
C Page Table
D Segmentation
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?
A Best-Fit
B Worst-Fit
C First-Fit
D None of them
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:
A Internal Fragmentation
B Virtual Fragmentation
C External Fragmentation
D None of them
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:
A More than one processor in the system
B More than one memory in the system
C More than one program in memory
D None of above
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:
A Convert String to Char
B Copy two Strings
C Compare two Strings
D None of these
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:
A Form feed
B Line Break
C Select All
D Alarm
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?
A Variable name must start with an underscore or letter
B Variable name must have a digit
C Variable name must have a whitespace character
D Keyword cannot be a variable name
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:
A Address of variable
B Value of the variable
C Either value or address
D Both value and address
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?
A &
B &&
C ||
D $$
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?
A Extern
B Register
C Global
D None of the above
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?
A All array variables have the same type
B An array is a collection of variables
C Array variables can be used individually
D None of these
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.
A Default Constructor
B Overloaded Constructor
C Default Object
D None of the above
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?
A Inheritance
B Composition
C Aggregation
D Association
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:
A An object is created in terms of a pre-existing object
B An object is created
C An object is initialized
D None of the above
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.
A Aggregation
B Composition
C Separation
D None of the given
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.
A class Supervisor public Person
B class Person : public Supervisor
C class Supervisor : public Person
D class Person:: public Supervisor
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.
A Aggregation
B Composition
C Inheritance
D Association
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.
A class Male; public Gender
B class Gender : public Male
C class Male : public Gender
D class Gender:: public Male
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:
A Take two arguments
B Take a single argument
C Take three arguments
D None of the given choices
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.
A class SpecialKeys public Keys
B class Keys : public SpecialKeys
C class SpecialKeys : public Keys
D class Keys public SpecialKeys
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.