Computer fundamentals
1. Who is the father of Computers?
a) James Gosling
b) Charles Babbage
c) Dennis Ritchie
d) Bjarne Stroustrup
Answer: b
Explanation: Charles Babbage is known as the father of computers. Charles Babbage
designed and built the first mechanical computer and Difference Engine.
2. Which of the following is the correct abbreviation of COMPUTER?
a) Commonly Occupied Machines Used in Technical and Educational Research
b) Commonly Operated Machines Used in Technical and Environmental Research
c) Commonly Oriented Machines Used in Technical and Educational Research
d) Commonly Operated Machines Used in Technical and Educational Research
Answer: d
Explanation: The word COMPUTER is an abbreviation for the terms “Commonly Operated
Machines Used in Technical and Educational Research”. The word COMPUTER also
relates to the word COMPUTE which means to calculate. So initially, it was thought that a
computer is a device that is used to perform calculations.
3. Which of the following is the correct definition of Computer?
a) Computer is a machine or device that can be programmed to perform arithmetical or logic
operation sequences automatically
b) Computer understands only binary language which is written in the form of 0s & 1s
c) Computer is a programmable electronic device that stores, retrieves, and processes the
data
d) All of the mentioned
Answer: d
Explanation: A computer is a machine or device that can be programmed to perform
arithmetical or logic operation sequences automatically. The computer understands only
binary codes (0s & 1s).
4. What is the full form of CPU?
a) Computer Processing Unit
b) Computer Principle Unit
c) Central Processing Unit
d) Control Processing Unit
Answer: c
Explanation: CPU stands for Central Processing Unit. CPU is the part of a computer system
that is mainly referred as the brain of the computer.
5. Which of the following language does the computer understand?
a) Computer understands only C Language
b) Computer understands only Assembly Language
c) Computer understands only Binary Language
d) Computer understands only BASIC
Answer: c
Explanation: The Computer understands only binary language which is written in the form of
0s & 1s. A computer can understand assembly language but an assembler is required
which convert the assembly language to binary language. Similarly, for understanding high
level languages, compilers/interpreters are required.
6. Which of the following computer language is written in binary codes only?
a) pascal
b) machine language
c) C
d) C#
View Answer
Answer: b
Explanation: Machine Language is written in binary codes only. It can be easily understood
by the computer and is very difficult for us to understand. A machine language, unlike other
languages, requires no translators or interpreters.
7. Which of the following is the brain of the computer?
a) Central Processing Unit
b) Memory
c) Arithmetic and Logic unit
d) Control unit
View Answer
Answer: a
Explanation: The CPU is referred to as the brain of a computer.
It consists of a control unit and an arithmetic and logic unit. It is responsible for performing
all the processes and operations.
8. Which of the following is not a characteristic of a computer?
a) Versatility
b) Accuracy
c) Diligence
d) I.Q.
View Answer
Answer: d
Explanation: The Computer system has no I.Q. of its own. It does only what it is
programmed to do. It cannot take decisions of its own.
A computer is diligent because it can work continuously for hours without getting any errors
or without getting grumbled.
The accuracy of a computer is consistently high and its level of accuracy depends on its
design. A computer can perform any task if, it can be broken down into a series of logical
steps. Therefore, a computer is versatile.
9. Which of the following is the smallest unit of data in a computer?
a) Bit
b) KB
c) Nibble
d) Byte
View Answer
Answer: a
Explanation: A bit is defined as the smallest unit of data in a computer system. It is used as
a short form of Binary Digit. A bit can have only two values 0 or 1. A nibble comprises 4 bits,
a byte is a collection of 8 bits whereas KB (Kilobyte) is equal to 1024 bytes.
10. Which of the following unit is responsible for converting the data received from the user
into a computer understandable format?
a) Output Unit
b) Input Unit
c) Memory Unit
d) Arithmetic & Logic Unit
View Answer
Answer: b
Explanation: The Input Unit converts the data, which the user enters into a language that
the computer understands, i.e. it converts the data into binary format. The Output Unit is
responsible for giving the results in a user-understandable format. The Storage Unit is
responsible for storing the data after immediate results of processing whereas; the ALU is
responsible for various arithmetic and bitwise operations.
11. Which of the following monitor looks like a television and are normally used with non-
portable computer systems?
a) LED
b) LCD
c) CRT
d) Flat Panel Monitors
View Answer
Answer: c
Explanation: A CRT (or the Cathode Ray Tube) Monitor looks like a television ideally. The
flat-panel monitors are thinner and lighter in comparison.
12. Which of the following is not a type of computer code?
a) EDIC
b) ASCII
c) BCD
d) EBCDIC
View Answer
Answer: a
Explanation: There is no coding scheme like EDIC. EBCDIC stands for Extended Binary
Coded Decimal Interchange Code. BCD stands for Binary Coded Decimal. ASCII stands for
American Standard Code for information interchange.
13. Which of the following part of a processor contains the hardware necessary to perform
all the operations required by a computer?
a) Controller
b) Registers
c) Cache
d) Data path
View Answer
Answer: d
Explanation: A processor is a part of the computer which does all the data manipulation and
decision making. A processor comprises of:
A data path that contains the hardware necessary to perform all the operations. A controller
tells the data path what needs to be done.
The registers act as intermediate storage for the data.
14. Which of the following is designed to control the operations of a computer?
a) User
b) Application Software
c) System Software
d) Utility Software
View Answer
Answer: c
Explanation: Software is basically classified into two: System and application. System
Software is designed to control the operations and extend the processing capability of a
computer system.
15. Which of the following device use positional notation to represent a decimal number?
a) Pascaline
b) Abacus
c) Computer
d) Calculator
View Answer
Answer: b
Explanation: Abacus was used to do arithmetic calculations around 2500 years ago.
Pascaline was the pascal’s calculator by Blaise Pascal invented for doing laborious
calculations.
16. Which of the following is used in EBCDIC?
a) Super Computers
b) Mainframes
c) Machine Codes
d) Programming
View Answer
Answer: b
Explanation: This concept of EBCDIC was invented by IBM. It is mainly used in the IBM
mainframe environment. So basically, mainframes use EBCDIC codes.
17. Which of the following are physical devices of a computer?
a) Hardware
b) Software
c) System Software
d) Package
View Answer
Answer: a
Explanation: Hardware refers to the physical devices of a computer system. Software refers
to a collection of programs. A program is a sequence of instructions.
18. Which of the following defines the assigned ordering among the characters used by the
computer?
a) Accumulation
b) Sorting
c) Collating Sequence
d) Unicode
View Answer
Answer: c
Explanation: Collating sequence is the term used for ordering among characters. It may
vary depending upon the type of code used by a computer.
19. Which of the following storage is a system where a robotic arm will connect or
disconnect off-line mass storage media according to the computer operating system
demands?
a) Magnetic
b) Secondary
c) Virtual
d) Tertiary
View Answer
Answer: d
Explanation: Tertiary storage is the correct option. It is used in the realms of enterprise
storage and scientific computing on large computer systems and business computer
networks and is something a typical personal computer never sees firsthand.
20. Which of the following is known as the interval between the instant a computer makes a
request for the transfer of data from a disk system to the primary storage and the instance
the operation is completed?
a) Disk utilization time
b) Drive utilization time
c) Disk access time
d) Disk arrival time
View Answer
Answer: d
Explanation: The interval is referred to as the disk arrival time. It depends on several
parameters. Generally, a computer makes a request and the operation is served.
21. Which of the following devices provides the communication between a computer and
the outer world?
a) Compact
b) I/O
c) Drivers
d) Storage
View Answer
Answer: b
Explanation: The I/O i.e. the input/output devices provide a means of communication
between the computer and the outer world. They are often referred to as peripheral devices
sometimes.
22. Which of the following are the input devices that enable direct data entry into a
computer system from source documents?
a) System Access devices
b) Data acquiring devices
c) Data retrieving devices
d) Data Scanning devices
View Answer
Answer: d
Explanation: They are referred to as data scanning devices. They eliminate the need to key
in text data into the computer. It demands the high quality of input documents.
23. Which of the following is the device used for converting maps, pictures, and drawings
into digital form for storage in computers?
a) Image Scanner
b) Digitizer
c) MICR
d) Scanner
View Answer
Answer: b
Explanation: A digitizer serves the purpose given in the question. Digitizers are generally
used in the area of Computer-Aided Design by architects and engineers to design cars,
buildings, etc.
24. Which of the following can access the server?
a) Web Client
b) User
c) Web Browser
d) Web Server
View Answer
Answer: a
Explanation: Any computer that has access to the webserver is called the web client. A web
server is any computer that uses the HTTP protocol.
25. Which of the following is known as the language made up of binary-coded instructions?
a) High level
b) BASIC
c) C
d) Machine
View Answer
Answer: d
Explanation: The language made up of binary-coded instructions built into the hardware of a
particular computer and used directly by the computer is machine language.
26. Which of the following package allows individuals to use personal computers for storing
and retrieving their personal information?
a) Personal assistance package
b) Graphics package
c) Spreadsheet package
d) Animation package
View Answer
Answer: a
Explanation: It is a personal assistance package that allows for the same. It helps in
planning and managing their schedules, contacts, finances, and inventory of important
terms.
27. Which of the following is created when a user opens an account in the computer
system?
a) SFD
b) MFD
c) Subdirectory
d) RFD
View Answer
Answer: c
Explanation: A subdirectory is created when a user opens an account in the computer
system. It is treated as a file, though flagged in MFD as a subdirectory.
28. Which of the following is a technique that marked the beginning of computer
communications?
a) User Environment
b) Batch Environment
c) Time Sharing
d) Message passing
View Answer
Answer: c
Explanation: The answer is time-sharing. In time-sharing, Users were able to interact with
the computer and could share its information processing resources.
29. Which of the following is a type of technique in which dumb terminals are connected to a
central computer system?
a) Time Sharing
b) Message passing
c) Batch environment
d) User environment
View Answer
Answer: a
Explanation: This happens in time-sharing. In this, users were able to interact with the
computer and could share its information processing resources.
30. Which of the following service allows a user to log in to another computer somewhere
on the Internet?
a) e-mail
b) UseNet
c) Telnet
d) FTP
View Answer
Answer: c
Explanation: Telnet is the answer. It is a service that enables the user to log into another
computer somewhere on the Internet.
1. Which of the following is not a type of computer on the basis of operation?
a) Digital
b) Analog
c) Hybrid
d) Remote
View Answer
Answer: d
Explanation: There are three types of computers basically on the basis of operation:
Analog, Digital, and Hybrid.
32. Which of the following type of computer is mostly used for automatic operations?
a) analog
b) digital
c) hybrid
d) remote
View Answer
Answer: c
Explanation: Hybrid computer is mostly used with automatic operations of complicated
physical processes and machines.
33. Which of the following invention gave birth to the much cheaper microcomputers?
a) PDAs
b) Microprocessors
c) Microcomputers
d) Mainframes
View Answer
Answer: b
Explanation: The invention of the microprocessor (also called a single-chip CPU) gave birth
to much cheaper microcomputers.
34. Which of the following computers are lower than mainframe computers in terms of
speed and storage capacity?
a) Mainframes
b) Hybrid
c) Mini
d) Super
View Answer
Answer: c
Explanation: The answer is a. Mini computers are compared to mainframe computers in
terms of:
1. speed and, 2. storage capacity.
35. Which of the following is the first neural network computer?
a) AN
b) AM
c) RFD
d) SNARC
View Answer
Answer: d
Explanation: SNARC was the first neural network computer. it was built by Minsky and
Edmonds in 1956.
Cyber security
1. What is Cyber Security?
a) Cyber Security provides security against malware
b) Cyber Security provides security against cyber-terrorists
c) Cyber Security protects a system from cyber attacks
d) All of the mentioned
View Answer
Answer: d
Explanation: Cyber Security provides security to a system against cyber-attacks by using
various technologies, and processes.
2. What does cyber security protect?
a) Cyber security protects criminals
b) Cyber security protects internet-connected systems
c) Cyber security protects hackers
d) None of the mentioned
View Answer
Answer: b
Explanation: It protects internet-connected systems such as hardware, software, and data
from cyber-attacks. It aims to reduce cyber attacks against the system, network, and
technologies by reducing unauthorized exploitation, vulnerability, and threats.
3. Who is the father of computer security?
a) August Kerckhoffs
b) Bob Thomas
c) Robert
d) Charles
View Answer
Answer: a
Explanation: August Kerckhoffs, a linguist and German professor at HEC, wrote an essay in
the Journal of Military Science in February 1883. Kerckhoff had unwittingly established the
foundations for contemporary encryption, earning him the title of “Father of Computer
Security.”
4. Which of the following is defined as an attempt to steal, spy, damage or destroy computer
systems, networks, or their associated information?
a) Cyber attack
b) Computer security
c) Cryptography
d) Digital hacking
View Answer
Answer: a
Explanation: An effort to steal, spy on, damage, or destroy diverse components of
cyberspace, such as computer systems, related peripherals, network systems, and
information, is known as a cyber attack.
5. Which of the following is a type of cyber security?
a) Cloud Security
b) Network Security
c) Application Security
d) All of the above
View Answer
Answer:d
Explanation: Since technology is improving, the threat and attacks against the technology
are also increasing. Hence, to provide security, it is divided into the following types:
Cloud Security: Provides security for the data stored on the cloud.
Network Security: Protects the internal network from threats.
Application Security: Protects data stored in the application software
6. What are the features of cyber security?
a) Compliance
b) Defense against internal threats
c) Threat Prevention
d) All of the above
View Answer
Answer: d
Explanation: The features are as follows:
Compliance: Creating a program that meets the requirements and rules of the users.
Defense against internal threats: Should provide security against internal exploitation.
Threat Prevention: Should be capable of detecting the threat and preventing them.
7. Which of the following is an objective of network security?
a) Confidentiality
b) Integrity
c) Availability
d) All of the above
View Answer
Answer: d
Explanation: The objectives of network security are Confidentiality, Integrity, and
Availability.
Confidentiality: The function of confidentiality is to keep sensitive company information safe
from unwanted access. The confidentiality component of network security ensures that data
is only accessible to those who are authorized to see it.
Integrity: This goal entails ensuring and preserving data accuracy and consistency. The
purpose of integrity is to ensure that data is accurate and not tampered with by
unauthorized individuals.
Availability: The purpose of availability in Network Security is to ensure that data, network
resources, and services are always available to legitimate users, whenever they need them.
8. Which of the following is not a cybercrime?
a) Denial of Service
b) Man in the Middle
c) Malware
d) AES
View Answer
Answer: d
Explanation: Denial of Service, Man in the Middle, and Malware exploit the system causing
a threat to security, hence they are considered as cybercrime. AES (Advanced Encryption
Standard) provides security by encrypting the data.
9. Which of the following is a component of cyber security?
a) Internet Of Things
b) AI
c) Database
d) Attacks
View Answer
Answer: a
Explanation-: The Internet of Things (IoT) is a network of physical objects embedded with
sensors, software, and other technologies to connect and exchange data with other devices
and systems through the internet.
10. Which of the following is a type of cyber attack?
a) Phishing
b) SQL Injections
c) Password Attack
d) All of the above
View Answer
Answer: d
Explanation: Attacks are Phishing, SQL Injections, and Password Attack.
Phishing: The attacker sends a large number of fraudulent emails and gains access to the
system.
SQL Injections: The attacker gains access to the protected information by adding malicious
code to the SQL server.
Password Attack: Attackers gain access to the passwords unethically and gain access to
the confidential data.
11. Which of the following is not an advantage of cyber security?
a) Makes the system slower
b) Minimizes computer freezing and crashes
c) Gives privacy to users
d) Protects system against viruses
View Answer
Answer: a
Explanation: The advantages are minimization of computer freezing and crashes, user
privacy, and protection against viruses, worms, etc. Disadvantages include the system
becoming slow, configuring firewalls correctly can be difficult, need to update the new
software in order to keep security up to date.
12. “Cyberspace” was coined by _________
a) Richard Stallman
b) William Gibson
c) Andrew Tannenbaum
d) Scott Fahlman
View Answer
Answer: b
Explanation: William Gibson, an American-Canadian fiction pioneer, and coiner, examined
the many streams of technology and invented the word “cyberspace” in 1821. The phrase
refers to linked technologies that aid in information exchange, interaction with digital
devices, storage and digital entertainment, computer and network security, and other
information technology-related matters.
13. In which year has hacking become a practical crime and a matter of concern in the field
of cyber technology?
a) 1991
b) 1983
c) 1970
d) 1964
View Answer
Answer: c
Explanation: In the case of hackers in the 1970s, hackers and cyber thieves found out how
wired technologies operate and how they might be abused to obtain a competitive edge or
misuse the technology.
14. Governments hired some highly skilled hackers for providing cyber security for the
country or state. These types of hackers are termed as _______
a) Nation / State sponsored hackers
b) CIA triad
c) Special Hackers
d) Government Hackers
View Answer
Answer: a
Explanation: Nation / State-sponsored hackers are those who are engaged or paid by a
nation’s or state’s government to safeguard the country from cyber terrorists and other
groups or individuals, as well as to expose their plans, communications, and activities.
15. Which of the following act violates cyber security?
a) Exploit
b) Attack
c) Threat
d) Vulnerability
View Answer
Answer: b
Explanation: A threat is a possible danger that might lead to a security breach and cause
harm to the system or network. Vulnerability is a word that refers to a flaw in a network or
system that might be exploited by an attacker. Exploiting a security flaw might result in
unexpected and unwanted effects. A cyber-attack is an attempt by attackers to alter, delete,
steal or expose any specific data by gaining unauthorized access.
16. Which of the following actions compromise cyber security?
a) Vulnerability
b) Attack
c) Threat
d) Exploit
View Answer
Answer: c
Explanation: A threat is defined as a potential hazard that might result in a breach of
security and cause harm to the system or network. Vulnerability is a term that refers to a
weakness in a network or system that an attacker may exploit. Exploiting a weakness in
security might have unintended and undesirable consequences.
17. Which of the following is the hacking approach where cyber-criminals design fake
websites or pages for tricking or gaining additional traffic?
a) Pharming
b) Website-Duplication
c) Mimicking
d) Spamming
View Answer
Answer: a
Explanation: Pharming is a strategy and approach used by cybercriminals to create phony
web pages and sites in order to mislead users into giving over personal information such as
login IDs and passwords.
18. Which of the following is not a type of peer-to-peer cyber-crime?
a) MiTM
b) Injecting Trojans to a target victim
c) Credit card details leak in the deep web
d) Phishing
View Answer
Answer: c
Explanation: Peer-to-peer includes phishing, as well as the distribution of Trojans and
worms to individuals. The leakage of a huge number of people’s credit card data on the
deep web, on the other hand, is classified as a computer-as-weapon cyber-crime.
19. A cyber-criminal or penetration tester uses the additional data that stores certain special
instructions in the memory for activities to break the system in which of the following attack?
a) Clickjacking
b) Buffer-overflow
c) Phishing
d) MiTM
View Answer
Answer: b
Explanation: The excess data that contains certain specific instructions in the memory for
actions are projected by a cyber-criminal or penetration tester to break the system in a
buffer-overflow attack.
20. Which of the following do Cyber attackers commonly target for fetching IP address of a
target or victim user?
a) ip tracker
b) emails
c) websites
d) web pages
View Answer
Answer: c
Explanation: Enumeration by cyber-attackers is also feasible via websites since attackers
target websites in order to obtain the victim’s or target user’s IP address.
21. Which of the following is defined as an attempt to harm, damage or cause threat to a
system or network?
a) Digital crime
b) Threats
c) System hijacking
d) Cyber Attack
View Answer
Answer: d
Explanation: Extortion, identity theft, email hacking, digital surveillance, stealing hardware,
mobile hacking, and physical security breaches are all examples of cyber assaults or
activities.
22. They are nefarious hackers, and their main motive is to gain financial profit by doing
cyber crimes. Who are “they” referred to here?
a) White Hat Hackers
b) Black Hat Hackers
c) Hactivists
d) Gray Hat Hackers
View Answer
Answer: b
Explanation: Black Hat hackers, often known as “crackers,” are a sort of cyber crime that
gain illegal access to a user’s account or system in order to steal confidential data or
introduce malware into the system for personal gain or to harm the company.
23. IT security in any firm or organization is maintained and handled by
____________________
a) Software Security Specialist
b) CEO of the organization
c) Security Auditor
d) IT Security Engineer
View Answer
Answer: d
Explanation: This is a position in a company or organisation where an individual develops
and maintains different systems and security tools for the company or organisation to which
he or she belongs.
24. Where did the term “hacker” originate?
a) MIT
b) New York University
c) Harvard University
d) Bell’s Lab
View Answer
Answer: a
Explanation: The term “hacker” was coined at MIT (Massachusetts Institute of Technology)
because individuals and highly competent professionals use computer languages to
address various challenges. In this context, labels such as geeks and nerds have been
coined.
25. What is the existence of weakness in a system or network is known as?
a) Attack
b) Exploit
c) Vulnerability
d) Threat
View Answer
Answer: c
Explanation: Vulnerability is a term that refers to a weakness in a network or system that an
attacker may exploit. Exploiting a weakness in security might have unintended and
undesirable consequences.
26. Which of the following is an internet scam done by cyber-criminals where the user is
convinced digitally to provide confidential information.
a) MiTM attack
b) Phishing attack
c) Website attack
d) DoS attack
View Answer
Answer: b
Explanation: Phishing is a type of cybercrime in which a person is digitally persuaded to
disclose private information. Phishing comes in a variety of forms. Some of them employ
malware and emails to divert users to various websites.
27. Which of the following is not a step followed by cyber-criminals in data breaching?
a) Exfiltration
b) Research and info-gathering
c) Attack the system
d) Fixing the bugs
View Answer
Answer: d
Explanation: During a hack, cyber-criminals first do research on the target, gathering data
about the victim’s system and network. Then go ahead and attack. Once the attacker has
gained access, he or she takes sensitive information.
28. Which of the following online service’s privacy cannot be protected using Tor?
a) Browsing data
b) Instant messaging
c) Login using ID
d) Relay chats
View Answer
Answer: c
Explanation: Login using ID will obviously take your ID in order to access your account and
is not the headache of Tor. Privacy regarding instant messaging, browsing data, relay chats
are some of the following online services protected by Tor.
29. Which of the following term refers to a group of hackers who are both white and black
hat?
a) Yellow Hat hackers
b) Grey Hat hackers
c) Red Hat Hackers
d) White-Black Hat Hackers
View Answer
Answer: b
Explanation: Grey Hat Hackers are a hybrid of ethical and unethical hacker personalities.
They hack other people’s computers for fun, but they don’t hurt them, and they exploit
network faults and vulnerabilities without the admin or owner’s awareness.
30. Which of the following is not an email-related hacking tool?
a) Mail Password
b) Email Finder Pro
c) Mail PassView
d) Sendinc
View Answer
Answer: d
Explanation: Sendinc is not a tool that compromises email data. It is used to protect
business email accounts and provides a fast web-based solution for businesses to start
delivering secure emails. The other three are email hacking tools.
30. Which of the following DDoS in mobile systems wait for the owner to trigger the cyber
attack?
a) botnets
b) programs
c) virus
d) worms
View Answer
Answer: a
Explanation: Botnets on infected mobile devices are waiting for orders from their owners. It
starts a DDoS flood attack after receiving the owner’s instructions. As a result, calls are not
connected or data is not sent.
31. Which of the following is the least strong security encryption standard?
a) WPA3
b) WPA2
c) WPA
d) WEP
View Answer
Answer: d
Explanation: Wireless security is an important aspect of cyber-security. Wired Equivalent
Privacy (WEP), Wi-Fi Protected Access (WPA), WPA2, and WPA3 are the most common
kinds of wireless security. WEP is a famously insecure encryption protocol.
32. Which of the following is a Stuxnet?
a) Trojan
b) Antivirus
c) Worm
d) Virus
View Answer
Answer: c
Explanation: Stuxnet is a popular and powerful worm that came into existence in mid 2010,
which was very powerful as it was accountable for the cause of huge damage to Iran’s
Nuclear program. It mainly targets the PLCs (Programmable Logic Controllers) in a system.
33. Which of the following ethical hacking technique is used for determining which operating
system (OS) is running on a remote computer?
a) Operating System fingerprinting
b) Operating System penetration testing
c) Digital-printing
d) Machine printing
View Answer
Answer: a
Explanation: OS fingerprinting is an ethical hacking technique used for determining what
operating system (OS) is running on a remote computer. OS Fingerprinting is the practice of
examining data packets that come from a network in order to extract intelligence that may
be utilized in future assaults.
34. Which of the following can diminish the chance of data leakage?
a) Steganography
b) Chorography
c) Cryptography
d) Authentication
View Answer
Answer: a
Explanation: Ordinary files are targeted by hackers or other cyber criminals in order to
disguise distinct data or information within another data file. You can reduce the risk of data
leaking by employing steganography.
Web Technology
1. What is web technology?
a) A collection of tools and techniques used to create and deliver content on the World Wide
Web
b) A type of software that enables users to access and interact with information on the
internet
c) A network of interconnected computers that share information and services
d) A system for storing and retrieving information on the internet
View Answer
Answer: a
Explanation: Web technology is a term that encompasses the tools, techniques, and
standards used to create and deliver content on the World Wide Web. This includes markup
languages like HTML and CSS, scripting languages like JavaScript, client-side technologies
like HTML5 and CSS3, server-side technologies like PHP and Java, databases, networking
protocols, and more.
2. Which HTML tag is used to create a hyperlink?
a) <link>
b) <href>
c) <a>
d) <hyperlink>
View Answer
Answer: c
Explanation: The HTML tag <a> is used to create a hyperlink, which is a link to another web
page or resource. The <a> tag has two main attributes: href and target. The href attribute
specifies the URL of the linked resource, while the target attribute specifies whether the link
should open in a new browser window or tab.
3. Which of the following is not a web component element?
a) <shadow>
b) <menu>
c) <content>
d) <element>
View Answer
Answer: b
Explanation: There are web components in HTML related technology which makes it
possible to essentially create and use custom elements as if it were regular HTML. You can
also create custom versions of standard HTML elements. Some of the elements are
<shadow>, <content>, <element>, <template>, <slot>.
C++
.
1. Who invented C++?
a) Dennis Ritchie
b) Ken Thompson
c) Brian Kernighan
d) Bjarne Stroustrup
View Answer
Answer: d
Explanation: Bjarne Stroustrup is the original creator of C++ in 1979 at AT&T Bell Labs.
2. What is C++?
a) C++ is an object oriented programming language
b) C++ is a procedural programming language
c) C++ supports both procedural and object oriented programming language
d) C++ is a functional programming language
View Answer
Answer: c
Explanation: C++ supports both procedural(step by step instruction) and object oriented
programming (using the concept of classes and objects).
3. Which of the following is the correct syntax of including a user defined header files in
C++?
a) #include [userdefined]
b) #include “userdefined”
c) #include <userdefined.h>
d) #include <userdefined>
View Answer
Answer: b
Explanation: C++ uses double quotes to include a user-defined header file. The correct
syntax of including user-defined is #include “userdefinedname”.
4. Which of the following is used for comments in C++?
a) /* comment */
b) // comment */
c) // comment
d) both // comment or /* comment */
View Answer
Answer: d
Explanation: Both the ways are used for commenting in C++ programming. // is used for
single line comments and /* … */ is used for multiple line comments.
5. Which of the following extension is used for user-defined header file in c++?
a) hg
b) cpp
c) h
d) hf
View Answer
Answer: c
Explanation: .h extensions are used for user defined header files. To include a user defined
header file, one should use #include”name.h” i.e. it should be enclosed within double
quotes.
6. Which of the following is a correct identifier in C++?
a) VAR_1234
b) $var_name
c) 7VARNAME
d) 7var_name
View Answer
Answer: a
Explanation: The rules for writing an identifier is as follows:
i) may contain lowercase/uppercase letters, digits or underscore(_) only
ii) should start with a non-digit character
iii) should not contain any special characters like @, $, etc.
7. Which of the following is not a type of Constructor in C++?
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Friend constructor
View Answer
Answer: d
Explanation: Friend function is not a constructor whereas others are a type of constructor
used for object initialization.
8. Which of the following approach is used by C++?
a) Left-right
b) Right-left
c) Bottom-up
d) Top-down
View Answer
Answer: c
Explanation: C++ is an object-oriented language and OOL uses a bottom-up approach to
solve/view a problem.
9. What is virtual inheritance in C++?
a) C++ technique to enhance multiple inheritance
b) C++ technique to ensure that a private member of the base class can be accessed
somehow
c) C++ technique to avoid multiple inheritances of classes
d) C++ technique to avoid multiple copies of the base class into children/derived class
View Answer
Answer: d
Explanation: Virtual inheritance is a C++ technique with which it ensures that a derived
class contains only one copy of the base class’s variables. Refer Wikipedia for more info.
10. What happens if the following C++ statement is compiled and executed?
int *ptr = NULL;
delete ptr;
a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time
View Answer
Answer: b
Explanation: The above statement is syntactically and semantically correct as C++ allows
the programmer to delete a NULL pointer, therefore, the program is compiled and executed
successfully.
11. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
View Answer
Answer: c
Explanation: There is no operation defined for the addition of character array in C++ hence
the compiler throws an error as it does not understood what to do about this expression.
12. What is the difference between delete and delete[] in C++?
a) delete is syntactically correct but delete[] is wrong and hence will give an error if used in
any case
b) delete is used to delete normal objects whereas delete[] is used to pointer objects
c) delete is a keyword whereas delete[] is an identifier
d) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of)
objects
View Answer
Answer: d
Explanation: delete is used to delete a single object initiated using new keyword whereas
delete[] is used to delete a group of objects initiated with the new operator.
13. What happens if the following program is executed in C and C++?
#include <stdio.h>
int main(void)
{
int new = 5;
printf("%d", new);
}
a) Error in C and successful execution in C++
b) Error in both C and C++
c) Error in C++ and successful execution in C
d) A successful run in both C and C++
View Answer
Answer: c
Explanation: new is a keyword in C++, therefore, we cannot declare a variable with name
new but as there is no such keyword new in C, therefore, the program is compiled and
executed successfully in C.
14. What happens if the following program is executed in C and C++?
#include <stdio.h>
void func(void)
{
printf("Hello");
}
void main()
{
func();
func(2);
}
a) Outputs Hello twice in both C and C++
b) Error in C and successful execution in C++
c) Error in C++ and successful execution in C
d) Error in both C and C++
View Answer
Answer: d
Explanation: As the func(void) needs no argument during its call, hence when we are calling
func(2) with 2 as passed as a parameter then this statement gives the error in both C++ and
C compiler.
15. Which of the following is correct about this pointer in C++?
a) this pointer is passed as a hidden argument in all static variables of a class
b) this pointer is passed as a hidden argument in all the functions of a class
c) this pointer is passed as a hidden argument in all non-static functions of a class
d) this pointer is passed as a hidden argument in all static functions of a class
View Answer
Answer: c
Explanation: As static functions are a type of global function for a class so all the object
shares the common instance of that static function whereas all the objects have there own
instance for non-static functions and hence they are passed as a hidden argument in all the
non-static members but not in static members.
16. What will be the output of the following C++ code?
1. #include <iostream>
2. #include <string>
3. #include <algorithm>
4. using namespace std;
5. int main()
6. {
7. string s = "spaces in text";
8. [Link](remove([Link](), [Link](), ' ' ), [Link]() ) ;
9. cout << s << endl;
10. }
a) spacesintext
b) spaces in text
c) spaces
d) spaces in
View Answer
Answer: a
Explanation: In this program, We formed a algorithm to remove spaces in the string.
Output:
$ g++ [Link]
$ [Link]
spacesintext
17. Which of the following C++ code will give error on compilation?
================code 1=================
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
cout<<"Hello World";
return 0;
}
========================================
================code 2=================
#include <iostream>
int main(int argc, char const *argv[])
{
std::cout<<"Hello World";
return 0;
}
========================================
a) Code 1 only
b) Neither code 1 nor code 2
c) Both code 1 and code 2
d) Code 2 only
View Answer
Answer: b
Explanation: Neither code 1 nor code 2 will give an error as both are syntactically correct as
in first code we have included namespace std and in second one we have used scope
resolution operator to resolve the conflict.
18. Which of the following type is provided by C++ but not C?
a) double
b) float
c) int
d) bool
View Answer
Answer: d
Explanation: C++ provides the boolean type to handle true and false values whereas no
such type is provided in C.
19. What is the value of p in the following C++ code snippet?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int p;
6. bool a = true;
7. bool b = false;
8. int x = 10;
9. int y = 5;
10. p = ((x | y) + (a + b));
11. cout << p;
12. return 0;
13. }
a) 12
b) 0
c) 2
d) 16
View Answer
Answer: d
Explanation: | means bitwise OR operation so x | y (0101 | 1010) will be evaluated to 1111
which is integer 15 and as a is true and b is false so a+b(1 + 0) = 1. So final value of
expression in line #10 will be 15 + 1 = 16.
20. By default, all the files in C++ are opened in _________ mode.
a) Binary
b) VTC
c) Text
d) ISCII
View Answer
Answer: c
Explanation: By default, all the files in C++ are opened in text mode. They read the file as
normal text.
21. What will be the output of the following C++ function?
1. int main()
2. {
3. register int i = 1;
4. int *ptr = &i;
5. cout << *ptr;
6. return 0;
7. }
a) Runtime error may be possible
b) Compiler error may be possible
c) 1
d) 0
View Answer
Answer: b
Explanation: Using & on a register variable may be invalid, since the compiler may store the
variable in a register, and finding the address of it is illegal.
22. Which of the following correctly declares an array in C++?
a) array{10};
b) array array[10];
c) int array;
d) int array[10];
View Answer
Answer: d
Explanation: Because array variable and values need to be declared after the datatype only.
23. What is the size of wchar_t in C++?
a) Based on the number of bits in the system
b) 2 or 4
c) 4
d) 2
View Answer
Answer: a
Explanation: Compiler wants to make CPU as more efficient in accessing the next value.
24. What will be the output of the following C++ code?
#include<iostream>
using namespace std;
int main ()
{
int cin;
cin >> cin;
cout << "cin: " << cin;
return 0;
}
a) Segmentation fault
b) Nothing is printed
c) Error
d) cin: garbage value
View Answer
Answer: d
Explanation: cin is a variable hence overrides the cin object. cin >> cin has no meaning so
no error.
25. What is the use of the indentation in c++?
a) r distinguishes between comments and inner data
b) distinguishes between comments and outer data
c) distinguishes between comments and code
d) r distinguishes between comments and outer data
View Answer
Answer: c
Explanation: To distinguish between different parts of the program like comments, codes,
etc.
26. Which is more effective while calling the C++ functions?
a) call by object
b) call by pointer
c) call by value
d) call by reference
View Answer
Answer: d
Explanation: In the call by reference, it will just passes the reference of the memory
addresses of passed values rather than copying the value to new memories which reduces
the overall time and memory use.
27. What will be the output of the following C++ program?
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char const *argv[])
{
const char *a = "Hello\0World";
cout<<a;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
View Answer
Answer: a
Explanation: char* are terminated by a ‘\0’ character so the string “Hello\0World” will be cut
down to “Hello”.
28. Which of the following is used to terminate the function declaration in C++?
a) ;
b) ]
c) )
d) :
View Answer
29. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. char c = 74;
6. cout << c;
7. return 0;
8. }
a) I
b) J
c) A
d) N
View Answer
Answer: b
Explanation: The literal value for 74 is J. So it will be printing J.
30. What will be the output of the following C++ program?
1. #include <iomanip>
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6. cout << setprecision(17);
7. double d = 0.1;
8. cout << d << endl;
9. return 0;
10. }
a) compile time error
b) 0.100001
c) 0.11
d) 0.10000000000000001
View Answer
Answer: d
Explanation: The double had to truncate the approximation due to its limited memory, which
resulted in a number that is not exactly 0.1.
Output:
Python MCQ (Multiple Choice Questions)
1. Who developed Python Programming Language?
a) Wick van Rossum
b) Rasmus Lerdorf
c) Guido van Rossum
d) Niene Stom
View Answer
Answer: c
Explanation: Python language is designed by a Dutch programmer Guido van Rossum in
the Netherlands.
2. Which type of Programming does Python support?
a) object-oriented programming
b) structured programming
c) functional programming
d) all of the mentioned
View Answer
Answer: d
Explanation: Python is an interpreted programming language, which supports object-
oriented, structured, and functional programming.
3. Is Python case sensitive when dealing with identifiers?
a) no
b) yes
c) machine dependent
d) none of the mentioned
View Answer
Answer: b
Explanation: Case is always significant while dealing with identifiers in python.
4. Which of the following is the correct extension of the Python file?
a) .python
b) .pl
c) .py
d) .p
View Answer
Answer: c
Explanation: ‘.py’ is the correct extension of the Python file. Python programs can be written
in any text editor. To save these programs we need to save in files with file extension ‘.py’.
5. Is Python code compiled or interpreted?
a) Python code is both compiled and interpreted
b) Python code is neither compiled nor interpreted
c) Python code is only compiled
d) Python code is only interpreted
View Answer
Answer: a
Explanation: Many languages have been implemented using both compilers and
interpreters, including C, Pascal, and Python.
6. All keywords in Python are in _________
a) Capitalized
b) lower case
c) UPPER CASE
d) None of the mentioned
View Answer
Answer: d
Explanation: Most keywords are in lowercase, but some like True, False, and None are
capitalized.
7. What will be the value of the following Python expression?
print(4 + 3 % 5)
a) 7
b) 2
c) 4
d) 1
View Answer
Answer: a
Explanation: In Python, the modulus operator % has higher precedence than addition +. So,
the expression is evaluated as 4 + (3 % 5), which is 4 + 3 = 7.
8. Which of the following is used to define a block of code in Python language?
a) Indentation
b) Key
c) Brackets
d) All of the mentioned
View Answer
Answer: a
Explanation: In Python, to define a block of code we use indentation. Indentation refers to
whitespaces at the beginning of the line.
9. Which keyword is used for function in Python language?
a) Function
b) def
c) Fun
d) Define
View Answer
Answer: b
Explanation: The def keyword is used to create, (or define) a function in python.
10. Which of the following character is used to give single-line comments in Python?
a) //
b) #
c) !
d) /*
View Answer
Answer: b
Explanation: To write single-line comments in Python use the Hash character (#) at the
beginning of the line. It is also called number sign or pound sign. To write multi-line
comments, close the text between triple quotes.
Example: “”” comment
text “””
11. What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i)
i + = 1
a) 1 2 3
b) SyntaxError
c) 1 2
d) none of the mentioned
View Answer
Answer: b
Explanation: The output will be a SyntaxError because i + = 1 is invalid syntax in Python.
There should be no space between + and =. The correct syntax is i += 1.
12. Which of the following functions can help us to find the version of python that we are
currently working on?
a) [Link](1)
b) [Link](0)
c) [Link]()
d) [Link]
View Answer
Answer: d
Explanation: The function [Link] can help us to find the version of python that we are
currently working on. It also contains information on the build number and compiler used.
For example, 3.5.2, 2.7.3 etc. this function also returns the current date, time, bits etc along
with the version.
13. Python supports the creation of anonymous functions at runtime, using a construct
called __________
a) pi
b) anonymous
c) lambda
d) none of the mentioned
View Answer
Answer: c
Explanation: In Python, lambda functions are anonymous, meaning they don’t have a name.
They are defined using the lambda keyword and can take any number of arguments but
only have one expression. Lambdas are useful for creating small, throwaway functions
quickly without formally defining them using def.
14. What is the order of precedence in python?
a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
c) Parentheses, Exponential, Multiplication, Addition, Division, Subtraction
d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
View Answer
Answer: d
Explanation: Python follows the PEMDAS rule (similar to BODMAS): Parentheses,
Exponentiation, Multiplication/Division, then Addition/Subtraction. Operators at the same
level are evaluated left to right.
15. What will be the output of the following Python code snippet if x=1?
x<<2
a) 4
b) 2
c) 1
d) 8
View Answer
Answer: a
Explanation: The binary form of 1 is 0001. The expression x<<2 implies we are performing
bitwise left shift on x. This shift yields the value: 0100, which is the binary form of the
number 4.
16. What does pip stand for python?
a) Pip Installs Python
b) Pip Installs Packages
c) Preferred Installer Program
d) All of the mentioned
View Answer
Answer: c
Explanation: pip is a package manager for python. Which is also called Preferred Installer
Program.
17. Which of the following is true for variable names in Python?
a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned
View Answer
Answer: b
Explanation: Python allows variable names of unlimited length. Private members usually
have only a leading underscore, not both leading and trailing. The ampersand (&) is not
permitted in variable names; only the underscore (_) is allowed as a special character.
18. What are the values of the following Python expressions?
print(2**(3**2))
print((2**3)**2)
print(2**3**2)
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
View Answer
Answer: a
Explanation: Expression 1 is evaluated as: 2**9, which is equal to 512. Expression 2 is
evaluated as 8**2, which is equal to 64. The last expression is evaluated as 2**(3**2). This
is because the associativity of ** operator is from right to left. Hence the result of the third
expression is 512.
19. Which of the following is the truncation division operator in Python?
a) |
b) //
c) /
d) %
View Answer
Answer: b
Explanation: // is the operator for truncation division. It is called so because it returns only
the integer part of the quotient, truncating the decimal part. For example: 20//3 = 6.
20. What will be the output of the following Python code?
l=[1, 0, 2, 0, 'hello', '', []]
print(list(filter(bool, l)))
a) [1, 0, 2, ‘hello’, ”, []]
b) Error
c) [1, 2, ‘hello’]
d) [1, 0, 2, 0, ‘hello’, ”, []]
View Answer
Answer: c
Explanation: The function filter(bool, l) removes all false elements from the list l, such as
0, ”, and []. The remaining true elements — 1, 2, and ‘hello’ — are returned as a new list.
21. Which of the following functions is a built-in function in python?
a) factorial()
b) print()
c) seed()
d) sqrt()
View Answer
Answer: b
Explanation: The function seed is a function which is present in the random module. The
functions sqrt and factorial are a part of the math module. The print function is a built-in
function which prints a value directly to the system output.
22. Which of the following is the use of id() function in python?
a) Every object doesn’t have a unique id
b) Id returns the identity of the object
c) All of the mentioned
d) None of the mentioned
View Answer
Answer: b
Explanation: The id() function in Python returns the identity of an object. This identity is a
unique integer (or memory address) that remains constant for the object during its lifetime.
Every object in Python has a unique id, which helps in comparing object references.
23. The following python program can work with ____ parameters.
def f(x):
def f1(*args, **kwargs):
print("Sanfoundry")
return x(*args, **kwargs)
return f1
a) any number of
b) 0
c) 1
d) 2
View Answer
Answer: a
Explanation: The decorator function f defines f1 which uses *args and **kwargs to accept
any number of positional and keyword arguments. This allows the decorated function to
work with any number of parameters, making the decorator flexible.
24. What will be the output of the following Python function?
print(min(max(False,-3,-4), 2,7))
a) -4
b) -3
c) 2
d) False
View Answer
Answer: d
Explanation: The max(False, -3, -4) evaluates to 0 because False is treated as 0, and 0 is
greater than -3 and -4. Then, min(0, 2, 7) returns 0. Since 0 is equivalent to False, the
output is False.
25. Which of the following is not a core data type in Python programming?
a) Tuples
b) Lists
c) Class
d) Dictionary
View Answer
26. What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
a) 56.236
b) 56.23
c) 56.0000
d) 56.24
View Answer
27. Which of these is the definition for packages in Python?
a) A set of main modules
b) A folder of python modules
c) A number of files containing Python definitions and statements
d) A set of programs making use of Python modules
View Answer
28. What will be the output of the following Python function?
print(len(["hello",2, 4, 6]))
a) Error
b) 6
c) 4
d) 3
View Answer
Answer: c
Explanation: The len() function returns the number of elements in the list, regardless of their
types. In this case, the list [“hello”, 2, 4, 6] contains four elements, so len() returns 4.
29. What will be the output of the following Python code?
x = 'abcd'
for i in x:
print([Link]())
a)
B
C
b) a b c d
c) error
d)
View Answer
Answer: d
Explanation: In this code, x = ‘abcd’ is iterated over, and for each character i, [Link]() is
called. The upper() method returns a new string where all characters are converted to
uppercase. Each uppercase character is then printed on a new line. Therefore, the output is
A, B, C, D, one per line.
30. What is the order of namespaces in which Python looks for an identifier?
a) Python first searches the built-in namespace, then the global namespace and finally the
local namespace
b) Python first searches the built-in namespace, then the local namespace and finally the
global namespace
c) Python first searches the local namespace, then the global namespace and finally the
built-in namespace
d) Python first searches the global namespace, then the local namespace and finally the
built-in namespace
View Answer
Answer: c
Explanation: When Python encounters an identifier (like a variable or function name), it
follows the LEGB rule to resolve it. It first looks in the Local namespace (inside the current
function), then in the Enclosing namespace (if it’s a nested function), followed by the Global
namespace (top-level of the module), and finally the Built-in namespace (predefined
functions like len(), sum(), etc.). So, the correct search order for namespaces is: local →
global → built-in.
31. What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
print(i, end=' ')
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
View Answer
Answer: a
Explanation: The expression [1, 2, 3, 4][::-1] uses slicing with a step of -1 to reverse the list.
So the list becomes [4, 3, 2, 1]. The for loop iterates over this reversed list and prints each
element, with end=’ ‘ ensuring the output is on one line with spaces in between.
32. What will be the output of the following Python statement?
print("a"+"bc")
a) bc
b) abc
c) a
d) bca
View Answer
Answer: b
Explanation: In Python, the + operator is used for string concatenation. “a” + “bc” joins the
two strings together into a single string “abc”.
33. Which function is called when the following Python program is executed?
f = foo()
format(f)
a) str()
b) format()
c) __str__()
d) __format__()
View Answer
Answer: d
Explanation: When format(f) is executed, Python internally invokes the special method
f.__format__(). This method controls how the object is formatted. The __str__() method is
used by str(f), not format(f).
34. Which one of the following is not a keyword in Python language?
a) pass
b) eval
c) assert
d) nonlocal
View Answer
Answer: b
Explanation: eval can be used as a variable.
35. What will be the output of the following Python code?
class tester:
def __init__(self, id):
[Link] = str(id)
id="224"
temp = tester(12)
print([Link])
a) 12
b) 224
c) None
d) Error
View Answer
Answer: a
Explanation: When the tester class is instantiated with temp = tester(12), the __init__
method is called. The id argument is passed as 12, and inside the __init__ method, [Link] is
assigned the string value of id, which is “12”. However, the local variable id is reassigned to
“224”, but this change does not affect [Link], which retains the value “12”.
36. What will be the output of the following Python program?
def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a) Error
b) None
c) False
d) True
View Answer
Answer: d
Explanation: The list q is passed by reference to the function foo, so both x and q refer to
the same object in memory. The id() function returns the memory address of the object,
which remains unchanged. Therefore, id(q) == foo(q) evaluates to True.
37. Which module in the python standard library parses options received from the command
line?
a) getarg
b) getopt
c) main
d) os
View Answer
Answer: b
Explanation: The getopt module in Python’s standard library is used to parse command-line
options and arguments. It allows the script to accept flags and parameters (like -h or –help)
similar to those in shell scripts. For example:
import getopt, sys
opts, args = [Link]([Link][1:], "h", ["help"])
This line parses short option -h and long option –help.
38. What will be the output of the following Python program?
z=set('abc')
[Link]('san')
[Link](set(['p', 'q']))
print(z)
a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b) {‘abc’, ‘p’, ‘q’, ‘san’}
c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
View Answer
Answer: c
Explanation: The code shown first adds the element ‘san’ to the set z. The set z is then
updated and two more elements, namely, ‘p’ and ‘q’ are added to it. Hence the output is:
{‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
39. What arithmetic operators cannot be used with strings in Python?
a) *
b) –
c) +
d) All of the mentioned
View Answer
Answer: b
Explanation: + is used to concatenate and * is used to multiply strings.
40. What will be the output of the following Python code?
print("abc. DEF".capitalize())
a) Abc. def
b) abc. def
c) Abc. Def
d) ABC. DEF
View Answer
Answer: a
Explanation: The first letter of the string is converted to uppercase and the others are
converted to lowercase.
41. Which of the following statements is used to create an empty set in Python?
a) ( )
b) [ ]
c) { }
d) set()
View Answer
Answer: d
Explanation: { } creates a dictionary not a set. Only set() creates an empty set.
42. What will be the value of ‘result’ in following Python program?
list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
[Link](i for i in list1 if i not in (list2+list3) and i not in result)
[Link](i for i in list2 if i not in (list1+list3) and i not in result)
[Link](i for i in list3 if i not in (list1+list2) and i not in result)
print(result)
a) [1, 3, 5, 7, 8]
b) [1, 7, 8]
c) [1, 2, 4, 7, 8]
d) error
View Answer
Answer: a
Explanation: Here, ‘result’ is a list which is extending three times. When first time ‘extend’
function is called for ‘result’, the inner code generates a generator object, which is further
used in ‘extend’ function. This generator object contains the values which are in ‘list1’ only
(not in ‘list2’ and ‘list3’).
Same is happening in second and third call of ‘extend’ function in these generator object
contains values only in ‘list2’ and ‘list3’ respectively.
So, ‘result’ variable will contain elements which are only in one list (not more than 1 list).
43. To add a new element to a list we use which Python command?
a) [Link](5)
b) [Link](5)
c) [Link](5)
d) [Link](5)
View Answer
Answer: c
Explanation: We use the function append to add an element to the list.
44. What will be the output of the following Python code?
print('*', "abcde".center(6), '*', sep='')
a) * abcde *
b) *abcde *
c) * abcde*
d) * abcde *
View Answer
Answer: b
Explanation: Padding is done towards the right-hand-side first when the final string is of
even length.
45. What will be the output of the following Python code?
list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
a) [1, 4]
b) [1, 3, 4]
c) [4, 3]
d) [1, 3]
View Answer
Answer: c
Explanation: In the code, list2 = list1 creates a reference to the same list in memory. So
w What will be the output of the following Python code?
i = 1
while True:
if i%3 == 0:
break
print(i)
i + = 1
a) 1 2 3
b) SyntaxError
c) 1 2
d) none of the mentioned
What will be the output of the following Python code snippet if x=1?
x<<2
a) 4
b) 2
c) 1
d) 8
View Answer
Answer: a
Which of the following is true for variable names in Python?
a) underscore and ampersand are the only two special characters allowed
b) unlimited length
c) all private members must have leading and trailing underscores
d) none of the mentioned
View Answer
Answer: b
What are the values of the following Python expressions?
print(2**(3**2))
print((2**3)**2)
print(2**3**2)
a) 512, 64, 512
b) 512, 512, 512
c) 64, 512, 64
d) 64, 64, 64
View Answer
Answer: a
What will be the output of the following Python code?
l=[1, 0, 2, 0, 'hello', '', []]
print(list(filter(bool, l)))
a) [1, 0, 2, ‘hello’, ”, []]
b) Error
c) [1, 2, ‘hello’]
d) [1, 0, 2, 0, ‘hello’, ”, []]
View Answer
Answer: c
What will be the output of the following Python code?
x = 'abcd'
for i in x:
print([Link]())
a)a
b) a b c d
c) error
d)
View Answer
Answer: d
What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
print(i, end=' ')
a) 4 3 2 1
b) error
c) 1 2 3 4
d) none of the mentioned
View Answer
Answer: a
What will be the output of the following Python program?
z=set('abc')
[Link]('san')
[Link](set(['p', 'q']))
print(z)
a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b) {‘abc’, ‘p’, ‘q’, ‘san’}
c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
View Answer
Answer: c
What will be the value of ‘result’ in following Python program?
list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
[Link](i for i in list1 if i not in (list2+list3) and i not in result)
[Link](i for i in list2 if i not in (list1+list3) and i not in result)
[Link](i for i in list3 if i not in (list1+list2) and i not in result)
print(result)
a) [1, 3, 5, 7, 8]
b) [1, 7, 8]
c) [1, 2, 4, 7, 8]
d) error
What will be the output of the following Python code?
list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
a) [1, 4]
b) [1, 3, 4]
c) [4, 3]
d) [1, 3]
Here are some multiple-choice questions (MCQs) on Python, along with their answers:
Q1: What is the correct way to define a function in Python?
a) function my_func():
b) def my_func():
c) create function my_func():
d) func my_func():
Answer: b) def my_func():
Q2: Which of the following is a mutable data type in Python?
a) tuple b) str c) list d) int
Answer: c) list
Q3: What does the len() function return when applied to a string?
a) The memory size of the string. b) The number of words in the string. c) The number of
characters in the string. d) The ASCII value of the first character.
Answer: c) The number of characters in the string.
Q4: How do you create a single-line comment in Python?
a) /* This is a comment */ b) # This is a comment c) // This is a comment d) <!-- This is a
comment -->
Answer: b) # This is a comment
Q5: What will be the output of the following code snippet?
Python
print(9 // 2)
a) 4.5 b) 4 c) 5 d) Error
Answer: b) 4
Q6: Which operator is used for exponentiation in Python?
a) ^
b) **
c) %
d) *
Answer: b) **
Q7: Which statement is used to exit a loop in Python?
a) continue b) exit c) break d) end
Answer: c) break
Q8: What is the output of print("Python"[::-1])?
a) Python b) nohtyP c) Error d) None
C Programming MCQ (Multiple Choice Questions)
Here are 1000 MCQs on C Programming (Chapterwise).
1. Who is the father of C language?
a) Steve Jobs
b) James Gosling
c) Dennis Ritchie
d) Rasmus Lerdorf
View Answer
Answer: c
Explanation: Dennis Ritchie is the father of C Programming Language. C programming
language was developed in 1972 at American Telephone & Telegraph Bell Laboratories of
USA.
2. Which of the following is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;
View Answer
Answer: d
Explanation: Since only underscore and no other special character is allowed in a variable
name, it results in an error.
3. All keywords in C are in ____________
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned
View Answer
Answer: a
Explanation: None.
4. Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length
View Answer
Answer: c
Explanation: According to the syntax for C variable name, it cannot start with a digit.
5. Which is valid C expression?
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;
View Answer
Answer: b
Explanation: Space, comma and $ cannot be used in a variable name.
6. Which of the following cannot be a variable name in C?
a) volatile
b) true
c) friend
d) export
View Answer
Answer: a
Explanation: volatile is C keyword.
7. What is short int in C programming?
a) The basic data type of C
b) Qualifier
c) Short is the qualifier and int is the basic data type
d) All of the mentioned
View Answer
Answer: c
Explanation: None.
8. Which of the following declaration is not supported by C language?
a) String str;
b) char *str;
c) float str = 3e2;
d) Both “String str;” and “float str = 3e2;”
View Answer
Answer: a
Explanation: It is legal in Java, but not in C language.
9. Which keyword is used to prevent any changes in the variable within a C program?
a) immutable
b) mutable
c) const
d) volatile
View Answer
Answer: c
Explanation: const is a keyword constant in C program.
10. What is the result of logical or relational expression in C?
a) True or False
b) 0 or 1
c) 0 if an expression is false and any positive number if an expression is true
d) None of the mentioned
View Answer
Answer: b
Explanation: None.
11. Which of the following typecasting is accepted by C language?
a) Widening conversions
b) Narrowing conversions
c) Widening & Narrowing conversions
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
12. Where in C the order of precedence of operators do not exist?
a) Within conditional statements, if, else
b) Within while, do-while
c) Within a macro definition
d) None of the mentioned
View Answer
Answer: d
Explanation: None.
13. Which of the following is NOT possible with any 2 operators in C?
a) Different precedence, same associativity
b) Different precedence, different associativity
c) Same precedence, different associativity
d) All of the mentioned
View Answer
Answer: c
Explanation: None.
14. What is an example of iteration in C?
a) for
b) while
c) do-while
d) all of the mentioned
View Answer
Answer: d
Explanation: None.
15. Functions can return enumeration constants in C?
a) true
b) false
c) depends on the compiler
d) depends on the standard
View Answer
Answer: a
Explanation: None.
16. Functions in C Language are always _________
a) Internal
b) External
c) Both Internal and External
d) External and Internal are not valid terms for functions
View Answer
Answer: b
Explanation: None.
17. Which of following is not accepted in C?
a) static a = 10; //static as
b) static int func (int); //parameter as static
c) static static int a; //a static variable prefixed with static
d) all of the mentioned
View Answer
Answer: c
Explanation: None.
18. Property which allows to produce different executable for different platforms in C is
called?
a) File inclusion
b) Selective inclusion
c) Conditional compilation
d) Recursive macros
View Answer
Answer: c
Explanation: Conditional compilation is the preprocessor facility to produce a different
executable.
19. What is #include <stdio.h>?
a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned
View Answer
Answer: a
Explanation: None.
20. C preprocessors can have compiler specific features.
a) True
b) False
c) Depends on the standard
d) Depends on the platform
View Answer
Answer: a
Explanation: #pragma is compiler specific feature.
21. Which of the following are C preprocessors?
a) #ifdef
b) #define
c) #endif
d) all of the mentioned
View Answer
Answer: d
Explanation: None.
22. The C-preprocessors are specified with _________ symbol.
a) #
b) $
c) ” ”
d) &
View Answer
Answer: a
Explanation: The C-preprocessors are specified with # symbol.
23. How is search done in #include and #include “somelibrary.h” according to C standard?
a) When former is used, current directory is searched and when latter is used, standard
directory is searched
b) When former is used, standard directory is searched and when latter is used, current
directory is searched
c) When former is used, search is done in implementation defined manner and when latter
is used, current directory is searched
d) For both, search for ‘somelibrary’ is done in implementation-defined places
View Answer
Answer: b
Explanation: None.
24. How many number of pointer (*) does C have against a pointer variable declaration?
a) 7
b) 127
c) 255
d) No limits
View Answer
Answer: d
Explanation: None.
25. Which of the following is not possible statically in C language?
a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array
View Answer
Answer: a
Explanation: None.
26. Which of the following return-type cannot be used for a function in C?
a) char *
b) struct
c) void
d) none of the mentioned
View Answer
Answer: d
Explanation: None.
27. The standard header _______ is used for variable list arguments (…) in C.
a) <stdio.h >
b) <stdlib.h>
c) <math.h>
d) <stdarg.h>
View Answer
Answer: d
Explanation: None.
28. When a C program is started, O.S environment is responsible for opening file and
providing pointer for that file?
a) Standard input
b) Standard output
c) Standard error
d) All of the mentioned
View Answer
Answer: d
Explanation: None.
29. In C language, FILE is of which data type?
a) int
b) char *
c) struct
d) None of the mentioned
View Answer
Answer: c
Explanation: None.
30. What is the sizeof(char) in a 32-bit C compiler?
a) 1 bit
b) 2 bits
c) 1 Byte
d) 2 Bytes
View Answer
Answer: c
Explanation: None.
31. Which of the following is not an operator in C?
a) ,
b) sizeof()
c) ~
d) None of the mentioned
View Answer
Answer: d
Explanation: None.
32. scanf() is a predefined function in______header file.
a) stdlib. h
b) ctype. h
c) stdio. h
d) stdarg. h
View Answer
Answer: c
Explanation: scanf() is a predefined function in "stdio.h" header [Link] and scanf() carry
out input and output functions in C. These functions statements are present in the header
file stdio.h.
33. What is meant by ‘a’ in the following C operation?
fp = fopen("[Link]", "a");
a) Attach
b) Append
c) Apprehend
d) Add
View Answer
Answer: b
Explanation: None.
34. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int y = 10000;
5. int y = 34;
6. printf("Hello World! %d\n", y);
7. return 0;
8. }
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value
View Answer
Answer: a
Explanation: Since y is already defined, redefining it results in an error.
Output:
$ cc pgm2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was here
35. What will happen if the following C code is executed?
1. #include <stdio.h>
2. int main()
3. {
4. int main = 3;
5. printf("%d", main);
6. return 0;
7. }
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping
View Answer
Answer: c
Explanation: A C program can have same function name and same variable name.
$ cc pgm3.c
$ [Link]
3
36. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. signed char chr;
5. chr = 128;
6. printf("%d\n", chr);
7. return 0;
8. }
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
View Answer
Answer: b
Explanation: The range of signed character is from -128 to +127. Since we are assigning a
value of 128 to the variable ‘chr’, the result will be negative. 128 in binary is represented as
“1000 0000” for character datatype. As you can see that the sign bit is set to 1, followed by
7 zeros (0), its final decimal value will be -128 (negative 128).
Output:
$ cc pgm2.c
$ [Link]
-128
37. What will be the output of the following C code on a 64 bit machine?
1. #include <stdio.h>
2. union Sti
3. {
4. int nu;
5. char m;
6. };
7. int main()
8. {
9. union Sti s;
10. printf("%d", sizeof(s));
11. return 0;
12. }
a) 8
b) 5
c) 9
d) 4
View Answer
Answer: d
Explanation: Since the size of a union is the size of its maximum data type, here int is the
largest data type. Hence the size of the union is 4.
Output:
$ cc pgm7.c
$ [Link]
4
38. What will be the output of the following C function?
1. #include <stdio.h>
2. enum birds {SPARROW, PEACOCK, PARROT};
3. enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
4. int main()
5. {
6. enum birds m = TIGER;
7. int k;
8. k = m;
9. printf("%d\n", k);
10. return 0;
11. }
a) 0
b) Compile time error
c) 1
d) 8
View Answer
Answer: d
Explanation: m is an integer constant, hence it is compatible.
Output:
$ cc pgm5.c
$ [Link]
8
39. What will be the output of the following C code?
1. #include <stdio.h>
2. int const print()
3. {
4. printf("[Link]");
5. return 0;
6. }
7. void main()
8. {
9. print();
10. }
a) Error because function name cannot be preceded by const
b) [Link]
c) [Link] is printed infinite times
d) Blank screen, no output
View Answer
Answer: b
Explanation: None.
Output:
$ cc pgm13.c
$ [Link]
[Link]
40. Will the following C code compile without any error?
1. #include <stdio.h>
2. int main()
3. {
4. for (int k = 0; k < 10; k++);
5. return 0;
6. }
a) Yes
b) No
c) Depends on the C standard implemented by compilers
d) Error
View Answer
Answer: c
Explanation: Compilers implementing C90 do not allow this, but compilers implementing
C99 allow it.
Output:
$ cc pgm4.c
pgm4.c: In function ‘main’:
pgm4.c:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code
6. What is the extension of java code files?
a) .js
b) .txt
c) .class
d) .java
View Answer
Answer: d
Explanation: Java files have .java extension.
7. What will be the output of the following Java code?
1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. [Link](++g * 8);
6. }
7. }
a) 32
b) 33
c) 24
d) 25
View Answer
Answer: a
Explanation: Operator ++ has more preference than *, thus g becomes 4 and when
multiplied by 8 gives 32.
output:
$ javac [Link]
$ java increment
32
8. Which environment variable is used to set the java path?
a) MAVEN_Path
b) JavaPATH
c) JAVA
d) JAVA_HOME
View Answer
Answer: d
Explanation: JAVA_HOME is used to store a path to the java installation.
9. What will be the output of the following Java program?
1. class output {
2. public static void main(String args[])
3. {
4. double a, b,c;
5. a = 3.0/0;
6. b = 0/4.0;
7. c=0/0.0;
8.
9. [Link](a);
10. [Link](b);
11. [Link](c);
12. }
13. }
a) NaN
b) Infinity
c) 0.0
d) all of the mentioned
View Answer
Answer: d
Explanation: For floating point literals, we have constant value to represent (10/0.0) infinity
either positive or negative and also have NaN (not a number for undefined like 0/0.0), but
for the integral type, we don’t have any constant that’s why we get an arithmetic exception.
10. Which of the following is not an OOPS concept in Java?
a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation
View Answer
Answer: c
Explanation: There are 4 OOPS concepts in Java. Inheritance, Encapsulation,
Polymorphism and Abstraction.
11. What is not the use of “this” keyword in Java?
a) Referring to the instance variable when a local variable has the same name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining
View Answer
Answer: b
Explanation: “this” is an important keyword in java. It helps to distinguish between local
variable and variables passed in the method as parameters.
12. What will be the output of the following Java program?
1. class variable_scope
2. {
3. public static void main(String args[])
4. {
5. int x;
6. x = 5;
7. {
8. int y = 6;
9. [Link](x + " " + y);
10. }
11. [Link](x + " " + y);
12. }
13. }
a) Compilation error
b) Runtime error
c) 5 6 5 6
d) 5 6 5
View Answer
Answer: a
Explanation: Second print statement doesn’t have access to y , scope y was limited to the
block defined after initialization of x.
output:
$ javac variable_scope.java
Exception in thread "main" [Link]: Unresolved compilation problem: y
cannot be resolved to a variable
13. What will be the error in the following Java code?
byte b = 50;
b = b * 50;
a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which cannot be converted to byte without
casting
View Answer
Answer: d
Explanation: While evaluating an expression containing int, bytes or shorts, the whole
expression is converted to int then evaluated and the result is also of type int.
14. Which of the following is a type of polymorphism in Java Programming?
a) Multiple polymorphism
b) Compile time polymorphism
c) Multilevel polymorphism
d) Execution time polymorphism
View Answer
Answer: b
Explanation: There are two types of polymorphism in Java. Compile time polymorphism
(overloading) and runtime polymorphism (overriding).
15. What will be the output of the following Java program?
1. class leftshift_operator
2. {
3. public static void main(String args[])
4. {
5. byte x = 64;
6. int i;
7. byte y;
8. i = x << 2;
9. y = (byte) (x << 2);
10. [Link](i + " " + y);
11. }
12. }
a) 0 256
b) 0 64
c) 256 0
d) 64 0
View Answer
Answer: c
Explanation: A variable of type int can store values within 32 bits, while a byte has only 8
bits to store any value. The expression (64 << 2) results in 256, which requires at least 9
bits to represent. Therefore:
• For byte: The 9th bit is lost (truncated), and the remaining 8 bits are all zeros,
resulting in zero.
• For int: All significant bits are preserved, allowing the value 256 to be stored
correctly.
output:
$ javac leftshift_operator.java
$ java leftshift_operator
256 0
16. What will be the output of the following Java code?
1. class box
2. {
3. int width;
4. int height;
5. int length;
6. }
7. class main
8. {
9. public static void main(String args[])
10. {
11. box obj = new box();
12. [Link] = 10;
13. [Link] = 2;
14. [Link] = 10;
15. int y = [Link] * [Link] * [Link];
16. [Link](y);
17. }
18. }
a) 100
b) 400
c) 200
d) 12
View Answer
Answer: c
Explanation: The variables length, breadth, and height are default (friendly) instance
variables of the Box class. Therefore, they can be accessed directly by the object. The
variable y stores the product of these three variables, resulting in an output of 200.
output:
$ javac [Link]
$ java main
200
17. What is Truncation in Java?
a) Floating-point value assigned to a Floating type
b) Floating-point value assigned to an integer type
c) Integer value assigned to floating type
d) Integer value assigned to floating type
View Answer
Answer: b
Explanation: Truncation refers to the removal of digits after the decimal point. When a
floating-point value (float, double, etc.) is assigned to an integer type (int, long, etc.), the
fractional part after the decimal point is discarded.
Note: This operation requires explicit type casting.
18. What will be the output of the following Java program?
1. class Output
2. {
3. public static void main(String args[])
4. {
5. int arr[] = {1, 2, 3, 4, 5};
6. for ( int i = 0; i < [Link] - 2; ++i)
7. [Link](arr[i] + " ");
8. }
9. }
a) 1 2 3 4 5
b) 1 2 3 4
c) 1 2
d) 1 2 3
View Answer
Answer: d
Explanation:
Explanation: Since, [Link]() is 5, then the loop is iterate for 0, 1, 2. Which prints the 1, 2,
3, respectively.
output:
$ javac [Link]
$ java Output
1 2 3
19. What will be the output of the following Java code snippet?
1. class abc
2. {
3. public static void main(String args[])
4. {
5. if([Link]>0)
6. [Link]([Link]);
7. }
8. }
a) The snippet compiles and runs but does not print anything
b) The snippet compiles, runs and prints 0
c) The snippet compiles, runs and prints 1
d) The snippet does not compile
View Answer
Answer: a
Explanation: As no argument is passed to the code, the length of args is 0. So the code will
not print.
20. What is the extension of compiled java classes?
a) .txt
b) .js
c) .class
d) .java
View Answer
Answer: c
Explanation: The compiled java files have .class extension.
21. Which exception is thrown when java is out of memory?
a) MemoryError
b) OutOfMemoryError
c) MemoryOutOfBoundsException
d) MemoryFullException
View Answer
Answer: b
Explanation: The Xms flag has no default value, and Xmx typically has a default value of
256MB. A common use for these flags is when you encounter a
[Link].
22. What will be the output of the following Java code?
1. class String_demo
2. {
3. public static void main(String args[])
4. {
5. char chars[] = {'a', 'b', 'c'};
6. String s = new String(chars);
7. [Link](s);
8. }
9. }
a) abc
b) a
c) b
d) c
View Answer
Answer: a
Explanation: String(chars) is a constructor of class string, it initializes string s with the
values stored in character array chars, therefore s contains “abc”.
23. Which of these are selection statements in Java?
a) break
b) continue
c) for()
d) if()
View Answer
Answer: d
Explanation: Continue and break are jump statements, and for is a looping statement.
24. What will be the output of the following Java program?
1. class recursion
2. {
3. int func (int n)
4. {
5. int result;
6. if (n == 1)
7. return 1;
8. result = func (n - 1);
9. return result;
10. }
11. }
12. class Output
13. {
14. public static void main(String args[])
15. {
16. recursion obj = new recursion() ;
17. [Link]([Link](5));
18. }
19. }
a) 1
b) 120
c) 0
d) None of the mentioned
View Answer
Answer: a
Explanation: The base case returns the value 1 for each call, which is stored in 1 and
returned inside the main() where it is called.
Output:
$ javac [Link]
$ java Output
1
25. What will be the output of the following Java code?
1. class output
2. {
3. public static void main(String args[])
4. {
5. String c = "Hello i love java";
6. boolean var;
7. var = [Link]("hello");
8. [Link](var);
9. }
10. }
a) 0
b) true
c) 1
d) false
View Answer
Answer: d
Explanation: The startsWith() method is case-sensitive; for example, “hello” and “Hello” are
treated as different strings. Therefore, the result of the method is false, which is stored in
the variable since the return type of startsWith() is boolean.
Note: Although var is a keyword used for type inference in Java, it can still be used as an
identifier in earlier versions where var is not a reserved keyword.
26. Which of these keywords is used to define interfaces in Java?
a) intf
b) Intf
c) interface
d) Interface
View Answer
Answer: c
Explanation: interface keyword is used to define interfaces in Java.
27. What will be the output of the following Java program?
1. class output
2. {
3. public static void main(String args[])
4. {
5. StringBuffer s1 = new StringBuffer("Quiz");
6. StringBuffer s2 = [Link]();
7. [Link](s2);
8. }
9. }
a) QuizziuQ
b) ziuQQuiz
c) Quiz
d) ziuQ
View Answer
Answer: d
Explanation: reverse() method reverses all characters. It returns the reversed object on
which it was called.
Output:
$ javac [Link]
$ java output
ziuQ
28. What will be the output of the following Java code?
1. class Output
2. {
3. public static void main(String args[])
4. {
5. Integer i = new Integer(257);
6. byte x = [Link]();
7. [Link](x);
8. }
9. }
a) 257
b) 256
c) 1
d) 0
View Answer
Answer: c
Explanation: [Link]() method returns the value of wrapper i as a byte value. i is 257,
range of byte is 256 therefore i value exceeds byte range by 1 hence 1 is returned and
stored in x.
Output:
$ javac [Link]
$ java Output
1
29. What will be the output of the following Java program?
1. class Output
2. {
3. public static void main(String args[])
4. {
5. double x = 2.0;
6. double y = 3.0;
7. double z = [Link]( x, y );
8. [Link](z);
9. }
10. }
a) 9.0
b) 8.0
c) 4.0
d) 2.0
View Answer
Answer: b
Explanation: [Link](x, y) methods returns the value of y to the power x as double
{floating point data type}, i:e x ^ y, 2.0 ^ 3.0 = 8.0.
Output:
$ javac [Link]
$ java Output
8.0
30. Which of the following is a superclass of every class in Java?
a) ArrayList
b) Abstract class
c) Object class
d) String
View Answer
Answer: c
Explanation: Object class is superclass of every class in Java.
Which statement is true about Java?
a) Java is a sequence-dependent programming language
b) Java is a code dependent programming language
c) Java is a platform-dependent programming language
d) Java is a platform-independent programming language
View Answer
Answer: d
What will be the output of the following Java code?
1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. [Link](++g * 8);
6. }
7. }
a) 32
b) 33
c) 24
d) 25
View Answer
Answer: a
Explanation: Operator ++ has more preference than *, thus g becomes 4 and when
multiplied by 8 gives 32.
. What will be the output of the following Java program?
1. class output {
2. public static void main(String args[])
3. {
4. double a, b,c;
5. a = 3.0/0;
6. b = 0/4.0;
7. c=0/0.0;
8.
9. [Link](a);
10. [Link](b);
11. [Link](c);
12. }
13. }
a) NaN
b) Infinity
c) 0.0
d) all of the mentioned
View Answer
Answer: d
Explanation: For floating point literals, we have constant value to represent (10/0.0) infinity
either positive or negative and also have NaN (not a number for undefined like 0/0.0), but
for the integral type, we don’t have any constant that’s why we get an arithmetic exception.
What will be the output of the following Java program?
1. class variable_scope
2. {
3. public static void main(String args[])
4. {
5. int x;
6. x = 5;
7. {
8. int y = 6;
9. [Link](x + " " + y);
10. }
11. [Link](x + " " + y);
12. }
13. }
a) Compilation error
b) Runtime error
c) 5 6 5 6
d) 5 6 5
View Answer
Answer: a
Explanation: Second print statement doesn’t have access to y , scope y was limited to the
block defined after initialization of x.
Java Programming MCQ (Multiple Choice Questions)
Here are 1000 MCQs on Java Programming (Chapterwise).
1. Who invented Java Programming?
a) Guido van Rossum
b) James Gosling
c) Dennis Ritchie
d) Bjarne Stroustrup
View Answer
Answer: b
Explanation: Java programming was developed by James Gosling at Sun Microsystems in
1995. James Gosling is well known as the father of Java.
2. Which statement is true about Java?
a) Java is a sequence-dependent programming language
b) Java is a code dependent programming language
c) Java is a platform-dependent programming language
d) Java is a platform-independent programming language
View Answer
Answer: d
Explanation: Java is called ‘Platform Independent Language’ as it primarily works on the
principle of ‘compile once, run everywhere’.
3. Which component is used to compile, debug and execute the java programs?
a) JRE
b) JIT
c) JDK
d) JVM
View Answer
Answer: c
Explanation: JDK is a core component of Java Environment and provides all the tools,
executables and binaries required to compile, debug and execute a Java Program.
4. Which one of the following is not a Java feature?
a) Object-oriented
b) Use of pointers
c) Portable
d) Dynamic and Extensible
View Answer
Answer: b
Explanation: Pointers is not a Java feature. Java provides an efficient abstraction layer for
developing without using a pointer in Java. Features of Java Programming are Portable,
Architectural Neutral, Object-Oriented, Robust, Secure, Dynamic and Extensible, etc.
5. Which of these cannot be used for a variable name in Java?
a) identifier & keyword
b) identifier
c) keyword
d) none of the mentioned
View Answer
Answer: c
Explanation: Keywords are specially reserved words that can not be used for naming a
user-defined variable, for example: class, int, for, etc
Which of the following is a type of polymorphism in Java Programming?
a) Multiple polymorphism
b) Compile time polymorphism
c) Multilevel polymorphism
d) Execution time polymorphism
View Answer
Answer: b
Explanation: There are two types of polymorphism in Java. Compile time polymorphism
(overloading) and runtime polymorphism (overriding).
What will be the output of the following Java program?
1. class leftshift_operator
2. {
3. public static void main(String args[])
4. {
5. byte x = 64;
6. int i;
7. byte y;
8. i = x << 2;
9. y = (byte) (x << 2);
10. [Link](i + " " + y);
11. }
12. }
a) 0 256
b) 0 64
c) 256 0
d) 64 0
View Answer
Answer: c
Explanation: A variable of type int can store values within 32 bits, while a byte has only 8
bits to store any value. The expression (64 << 2) results in 256, which requires at least 9
bits to represent. Therefore:
• For byte: The 9th bit is lost (truncated), and the remaining 8 bits are all zeros,
resulting in zero.
• For int: All significant bits are preserved, allowing the value 256 to be stored
correctly.
output:
Artificial Intelligence MCQ (Multiple Choice Questions)
Here are 1000 MCQs on AI (Chapterwise).
1. What is the full form of “AI”?
a) Artificially Intelligent
b) Artificial Intelligence
c) Artificially Intelligence
d) Advanced Intelligence
View Answer
Answer: b
Explanation: AI is abbreviated as Artificial Intelligence. It is used to create systems or build
machines to think and work like humans.
2. What is Artificial Intelligence?
a) Artificial Intelligence is a field that aims to make humans more intelligent
b) Artificial Intelligence is a field that aims to improve the security
c) Artificial Intelligence is a field that aims to develop intelligent machines
d) Artificial Intelligence is a field that aims to mine the data
View Answer
Answer: c
Explanation: Artificial Intelligence is the development of intelligent systems that work and
react in the same way that humans do. Intelligence is a process or a component of the
ability to achieve goals in the world. People, animals, and a few machines all have different
types and degrees of intelligence.
3. Who is the inventor of Artificial Intelligence?
a) Geoffrey Hinton
b) Andrew Ng
c) John McCarthy
d) Jürgen Schmidhuber
View Answer
Answer: c
Explanation: John McCarthy was a pioneer in Artificial Intelligence research, helping to
name the field and spending decades teaching computers to grasp concepts that are
intuitive to humans.
4. Which of the following is the branch of Artificial Intelligence?
a) Machine Learning
b) Cyber forensics
c) Full-Stack Developer
d) Network Design
View Answer
Answer: a
Explanation: Machine learning is one of the important sub-areas of Artificial Intelligence
likewise Neural Networks, Computer Vision, Robotics, and NLP are also the sub-areas. In
machine learning, we build or train ML models to do certain tasks.
5. What is the goal of Artificial Intelligence?
a) To solve artificial problems
b) To extract scientific causes
c) To explain various sorts of intelligence
d) To solve real-world problems
View Answer
Answer: c
Explanation: Artificial Intelligence’s goal is to explain various sorts of intelligence.
6. Which of the following is an application of Artificial Intelligence?
a) It helps to exploit vulnerabilities to secure the firm
b) Language understanding and problem-solving (Text analytics and NLP)
c) Easy to create a website
d) It helps to deploy applications on the cloud
View Answer
Answer: b
Explanation: Language understanding and problem-solving come under the NLP and Text
Analysis area which involves text recognition and sentiment analysis of the text. NLP ML
model is trained to mainly do the task which processes human language’s speech or text.
For example voice assistant.
7. In how many categories process of Artificial Intelligence is categorized?
a) categorized into 5 categories
b) processes are categorized based on the input provided
c) categorized into 3 categories
d) process is not categorized
View Answer
Answer: c
Explanation: It is categorized into 3 steps Sensing, Reasoning, Acting
i) Sensing: Through the sensor taking in the data about the world
ii) Reasoning: Reasoning is thinking or processing the data sensed by the sensor.
iii) Action: On the basis of input and reasoning, acting is generating and controlling actions
in the environment.
8. Based on which of the following parameter Artificial Intelligence is categorized?
a) Based on functionally only
b) Based on capabilities only
c) Based on capabilities and functionally
d) It is not categorized
View Answer
Answer: c
Explanation: The two main categorizations of AI are based on the capability and
functionality. Based on capability it is divided into Artificial Narrow Intelligence (ANI),
Artificial General Intelligence (AGI), and Artificial Super Intelligence (ASI). Based on
functionality it is divided into reactive machines, limited memory, theory of mind, and self-
awareness.
9. Which of the following is a component of Artificial Intelligence?
a) Learning
b) Training
c) Designing
d) Puzzling
View Answer
Answer: a
Explanation: Intelligence is intangible and is composed of mainly five techniques. Learning
is the process of gaining knowledge by understanding, practicing, being taught, or
experiencing one thing. Learning enhances the awareness of any topic, hence learning is
one of the important components.
10. What is the function of an Artificial Intelligence “Agent”?
a) Mapping of goal sequence to an action
b) Work without the direct interference of the people
c) Mapping of precept sequence to an action
d) Mapping of environment sequence to an action
View Answer
Answer: c
Explanation: A math function that converts a collection of perceptions into actions is known
as the agent function. The function is implemented using agent software. An agent is
responsible for the actions performed by the machine once it senses the environment.
11. Which of the following is not a type of Artificial Intelligence agent?
a) Learning AI agent
b) Goal-based AI agent
c) Simple reflex AI agent
d) Unity-based AI agent
View Answer
Answer: d
Explanation: There are mainly 5 types of agents
12. Which of the following is not the commonly used programming language for Artificial
Intelligence?
a) Perl
b) Java
c) PROLOG
d) LISP
View Answer
Answer: a
Explanation: Perl is a scripting language. Whereas other programming languages are used
to program AI machines.
13. What is the name of the Artificial Intelligence system developed by Daniel Bobrow?
a) program known as BACON
b) system known as STUDENT
c) program known as SHRDLU
d) system known as SIMD
View Answer
Answer: b
Explanation: STUDENT is the name of the Artificial Intelligence system developed by Daniel
Bobrow in 1964. Daniel Bobrow had used LISP programming language to write this AI
program for his PhD thesis.
14. What is the function of the system Student?
a) program that can read algebra word problems only
b) system which can solve algebra word problems but not read
c) system which can read and solve algebra word problems
d) None of the mentioned
View Answer
Answer: c
Explanation: The system STUDENT developed by Daniel Bobrow was written in LISP to
read and solve algebra word problems of high school books. This is referred as the
achievement in the field of Natural Language Processing.
15. Which of the following is not an application of artificial intelligence?
a) Face recognition system
b) Chatbots
c) LIDAR
d) DBMS
View Answer
Answer: d
Explanation: Face recognition system, Chatbots, and LIDAR are the various applications of
AI in various fields like security system, business, automobiles etc. DBMS is used to store
and manipulate data.
16. Which of the following machine requires input from the humans but can interpret the
outputs themselves?
a) Actuators
b) Sensor
c) Agents
d) AI system
View Answer
Answer: d
Explanation: Actuators are used in machines to convert energy from one form to another to
perform a physical function. The sensor is a device that receives signals from the physical
environment to detect the changes. Systems receive input from humans and interpret the
outputs.
17. _________ number of informed search method are there in Artificial Intelligence.
a) 4
b) 3
c) 2
d) 1
View Answer
Answer: a
Explanation: There are four types of informed search methods. The four types of informed
search method are best-first search, Greedy best-first search, A* search and memory
bounded heuristic search.
18. The total number of proposition symbols in AI are ________
a) 3 proposition symbols
b) 1 proposition symbols
c) 2 proposition symbols
d) No proposition symbols
View Answer
Answer: c
Explanation: There are totally 2 proposition symbols. The two proposition symbols are true
and false.
19. The total number of logical symbols in AI are ____________
a) There are 3 logical symbols
b) There are 5 logical symbols
c) Number of logical symbols are based on the input
d) Logical symbols are not used
View Answer
Answer: b
Explanation: There are totally five logical symbols. The five logical symbols are:
a) Negation
b) Conjunction
c) Disjunction
d) Implication
e) Biconditional
20. Which of the following are the approaches to Artificial Intelligence?
a) Applied approach
b) Strong approach
c) Weak approach
d) All of the mentioned
View Answer
Answer: d
Explanation: Strong AI is used to build machines that can truly reason and solve problems.
Weak AI deals with building computer-based Artificial Intelligence that can act as if it were
intelligent but cannot truly reason and solve problems. Applied approach creates
commercially viable “smart” systems.
In the Cognitive approach, a computer is used to test theories about how the human mind
works.
21. Face Recognition system is based on which type of approach?
a) Weak AI approach
b) Applied AI approach
c) Cognitive AI approach
d) Strong AI approach
View Answer
Answer: b
Explanation: Applied approach aims to produce commercially viable “smart” systems such
as, for example, a security system that recognizes the faces of people to provide access.
The applied approach has already enjoyed considerable success.
22. Which of the following is an advantage of artificial intelligence?
a) Reduces the time taken to solve the problem
b) Helps in providing security
c) Have the ability to think hence makes the work easier
d) All of the above
View Answer
Answer: d
Explanation: Artificial intelligence creates a machine that can think and make decisions
without human involvement.
23. Which of the following can improve the performance of an AI agent?
a) Perceiving
b) Learning
c) Observing
d) All of the mentioned
View Answer
Answer: b
Explanation: An AI agent learns from previous states by saving it and responding to the
same situation better if it occurs again in the future. Hence, learning can improve the
performance of an AI agent.
24. Which of the following is/are the composition for AI agents?
a) Program only
b) Architecture only
c) Both Program and Architecture
d) None of the mentioned
View Answer
Answer: c
Explanation: An AI agent program will implement function mapping percepts to actions.
25. On which of the following approach A basic line following robot is based?
a) Applied approach
b) Weak approach
c) Strong approach
d) Cognitive approach
View Answer
Answer: b
Explanation: Weak approach is concerned with the development of a computer-based
artificial intelligence that can behave intelligently but cannot really reason or solve issues.
According to Weak approach, properly configured computers can mimic human intellect.
26. Artificial Intelligence has evolved extremely in all the fields except for _________
a) Web mining
b) Construction of plans in real time dynamic systems
c) Understanding natural language robustly
d) All of the mentioned
View Answer
Answer: d
Explanation: Artificial Intelligence is used in all the fields to make work easier and complete
the work before the deadline. However, it could not excel in these fields. Hence, these
areas need more focus for improvements.
27. Which of the following is an example of artificial intelligent agent/agents?
a) Autonomous Spacecraft
b) Human
c) Robot
d) All of the mentioned
View Answer
Answer: d
Explanation: Humans can be considered agents. Sensors include eyes, ears, skin, taste
buds, and so on, whereas effectors include hands, fingers, legs, and mouth. Agents are
robots. Sensors on robots might include a camera, sonar, infrared, bumper, and so on.
Actuators can include grippers, wheels, lights, speakers, and other components. Based on
its senses, autonomous spacecraft makes decisions on its own.
28. Which of the following is an expansion of Artificial Intelligence application?
a) Game Playing
b) Planning and Scheduling
c) Diagnosis
d) All of the mentioned
View Answer
Answer: d
Explanation: In recent days AI is used in all sectors in different forms. All sectors require
intelligence and automation for its working.
29. What is an AI ‘agent’?
a) Takes input from the surroundings and uses its intelligence and performs the desired
operations
b) An embedded program controlling line following robot
c) Perceives its environment through sensors and acting upon that environment through
actuators
d) All of the mentioned
View Answer
Answer: d
Explanation: An AI agent is defined as anything that uses sensors and actuators to perceive
and act on the environment. It receives information from its surroundings via sensors,
executes operations, and outputs via actuators.
30. Which of the following environment is strategic?
a) Rational
b) Deterministic
c) Partial
d) Stochastic
View Answer
Answer: b
Explanation: In a deterministic environment the output is determined based on a particular
state. If the environment is deterministic except for the action of other agents it is called
deterministic.
31. What is the name of Artificial Intelligence which allows machines to handle vague
information with a deftness that mimics human intuition?
a) Human intelligence
b) Boolean logic
c) Functional logic
d) Fuzzy logic
View Answer
Answer: d
Explanation: Many popular goods, such as microwave ovens, cars, and plug-in circuit
boards for desktop PCs, employ the first widely-used commercial form of Artificial
Intelligence. It enables robots to handle ambiguous data with a dexterity that resembles
human intuition.
32. Which of the following produces hypotheses that are easy to read for humans?
a) Machine Learning
b) ILP
c) First-order logic
d) Propositional logic
View Answer
Answer: b
Explanation: ILP (Inductive logic programming) is a subfield of artificial intelligence.
Because ILP can participate in the scientific cycle of experimentation So that it can produce
a flexible structure.
33. What does the Bayesian network provide?
a) Partial description of the domain
b) Complete description of the problem
c) Complete description of the domain
d) None of the mentioned
View Answer
Answer: c
Explanation: A Bayesian network provides a complete description of the domain.
33. What is the total number of quantification available in artificial intelligence?
a) 4
b) 3
c) 1
d) 2
View Answer
Answer: d
Explanation: There are two types of quantification. They are:
a) Universal
b) Existential
34. What is Weak AI?
a) the study of mental faculties using mental models implemented on a computer
b) the embodiment of human intellectual capabilities within a computer
c) a set of computer programs that produce output that would be considered to reflect
intelligence if it were generated by humans
d) all of the mentioned
View Answer
Answer: a
Explanation: Weak AI is the study of mental faculties using mental models implemented on
a computer.
35. Which of the following are the 5 big ideas of AI?
a) Perception
b) Human-AI Interaction
c) Societal Impact
d) All of the above
View Answer
Answer: d
Explanation: The 5 big ideas are: