0% found this document useful (0 votes)
22 views

Assignment! chap3 (2)

The document consists of short answer and multiple-choice questions related to C++ programming, covering topics such as program structure, variable declaration, data types, operators, and input/output functions. It includes explanations of concepts like constants, comments, type casting, and escape sequences, along with examples. Additionally, it presents multiple-choice questions to test knowledge on C++ syntax and functionality.

Uploaded by

Talal shafiq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment! chap3 (2)

The document consists of short answer and multiple-choice questions related to C++ programming, covering topics such as program structure, variable declaration, data types, operators, and input/output functions. It includes explanations of concepts like constants, comments, type casting, and escape sequences, along with examples. Additionally, it presents multiple-choice questions to test knowledge on C++ syntax and functionality.

Uploaded by

Talal shafiq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Short Answer Questions:

1. Describe the structure of a C++ program.


2. What is the use of a statement terminator in C++?
3. Explain the purpose of comments in C++. Provide examples of both single-line and multi-line
comments.
4. Differentiate between constants and variables in C++.
5. What are the rules for specifying variable names in C++?
6. List any four data types used in C++ and provide an example of each.
7. Define the const qualifier and explain its purpose.
8. How do you declare and initialize a variable in C++? Provide an example.
9. Explain type casting with an example.
10. What is the purpose of the cout statement in C++? Provide an example.
11. How is the cin statement used to take input in a C++ program? Provide an example.
12. Define the functions getch(), gets(), and puts() in C++.
13. What is an escape sequence? Give two examples.
14. How are the manipulators endl and setw used in C++? Provide examples.
15. Define unary, binary, and ternary operators in C++ with examples.

Multiple-Choice Questions (MCQs):


Which of the following is used to terminate a statement in C++?
A) :
B) ;
C) .
D) ,

Which symbol is used for single-line comments in C++?


A) /*
B) //
C) #
D) %%

Which of the following is not a valid variable name in C++?


A) my_var
B) 1var
C) _var1
D) myVar123

Which of the following is a constant keyword in C++?


A) variable
B) int
C) const
D) float

What will be the output of the following code?

int a = 10;
cout << a;
A) 10
B) a
C) Error
D) 0

What does endl do in a C++ program?


A) Terminates the program
B) Prints a blank line
C) Inserts a new line
D) Ends an input statement

Which of the following is not a valid escape sequence in C++?


A) \t
B) \n
C) \b
D) \x

What is the result of the following code?


int x = 5;
cout << x++;
A) 6
B) 5
C) 0
D) Error

Which operator is used for multiplication in C++?


A) /
B) *
C) &
D) %

The cin statement in C++ is used to:


A) Display output
B) Take input
C) Declare variables
D) Terminate a program

Which of the following is a unary operator?


A) ++
B) +
C) =
D) ?:

What does the function getch() do in C++?


A) Reads a single character input without displaying it on the screen
B) Reads a string of characters
C) Outputs a character
D) Pauses program execution

Which of the following statements is true about type casting in C++?


A) It converts one data type into another
B) It declares variables as constants
C) It changes variable names
D) It terminates loops

What does the function puts() do?


A) Takes input
B) Displays a string
C) Declares a string variable
D) Clears the console
Which of the following data types is used to store characters in C++?
A) int
B) float
C) char
D) double

What is the purpose of the setw() manipulator in C++?


A) Set the width of the output field
B) End the output statement
C) Set precision of floating-point numbers
D) Clear output buffer

Which operator is a ternary operator in C++?


A) +
B) ? :
C) =
D) &&

What does const keyword do in C++?


A) Makes a variable mutable
B) Makes a variable constant
C) Declares a variable as floating-point
D) Initializes a variable with zero

Which of the following functions reads a string input in C++?


A) getch()
B) puts()
C) gets()
D) cin.get()

What does the escape sequence \\ represent in C++?


A) Backslash
B) Forward slash
C) Tab
D) Space

You might also like