CS UNIT 2
CS UNIT 2
Below is a complete and self-contained response to your query, providing answers to all the
questions listed under the 1-Mark, 2-Mark, and 3-Mark categories. Each question is clearly stated,
followed by its answer, ensuring the content is concise, informative, and formatted for easy copying
into a Word document.
1-Mark Questions
These are short, straightforward questions requiring brief answers, such as definitions, examples, or
simple identifications.
4. Which header file is used for input and output operations in C++?
The header file iostream.h is used for input and output operations.
2-Mark Questions
These questions require slightly more detailed answers, such as explanations with examples or
comparisons.
cpp
CollapseWrapCopy
#include <iostream.h>
int main() {
return 0;
2. What are header files? Name two header files used in C++.
Header files declare functions and objects for use in programs. Two examples are iostream.h
(I/O operations) and iomanip.h (formatting manipulators).
cpp
CollapseWrapCopy
int x;
cin >> x;
cpp
CollapseWrapCopy
#include <iomanip.h>
cpp
CollapseWrapCopy
float f = 3.14f;
double d = 3.14159;
o Integer: 5
o Character: 'a'
o Floating-point: 3.14
o String: "Hello"
cpp
CollapseWrapCopy
int x = 10;
12. Explain the difference between prefix and postfix increment operators.
CollapseWrapCopy
int x = 5;
13. Describe the logical operators in C++ with their truth tables.
text
CollapseWrapCopy
T && T → T
T && F → F
F && T → F
F && F → F
text
CollapseWrapCopy
T || T → T
T || F → T
F || T → T
F || F → F
text
CollapseWrapCopy
!T → F
!F → T
cpp
CollapseWrapCopy
int x = 5;
cpp
CollapseWrapCopy
int x = 5;
x += 3; // x = x + 3, now 8
cpp
CollapseWrapCopy
3-Mark Questions
These questions demand detailed explanations, often with examples, comparisons, or processes.
3. Describe the use of I/O operators (<< and >>) with examples.
cpp
CollapseWrapCopy
int x;
4. What is the role of the iomanip.h header file? Provide examples of its use.
iomanip.h provides formatting manipulators like setw().
Example:
cpp
CollapseWrapCopy
#include <iomanip.h>
cpp
CollapseWrapCopy
7. Describe the process of declaring and initializing variables of different data types.
Declaration specifies type; initialization assigns a value.
Examples:
cpp
CollapseWrapCopy
int a = 5;
float b = 3.14f;
char c = 'A';
double d = 2.718;
8. What are the rules for naming variables in C++? Provide examples.
o Not a keyword.
Examples:
o Arithmetic: +, e.g., 5 + 3.
cpp
CollapseWrapCopy
cpp
CollapseWrapCopy
float f = 3.14;
int i = (int)f; // 3
12. What are expressions in C++? Provide examples of different types of expressions.
Expressions combine operands and operators:
o Arithmetic: x + y
o Relational: x > y
o Logical: x &&