Computer Studies
Viva Voce
Class x
1.What is the difference between int and float data types?
Answer:
• int: Used to store integer (whole) values. It does not allow decimal points.
• float: Used to store floating-point numbers (numbers with decimals). It has a
larger range and precision than int.
2 What is the difference between == and = in C++?
Answer:
• ==: The equality operator, used to compare two values.
• =: The assignment operator, used to assign a value to a variable
3.What are loops in C++?
Answer: Loops are used to execute a block of code repeatedly under certain
conditions. The main types of loops in C++ are:
4.What is a pointer in C++?
Answer: A pointer is a variable that stores the memory address of another variable.
Pointers allow direct access and manipulation of memory.
5.What is the difference between ++i and i++?
Answer: ++i: Pre-increment. Increments the value of i first, then uses it in the
expression.
• i++: Post-increment. Uses the value of i first, then increments it.
6.What is an array in C++?
Answer: An array is a collection of elements of the same data type, stored in
contiguous memory locations. It allows you to store multiple values in a single
variable.
7.What is the use of return in C++?
Answer: The return statement is used to exit a function and optionally return a value
to the calling function. If the function is of type void, no value is returned.
8.What is the break statement in C++?
Answer: The break statement is used to exit a loop or switch statement prematurely.
It is commonly used when a certain condition is met and you want to stop the loop
or switch.
9.What is the difference between cin and cout in C++?
Answer: cin is used to take input from the user (standard input stream).
cout is used to display output to the console (standard output stream).
10.What is the purpose of the << operator in C++?
Answer:The << operator is used with cout to send data to the output stream,
effectively displaying it on the
11.What does endl do in C++?
Answer: endl inserts a newline character (\n) and also flushes the output buffer,
ensuring that all output is immediately written to the console.
12.What is the purpose of the cin object in C++?
Answer:The cin object is used to receive input from the user. It reads data from the
standard input (keyboard) and stores it in variables.
13.What does the >> operator do in C++?
Answer: The >> operator is used with cin to extract input from the user. It reads the
data entered by the user and stores it in the provided variable.
14.Can cout print multiple variables in a single statement?
Answer: Yes, you can chain multiple variables and literals in a single cout statement
15 .How can you display a message on the screen in C++?
Answer You use cout to display a message:
16.What is the difference between if and switch statements in C++?
Answer if is used to check conditions and execute code based on a true/false
condition.
• switch is used to choose between multiple options based on the value of a
variable.
17.What does a for loop do in C++? Can you give an example?
Answer. A for loop is used to repeat a block of code a specific number of times.
Example:
• cpp
• Copy
• for (int i = 0; i < 5; i++) {
• cout << i << endl;
18.How does a while loop differ from a do-while loop in C++?
Answer. A while loop checks the condition before executing the loop's body.
• A do-while loop checks the condition after executing the loop's body at least
once.
19.What is a function in C++?
Answer. A function is a block of code that performs a specific task. Functions are
used to avoid repetitive code, improve readability, and modularize programs.
20. How do you define a function in C++?
Answer.You define a function by specifying its return type, name, and parameters.
21.What is the difference between passing by value and passing by reference?
Answwr. Passing by value means passing a copy of the argument to the function.
• Passing by reference means passing the actual argument, and any changes
made to the parameter in the function will affect the argument outside the
function.
22.How can you access an element in an array?
Answer. You can access an element using the index of the array.
23.What are arithmetic operators in C++? Can you give some examples?
Answer.Arithmetic operators are used to perform mathematical operations.
Examples include:
• + (addition)
• - (subtraction)
• * (multiplication)
• / (division)
• % (modulus)
24.What is a syntax error? Can you give an example?
Answer.A syntax error occurs when the code violates the syntax rules of the
language.
25.What is a runtime error?
Answer.A runtime error occurs while the program is running, often due to invalid
operations like division by zero.
26.What is a comment in C++? How do you add comments in the code?
Answer.Comments are used to explain the code. They are ignored by the compiler.
You can add comments using:
• Single-line comments: // This is a comment
• Multi-line comments: /* This is a multi-line comment */
27.What is the role of the #include directive in C++?
Answer .The #include directive is used to include header files in a program. It allows
the use of standard library functions or user-defined files. For example, #include
<iostream> allows the program to use input and output functions like cin and cout.
28. What is the use of the main() function in C++?
Answer.The main() function is the entry point of a C++ program. Execution starts
from the main() function.
29. What is the difference between a local and a global variable in C++?
Answer.A local variable is declared inside a function and can only be accessed
within that function.
• A global variable is declared outside all functions and can be accessed
throughout the program.
30. What is a syntax error and how does it differ from a runtime error?
Answer. A syntax error occurs when the code violates the language's syntax rules
(e.g., missing semicolon, unmatched parentheses).
• A runtime error occurs during program execution, often due to invalid
operations (e.g., division by zero, accessing out-of-bounds array elements).
31. Describe the use of switch statement in C++.
Answer.A switch statement is used to select one of many code blocks to execute
based on the value of an expression.
32. What type of error occurs during program execution?
Answer. runtime
33. What is the default return type of a C++ function?
Answer.int
34. Which data type is used to store a single character in C++?
Answer .char
35. What is used to terminate a loop prematurely in C++?
Answer. break
36. What is used to define a block of code that is executed repeatedly in C++?
Answer. loop
37. What do you understand by volume of cube
Answer. The volume of a cube is the amount of space inside the cube. It is
calculated by raising the length of one side of the cube to the power of three.
38.What is the formula for the volume of a cube
Answer. The formula for the volume of a cube is: Volume=a3
39.What is the formula of percentage?
Answer. The formula for calculating percentage is:
For example, if three subjects have marks of 10, 11, and 12 out of 25, that is,
the maximum score is 25. And out of 25, the student got 10, 11, and 12 in
three subjects. Therefore, his or her percentage mark can be calculated as
follows:
perc = ((10+11+12)/(25*3))*100
= (33/75)*100
= (0.44)*100
= 44
40.Define the functionality of if-else?
Answer.
• if: It checks a condition. If the condition is true, the code block inside the
if statement is executed.
• else: If the condition in the if statement is false, the code block inside the
else statement is executed.
41.What are escape sequences?
Answer. Escape sequences in C++ are special characters that represent certain
actions or formatting that can't be directly typed into the program.