Sheet 1 Model Answer
Sheet 1 Model Answer
Sheet1
1. Answer in brief.
a. Why does the inclusion of the line "#include <iostream>" important in C++
programs that perform input or output?
Answer: The line "#include <iostream>" is important in C++ programs that perform
input or output because it tells the compiler to include the necessary service for stream
input/output. The iostream library provides functionality for reading input from the user
and displaying output on the screen.
b. What does the line "using namespace std;" indicate in a C++ program, and why
is it commonly used?
Answer: The line "using namespace std;" indicates that the program will use the
standard namespace. Namespaces are used to avoid naming conflicts in large programs.
By using the standard namespace, we can access the standard library (std) without
explicitly specifying it for each identifier. It is commonly used to simplify the code and
make it more readable.
c. What is the significance of the "int main ()" function in a C++ program?
Answer: The "int main ()" function is the entry point of a C++ program. It is where the
program execution starts. The "int" indicates that the function will return an integer
value, and "main" is the name of the function. Any code inside the curly braces of the
main function will be executed when the program runs.
e. What is the purpose of the "return 0;" statement in the main function of a C++
program?
Answer: The "return 0;" statement in the main function of a C++ program indicates
that the program finished successfully. It is a convention to return 0 to denote
successful execution. Other return values can indicate different error codes or statuses.
1
2. Fill in the blanks.
1. In C++, everything is __case_____ sensitive.
2. A ___statement____ is a unit of code that does something and is a basic
building block of a program.
3. An ___expression____ is a statement that has a value, such as a number, a
string, or the sum of two numbers.
4. The ___%____ operator takes the remainder of two numbers.
5. The five arithmetic operators in C++ are __+_, __-_, _*___, ___/__, and ___
%__.
6. The operator % is used to find the remainder in ___ordinary_____ division.
3. Select the appropriate option.
1. Which category of data types is the fundamental building block for
structured data types?
a) Simple data type b) Structured data type
c) Pointers d) None of the above
Answer: c) char
Answer: c) 4 bytes
Answer: c) bool
5. What is the range of values that can be represented by the "unsigned int"
data type?
a) -128 to 127 b) -32768 to 32767
2
c) 0 to 255 d) 0 to 4294967295
Answer: d) 0 to 4294967295
Answer: b) double
7. How many bytes of memory does the "bool" data type occupy?
a) 1 byte b) 2 bytes
c) 4 bytes d) 8 bytes
Answer: a) 1 byte
Answer: c) 3
Answer: a) =
11. What is the preferred way to declare and initialize a variable in a single
statement?
a) int x b) x = 4 + 2
c) int x = 4 + 2 d) initialize (x, 4 + 2)
Answer: c) int x = 4 + 2
3
12. Which characters are allowed in variable names?
a) Letters, numbers, and underscores b) Symbols such as $ or %
c) Spaces d) Capital letters only
Answer: a) //
4
5