[go: up one dir, main page]

0% found this document useful (0 votes)
44 views12 pages

Programming Quiz

This document is a programming quiz for the course 'Introduction to Programming in C++' at Copperbelt University, consisting of 100 questions divided into multiple choice, true/false, and short answer sections. It assesses students' understanding of C++ concepts, syntax, and programming principles. The quiz covers various topics including data types, operators, and the structure of C++ programs.

Uploaded by

wanahseint
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views12 pages

Programming Quiz

This document is a programming quiz for the course 'Introduction to Programming in C++' at Copperbelt University, consisting of 100 questions divided into multiple choice, true/false, and short answer sections. It assesses students' understanding of C++ concepts, syntax, and programming principles. The quiz covers various topics including data types, operators, and the structure of C++ programs.

Uploaded by

wanahseint
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Programming Quiz: Introduction to Programming in

C++

COPPERBELT UNIVERSITY
Department of Computer Science
Course Code: CS110
Course Title: Introduction to Computing
Unit Focus: Unit 11-14
QUIZ: 100 Questions
Introduction to Programming in C++
INSTRUCTIONS:
●​ Answer ALL questions.
●​ Section A: Multiple Choice (1-50)
●​ Section B: True or False (51-70)
●​ Section C: One-word or Short Answer (71-100)
●​ This assessment evaluates conceptual understanding, critical thinking, and application.

SECTION A: MULTIPLE CHOICE QUESTIONS (1-50)

Choose the most appropriate answer from the given options.


1.​ Which of the following is NOT a programming language?​
A. Python​
B. Java​
C. C++​
D. HTML
2.​ What is the primary role of a compiler?​
A. To execute code line-by-line​
B. To write code​
C. To translate source code into machine-executable code​
D. To store data in memory

Compiled by Chisale
1
3.​ In C++, which symbol begins a preprocessor directive?​
A. $​
B. #​
C. @​
D.%
4.​ Which of the following is an advantage of compiled languages over interpreted ones?​
A. Easier syntax​
B. More secure​
C. Faster execution time​
D. Cross-platform by default
5.​ What is the function of a linker in program compilation?​
A. To check syntax​
B. To execute source code​
C. To translate machine code​
D. To produce an executable file
6.​ The traditional first program in C++ displays:​
A. Welcome User​
B. Hello World​
C. Start Program​
D. Print Name
7.​ In the Hello World program, what is the output redirection symbol?​
A. <<​
B. >>​
C. //​
D. **
8.​ The correct extension for C++ source files is:​
A. .java​
B. .txt​
C. .cpp​
D. .py
9.​ Which component is NOT typically part of an IDE?​
A. Debugger​
B. Linker​
C. Compiler​
D. Spreadsheet editor
10.​The file 'iostream.h' is used for:​
A. File management​
B. Math calculations​
C. Input/Output stream operations​
D. Memory allocation
11.​What is the key difference between an interpreter and a compiler?​
A. Interpreters produce faster executables​

Compiled by Chisale
2
B. Compilers translate the entire source code before execution​
C. Interpreters produce object files​
D. Compilers interpret line-by-line
12.​Which of these accurately describes a program?​
A. Only the machine code the computer runs​
B. Only the source code written by the programmer​
C. Either source code or the final executable​
D. A set of hardware instructions
13.​What is the main reason modern programmers prefer well-written and maintainable
code?​
A. It executes faster​
B. Memory is expensive​
C. Maintenance costs are high​
D. Users demand optimized code
14.​Which statement about debugging is true?​
A. Debugging only happens before compiling​
B. It is rarely necessary in C++​
C. Most program costs come from debugging and maintenance​
D. Linking fixes most bugs automatically
15.​What is the first question a programmer should ask before writing a program?​
A. What language should I use?​
B. Can I buy this software?​
C. What is the problem I'm solving?​
D. What data type should I use?
16.​What component of an IDE helps trace logical errors in programs?​
A. Compiler​
B. Debugger​
C. Code editor​
D. File manager
17.​Which of the following is not a typical C++ source file extension?​
A. .CPP​
B. .CP​
C. .C​
D. .JS
18.​What is the function of 'main()' in a C++ program?​
A. Outputs user data​
B. Initializes all variables​
C. Entry point for program execution​
D. Links external files
19.​Which of the following errors is most likely to be identified at compile time?​
A. Incorrect algorithm​
B. Syntax error​

Compiled by Chisale
3
C. Missing hardware driver​
D. Memory leak
20.​What is the output of:​
cout << "Area is:\t" << 5*4 << endl;​
A. Area is:20​
B. Area is:​
20​
C. Area is: \t20​
D. Error: syntax
21.​What happens if a closing brace is missing in a function definition?​
A. The compiler assumes it​
B. Runtime error occurs​
C. Compiler throws a syntax error​
D. Nothing, it's optional
22.​Which of these programs is easier to understand based on variable naming?​
A. int x, y; z=xy;​
B. int Width, Height, Area; Area = Width * Height;​
C. Both are equal​
D. Neither is valid
23.​What is an 'object' in the context of C++ I/O like cout?​
A. A function​
B. A keyword​
C. An instance of a class​
D. A compiler directive
24.​Which of the following is a correct way to use a symbolic constant?​
A. 'define MAX 100'​
B. const int MAX=100;​
C. MAX=100;​
D. constant int MAX;
25.​What happens when a signed short integer exceeds its maximum value?​
A. It becomes unsigned​
B. It resets to 0​
C. It wraps around to negative values​
D. Compilation fails
26.​The size of an int in C++ is:​
A. Always 4 bytes​
B. Always 2 bytes​
C. Fixed for all systems​
D. System/compiler dependent
27.​Which line of code declares and initializes two float variables correctly?​
A. float x, y=5.0,6.2;​
B. float x=5.0, y=6.2;​

Compiled by Chisale
4
C. float <y=5.0 6.2;​
D. float x:=5.0; y:=6.2;
28.​The escape character for backslash is:​
A. \​
B. \​
C. \b​
D. \\
29.​Which of the following correctly demonstrates typecasting?​
A. int x = (char) 'A';​
B. char x=int(65);​
C. float x=10.0f;​
D. x='A' as int;'
30.​What is the output of 'cout << (float)5/8; ?​
A.​
B. 0.625​
C. 5​
D. Error
31.​What is true about C-style and C++-style comments?​
A. C-style comments support multiple lines​
B. C++-style comments cannot be nested​
C. Both can be used interchangeably​
D. C++-style comments support multiline syntax
32.​Which statement best explains the role of comments in code?​
A. To assist compilers​
B. To improve runtime speed​
C. To explain logic and improve maintainability​
D. To define functions
33.​Which data type is most suitable to store the value of pi?​
A. int​
B. long​
C. float​
D. unsigned short
34.​What is the result of 'cout << '5';'?​
A. 5​
B. 53​
C. '5'​
D. Error
35.​What is the correct declaration for a constant using const?​
A. int const x=10;​
C. const: int x=10;​
B. constant int x=10:​
D. #const x=10;

Compiled by Chisale
5
36.​What is the output of:​
cpp​
unsigned short int x=65535​
x++;​
cout << x;​
A. 65536​
B. Overflow error​
C. O​
D.-1
37.​Why is Hungarian notation discouraged in modern C++?​
A. It is confusing​
B. C++ supports user-defined types and strong typing​
C. It causes compile errors​
D. It's illegal in C++20
38.​In the expression x=a+b;, a+b is called:​
A. an Ivalue​
B. an assignment​
C. an expression​
D. a constant
39.​Which of these shows valid use of sizeof() ?​
A. cout << sizeof int;​
B. sizeof(int)​
C. size(int)​
D. length(int)
40.​Which line will result in a compile-time error?​
A. char letter ='a'​
C. float pi=3.14;​
B. 'int num =""5""'​
D. const int x=10;
41.​The escape sequence " is used to:​
A. Print a double quote​
B. Begin a string​
C. End a statement​
D. Comment a line
42.​Which operator is used for modulus?​
A. &​
B. C.​
D.%
43.​What is the purpose of 'n' in a 'cout' statement?​
A. Ends the program​
B. Inserts a tab​
C. Creates a new line​

Compiled by Chisale
6
D. Prints an empty space
44.​The expression x+=5; is equivalent to:​
A. x=x*5​
B. x=5;​
C. x=x+5​
D. x==5,
45.​Prefix increment is evaluated:​
A. After the statement​
B. Only in loops​
C. Before assignment​
D. Before compile time
46.​In the declaration unsigned short X;, what is the range of 'x'?​
A. 0 to 32767​
B. 0 to 65535​
C. -32768 to 32767​
D. -65535 to 65535
47.​The postfix increment operator is represented as:​
A. ++x​
B. x++​
C. x+1​
D. +=x
48.​Which escape character allows printing a tab?​
A. n​
B. \b​
C. \t​
D. \
49.​The line int main(); is necessary in:​
A. All compilers​
B. Some older or strict compilers​
C. When declaring a float​
D. Only when using variables
50.​What does the term "object file" refer to in the compile process?​
A. A running program​
B. A source file​
C. A pre-linked binary code​
D. An HTML file

SECTION B: TRUE/FALSE QUESTIONS (51-70)

Compiled by Chisale
7
Write TRUE or FALSE for each of the following statements.
51.​The main() function is optional in every C++ program.
52.​#include <iostream.h> includes a header file necessary for input/output.
53.​A literal constant can be assigned a new value during runtime.
54.​The postfix increment operator increments the variable after its current value is used.
55.​Variables in C++ are case-insensitive.
56.​cout is a function used for user input in C++.
57.​The endl manipulator prints a newline to the screen.
58.​A signed short integer can store negative values.
59.​An unsigned variable can store negative numbers.
60.​cin is used for output in C++.
61.​Hungarian notation prefixes variable names with type indicators.
62.​The modulus operator (%) returns the remainder of a division operation.
63.​Constants declared with const cannot be changed during runtime.
64.​An lvalue must be assignable in C++.
65.​All whitespace characters in C++ code are ignored by the compiler.
66.​A block of code in C++ must begin and end with braces {} and }.
67.​The assignment operator is ==.
68.​You can define multiple variables in a single line.
69.​int, float, and char are all valid C++ data types.
70.​Comments affect the execution of C++ code.

SECTION C: ONE-WORD OR SHORT-ANSWER


QUESTIONS (71-100)

Answer each question briefly using one word or a short phrase.


71. What is the function that must exist in every C++ program?
72. What operator is used to assign a value to a variable?
73. What is the result of 5/2 using integer division?
74. What keyword is used to define a constant in modern C++?
75. Give the escape character used to insert a tab.
76. Which operator is used to increase a variable by 1 (postfix)?
77. Which operator is used to combine assignment and addition?
78. How many bytes does a 'char' typically take?
79. What keyword precedes variable declarations to prevent them from taking negative

Compiled by Chisale
8
values?
80. What does 'cout' stand for?
81. What is the result of 8% 5?
82. What C++ component helps identify compile-time errors?
83. What keyword is used to include external files in C++?
84. What is the C++ term for a statement that does nothing?
85. What operator is used for modulus?
86. What is the output of 'cout << 5 + 2; ?
87. How many bits are there in one byte?
88. What keyword is used to declare a floating-point number?
89. Give an example of a C++ keyword.
90. What symbol is used for single-line comments?
91. What is the output of 'cout << "Hello\tWorld!"; ?
92. What does 'endl' do in C++?
93. What header file is required for 'cout' to work?
94. What happens when an unsigned short overflows?
95. What data type would you use to store pi?
96. Name a common C++ IDE.
97. Which memory type do variables get stored in during execution?
98. What command begins every preprocessor directive?
99. What does ASCII stand for?
100. What is 'sizeof(int)' likely to return on a 16-bit system?

ANSWER KEY

SECTION A: MULTIPLE CHOICE (1-50)

1.​ D. HTML
2.​ C. To translate source code into machine-executable code
3.​ B. #
4.​ C. Faster execution time
5.​ D. To produce an executable file
6.​ B. Hello World
7.​ A. <<
8.​ C. .cpp

Compiled by Chisale
9
9.​ D. Spreadsheet editor
10.​C. Input/Output stream operations
11.​C. Compilers translate the entire source code before execution
12.​C. Either source code or the final executable
13.​C. Maintenance costs are high
14.​C. Most program costs come from debugging and maintenance
15.​C. What is the problem I'm solving?
16.​B. Debugger
17.​D. .JS
18.​C. Entry point for program execution
19.​B. Syntax error
20.​B. Area is: 20
21.​C. Compiler throws a syntax error
22.​B. int Width, Height, Area; Area=Width*Height;
23.​C. An instance of a class
24.​B. const int MAX=100;
25.​C. It wraps around to negative values
26.​D. System/compiler dependent
27.​B. float x=5.0, y=6.2;
28.​A. \
29.​A. int x = (char) 'A';
30.​B. 0.625
31.​A. C-style comments support multiple lines
32.​C. To explain logic and improve maintainability
33.​C. float
34.​A. 5
35.​A. int const x=10;
36.​C. 0
37.​B. C++ supports user-defined types and strong typing
38.​C. an expression
39.​B. sizeof(int)
40.​B. int num =""5"";
41.​A. Print a double quote
42.​D. %
43.​C. Creates a new line
44.​C. x=x+5
45.​C. Before assignment
46.​B. 0 to 65535
47.​B. x++
48.​C. \t
49.​B. Some older or strict compilers
50.​C. A pre-linked binary code

Compiled by Chisale
10
SECTION B: TRUE/FALSE (51-70)

51.​False
52.​False (modern use is
53.​False
54.​True
55.​False
56.​False (cout is for output, cin is for input)
57.​True
58.​True
59.​False
60.​False
61.​True
62.​True
63.​True
64.​True
65.​False
66.​True
67.​False (= is assignment, == is comparison)
68.​True
69.​True
70.​False (comments are ignored by the compiler, they do not affect execution)

SECTION C: ONE-WORD OR SHORT-ANSWER QUESTIONS (71-100)

71.​main()
72.​=
73.​2
74.​const
75.​\t
76.​x++
77.​+=
78.​1
79.​unsigned
80.​Console Output
81.​3

Compiled by Chisale
11
82.​Compiler
83.​#include
84.​Null statement
85.​%
86.​7
87.​8
88.​float
89.​int (or any other like return, if, while)
90.​//
91.​Hello World!
92.​Moves to a new line
93.​<iostream>
94.​Wraps around to 0
95.​float
96.​Code::Blocks (also acceptable: Visual Studio, Dev C++)
97.​RAM (main memory)
98.​#
99.​American Standard Code for Information Interchange
100.​ 2 (on most 16-bit systems)

Compiled by Chisale
12

You might also like