CS201 Important Questions Answers for VIVA Preparation
CS201 Important VIVA Questions that are Most Frequenly Asked
CS201 Important Questions for VIVA Preparation
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 the data members?
The
data members, functions and nested classes are called class
members.
4.
What is the class layout?
The way in which data class members are arranged in a class object is
called class
layout.
5.
What is the class template?
The template is used for generating class types.
6.
What is the comment in Programing 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?
The constructor initializes the data member of an object in the scope. It
has no return type and has the same name as the class. We use many types
of constructors by overloading them.
Types
of constructor:
Default
constructor/compiler-generated constructor
Simple
constructor (takes no arguments)
Parameterized
constructor (takes arguments)
Constructor
overloading
Copy
constructor
8.
What is a 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.
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 C-out?
If
we want to print something on the screen we use Cout (Output stream)
for this purpose.
cs201 viva questions and answers
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 the 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 sizes in memory.
13.Operators:
Assignment
operator :
“ =
”is
used to assign a value to a specific location.
Compound
assignment operators:
“+=”
“-=”
“*=”
“/=”
“%=”
Modulus
Operator:
“%”
is
used to get the remainder. (For division)
Relational
Operators:
“<,
=, >”
used
for decision making (in if
statement)
“>”
greater
than
“==”
equal
to
“<”
less
than
“>=”
greater
than or equal to
“<=”
less
than or equal to
not equal to
Logical
Operators:
(These
are binary operators and take two operands)
“&&”
AND
operator
“||”
OR
operator
“!”
Logical
Negation
Increment
and decrement operator:
“++” The increment operator (unary operator) that increase the value of its
operator by 1.
“-
-(with no space between)“ decrement operator that decrease the
value by 1.
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
the statement” it also called a 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 the team
16.
What is “if/else
statement structure?
If(condition){
statement(s);
}else{
Statement(s);
}
17.
When we use a switch statement?
The
switch structure is a multiple-selection construct that is used in
multi-way decisions to make the code more efficient and easy to
understand. The multi decision means a condition where we have to use if
else statement again and again so for ease to access we use the switch
statement.
In
switch statement there should be an integer variable or an expression
that must evaluate an integer type. We can‟t use compound
conditions (conditions that use logical operators “&&, ||”
in the switch statements).
The
break statement interrupts the flow of control. In the switch statement, all statements are executed. But we want that only statements of the true
case should be executed and remaining should be skipped. For this
purpose, we use the break
statements.
Syntax
of switch and break statement:
switch(variable/expression){
case
constant1:
statement
1;
break;
case
constant2:
statement2;
break;
……………………………………
case
constantN:
statmentN;
break;
default:
statement;
}
19.
What is the purpose of “continue”
statement?
Continue the statement is related to the loop. When we have a lot of code in the body of the loop and we need some code to be executed every time and some code in
certain cases. For this purpose, we use continue statements
.
It one-line statement like a 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 a set of instructions under some conditions.
The syntax of while construct is:
while(logical
expression){
statement
1;
statement
2;
statement
3;
…………
}
Mostly asked question in viva cs201
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 execute zero or more
times.
In
“do-while
loop”
condition is tested after the execution of 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 we do in the loop?
There
are three things we do in a loop:
- Initialize a variable.
- A continuation / termination condition
- Changing the value of the condition variable, usually the increment of the variable value.
The
syntax of for
loop:
for(initialize
condition; continuation condition; incrementing condition)
{
statement(s);
}
23.
What are the 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 does not return a value.
Structure
of Functions:
Structure
of function
|
Example
|
return-data-type
function-name(argument-
|
int
square(int number){
list){
int
result = 0;
declarations
and statements
result
= number*number;
}
return
result;
}
Functions
which don‟treturnany value
use the keyword “void
”
instead of return-data-type. The default data type of functions is
int.
24.
What is the calling methodology of a function?
The
calling program just needs to write the function name and provide its
arguments without data types.
25.
What is the difference between declaration and definition of a
function? Declaration
and definition are both different things. The declaration is a prototype
of
the function, that includes the return type, name, and argument list
to the function and definition
is the actual function code.
Declaration
|
Definition
|
Int
square (int)
|
Int
square(int number){
|
Return
(number * number);
|
|
}
|
26.
What is the difference between “call
by value
”
and “call
by reference”?
Call
by Value:
In
call
by value
we pass a copy of the arguments instead of the 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 the original variable. And use
original variable.
27.
What is an array?
Array
is a special data type. Arrays can be used to store a collection of
data of the same data type. Every array has a data type name and size.
Arrays start from index 0.
Declaration:
Data-type array-name[size];
For
example:
Int
ages[10];
We
can initialize an array using “loop”
while assigning some value.
28.
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 with this situation. It can
be used for any data type and is written before the data type as:
const
int arrays = 100
;
Whenever
we use the word keyword const the value of that variable becomes
constant and no other value can be assigned to it later on.
29.
How we can manipulate arrays?
We
can manipulate arrays using loops.
30. What
are pointers?
Pointers
are a special type of variable 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.
Data
type *name;
For
example
int
*myptr;
One
of the major usages of pointers is to simulate call by reference
while using it with function calls. In the calling function, we pass
the address of the variable to a function being called by using &
operator
.
Mostly asked question in viva cs201
31.
What is bubble sort?
It
is a technique of comparing two values and interchanging the larger
and smaller values. To interchange the position of larger and smaller
values, the technique of swapping
is used.
32.
What is the relationship between pointers and arrays?
The
name of an array is a constant pointer which contains the memory address
of the first element of the array.
33.
What is the role of a backslash (\) in C and C++?
Whenever
a back
slash (\)
is used, the compiler considers both the characters as a single (also
known as escape characters).
“\n”
for
new line
“\t”
for
tab
“\0”
null
34.
What do you know about <ctype.h>
?
C the language provides any functions to perform useful tests and
manipulations of character data. These functions are found in the
header file <ctype.h>
.
35.
What do you know about <stdlib.h>
?
The
header file stdlib.h
includes functions, used for different conversions. These conversion
functions take an argument of a type and return it after converting it into another type.
36.
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>.
37.
What is the structure?
“A the 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 keyword
struct
.
(Keyword “struct”
cannot be used as a variable.)
38.
What is the 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.
Static memory runs
essentially
on stack.
We
use this type of allocation when we know how much memory is required.
39.
What is dynamic memory allocation?
Instead
of allocating static memory within code, we can ask how much memory
is required to allocate. And allocate memory at runtime
(dynamically). This type of memory allocation is used when we don‟t
know how much memory exactly we required. The dynamic memory
allocation use memory from the heap.
40.
Which functions are used for memory allocation in C?
“calloc()”,
“malloc()”
and
“realloc()”
functions
are used for memory
allocation
in C.
Mostly asked question in viva cs201
41.
For which purpose Function “free()”
is used?
The
memory allocated is no longer in use, we use free()
function to free that memory and make it a part of the heap again.
42.
How memory allocated in C++?
The
memory allocation in C++ is carried out with the use of an operator
called “new
operator”,
and deallocated with the “delete
operator”.
That memory returned back to the free store. Whenever we use “new
operator”
to allocate memory, it will be necessary to use “delete
operator”
to deallocate the memory.
43.
What is a dangling pointer?
The
pointer points to no memory location are called dangling pointer.
It
has an inverse effect of memory leak. A pointer was pointing to a chunk
of memory, now by some reason, that memory has deallocated and has
gone back to the heap. The pointer still has the starting address of that
chunk. Now pointer is pointing to a memory that no longer belongs to
the program and gone back to the heap.
44.
Define static variable also explain life time of static variable?
Static
variable means maintaining the state of a variable. It exists and
lives
around
even when we are outside the function. It is created and initialized
only once during the lifetime of the program and therefore it will be
destroyed or taken out of memory only once during the lifetime of the
program.
45.
What is the difference between pointers and variables?
Normal
variable
contains the value of variable either int
or float
whereas pointer
variable contains
the address of another variable.
46.
How many types of templates?
There
are two different types of templates in C++ language i.e.‟ function
templates and class templates.
A a program that writes the output data to the disc, it will be nice to
collect the output data (numbers) and write it on the disc in one
write operation instead of writing the numbers one by one. The area
where we gather the numbers is known as a buffer.
48.
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.
49.
What is the keyword „this‟ and what are the uses of „this‟
pointer?
'This'
is
used to refer the current class member without using the name of the
class.
We cannot use it as a variable name. „this’
the pointer is present in the function, referring to the calling object.
“this” the pointer points to the current object.
0 Comments