Best Collection for CS201 VIVA
1. What is a program?
A program is a precise sequence of steps to solve a particular problem.
2. What is a class?
We write a C++ program using data members, and functions. We call this program
“class”.
3. What are data members?
The data members, functions and nested classes are called class members.
4. What is class layout?
The way in which data class members are arranged in a class object is called class
layout.
5. What is class template?
A template is used for generating class types.
6. What is comment in Programming language?
Comments are used to explain the functioning of the programs. It helps to
understand the code. C style of commenting is /*……..*/ also used in C++. And
new line oriented C++ style is //………
7. What is a constructor?
A constructor initializes the data member of an object in the scope. It has no return
type, and has the same name as class. We use many types of constructor by
overloading them.
8. What is destructor?
A function called when a class object goes out of scope. It cleans up the object,
freeing resources like dynamic storage. The name of the destructor is the same as
that of a class with preceding tilde sign (~). It could not be overloaded. It has no
return type, and takes no argument
9. Define #include?
The #include directive instructs the preprocessor to read and include a file into a
source code file. The file name is typically enclosed with if the file is a system
provided file, or in quotes “….” if the file is user provided.
10. For which purpose we use Cout and Cin?
If we want to print something on the screen we use cout (<<) for this purpose. And
we enter a value in system or assign a value to any variable we use Cin (>>)
11. What are Variables?
Variables are locations in memory for storing data. We call them variables because
they can contain different values at different times. The variable name in C may be
started with a character or an underscore ( _ ).But in C++ we did not use
underscore _ . In a program every variable has:
Name
Type
Size
Value
12. What are data types?
A variable must have a data type associated with it. It can have data types like
integers, decimal numbers, characters etc. Different data types have different size
in memory.
13. Types of Operators:
1. Assignment operator: “ = ” is used to assign a value to a specific location.
2. Compound assignment operators: “+=” “-=” “*=” “/=” “%=”
3. Modulus Operator: “%” is used to get the remainder. (For division)
4. Relational Operators: “” used for decision making (in if statement) “>”
greater than “==” equal to “=” greater than or equal to “<=” less than or
equal to
5. Logical Operators: (These are binary operators and take two operands)
“&&” AND operator “||” OR operator “!” Logical Negation
6. Increment and decrement operator: “++” Increment operator (unary
operator) that increases the value of its operator by 1. “- - (with no space
between)“ decrement operator that decrease the value by 1.
7. Address operator: “&” to get the address of a memory location.
14. What is operator overloading?
Operator overloading is to allow the same operator to be bound to more than one
implementation, depending on the types of the operands.
15. What is if statement?
The statement used for decision in “C” language is known as the “if statement” it
also called conditional statement. It has a simple structure: If (condition) Statement
(or group of statements)
For example: If(Ali’s height is greater than six feet) Ali can be a member of team
16. What is “if/else statement structure?
If (condition){
statement(s);
}Else{
Statement(s);
}
18. What is break statement?
The break statement interrupts the flow of control. In switch statement all
statements are executed. But we want that only statements of true case should be
executed and remaining should be skipped.
19. What is the purpose of “continue” statement?
Continue statement is related to loop. When we have lot of code in the body of
loop and we need some code to be executed every time and some code in certain
cases. For this purpose we use continue statement. It one line statement like break
statement.
continue;
The statements of the loop body after continue are not executed. And loop starts
from the next iteration when a continue statement is encountered in the body of the
loop.
20. When will be used “while” Loop?
“While” means “do it until the condition is true”. Use of “while” construct can be
helpful in repeating of a set of instructions under some condition.
The syntax of while construct is:
While (logical expression){
Statement 1;
Statement 2;
Statement 3;
…………
}
21. What is the difference between “while” and “do-while loop”?
In “while loop” the condition is tested first and the statement in the body executed
only when the condition is true, the loop can executed zero or more times.
In “do-while loop” condition is tested after execution the statement of the loop
body. Thus, the loop body executed at least once and then the condition in do while
stamen is tested.
Syntax of do while Loop:
do{
statement(s);
}
while(condition);
22. What are functions?
Functions are like subtasks. They receive some information, do some process and
provide a result.
There are two categories of function:
Functions that returns a value
Functions that do not return a value
23. What is the difference between “call by value” and “call by reference”?
Call by Value:
Call by value
We pass a copy of arguments instead of original variables. The copy reaches to the
function that uses it and returns it back to the calling function. (C language use call
by value by default).
Call by Reference:
In call by reference we pass the reference of original variable. And use original
variable.
24. What is array?
Array is a special data type. Arrays can be used to store a collection of data of
same data type. Every array has a data type name and size. Arrays start from index
Index Always start from zero
25. Define keyword “const”.
The keyword “const” is the construct. If we want to change the size of an array
suppose from 10 to 100 we can use this keyword to deal this situation. It can be
used for any data type and is written before the data type as:
const int arraySize = 100;
Whenever we use the word key word const the value of that variable becomes
constant and no other value can be assigned to it later on.
26. What are pointers?
Pointers are a special type of variables in which a memory address is stored. (They
contain memory address not the value of the variable). Pointers works by pointing
to a particular data type i.e. Int, char, double, float etc.
27. What is the relationship between pointers and arrays?
The name of array is a constant pointer which contains the memory address of the
first element of the array.
28. What is the role of a back slash (\) in C and C++?
Whenever a back slash (\) is used, the compilers consider both the characters as
single (also known as escape characters).
“\n” for new line
“\t” for tab
“\0” null
29. Which header file we use for file handling in our programs?
Whenever using files in our programs, we will include this header file <fstream.h>
30. What is a structure?
“A structure is a collection of variables under a single name. These variables can
be of different types, and each has a name that is used to select it from the
structure”. It is defined with the key word struct.
(Keyword “struct” cannot be used as variable.)
31. What is static memory allocation?
When we write the things like int i, j, k these will reserve three integers in memory.
Similarly the typing of char s[20] will result in the allocation of space for
20characters in the memory. This type of memory allocation is called static
allocation. It is also called compile time allocation.
32. Which functions are used for memory allocation in C?
“calloc()”, “malloc()” and “realloc()” functions are used for memory allocation in
C.
33. What is different between pointers and variable?
Normal variable contains the value of variable either Int or float whereas pointer
variable contains the address of another variable.
34. What is function overloading?
In function overloading, the functions have the same name but differ either by the
number of arguments or the type of the arguments.
35. System Software
The system software controls the computer. It communicates with computer’s
hardware (key board, mouse, modem, sound card etc) and controls different
aspects of operations. Sub categories of system software are:
1. Operating system
2. Device drivers
3. Utilities
Editor:
We use editor to write our code
Compiler and Interpreter
Both are translator. These translators translate our program which is written in C Language
into Machine language. Interpreters translates the program line by line
meaning it reads one line of program and translates it, then it reads second line,
translate it and so on
The Compiler read the whole program and translates it into machine language
completely. The difference between interpreter and compiler is that compiler will
stop translating if it finds an error and there will be no executable code generated
whereas Interpreter will execute all the lines before error and will stop at the line
which contains the error.
Debugger:
Debugger is used to debug the program i.e. to correct the logical errors. Using
debugger we can control our program while it is running.
Loader:
Loader loads the program into memory and then instructs the processor to start the
execution of the program from the first instruction