Viva Questions
CHAPTER1 REVIEW OF C++
1.
What
are tokens, identifiers, literals. Pl learn the naming conventions of these.
·
Tokens- Smallest individual unit. Following are the
tokens
·
Keyword-Reserve word having special meaning the
language and can’t be used as
identifier.
·
Identifiers-Names given to any variable, function,
class, union etc. Naming convention (rule) for writing identifier is as under:
o
First
letter of identifier is always alphabet.
o
Reserve
word cannot be taken as identifier name.
o
No
special character in the name of identifier except under score sign ‘_’.
·
Literals-Value of specific data type assign to a
variable or constant. Four type of Literals: i) Integer Literal i.e int
x =10
ii) Floating point Literal i.e float
x=123.45
iii)Character Literal i.e char
x= ‘a’, enclosed in single
quotes and single character only.
iv) String Literal i.e cout<< “Welcome” , anything enclosed in double quotes
·
Operator –
performs some action on data
·
Arithmetic(+,-,*,/,%)
·
Assignment operator (=)
·
Increment
/ Decrement (++, --)
·
Relational/comparison
(<,>,<=,>=,==,!=).
·
Logical(AND(&&),OR(||),NOT(!).
·
Conditional
(? :)
2.
Name
simple, compound and user defined data types.
·
Fundamental
type/simple : Which are not composed any other data type
i.e. int, char, float and void
·
Derived
data type /compound: Which are made up of fundamental data type
i.e array, function, class etc
·
User
defined: they are tailor
made data types created by the user eg structures and classes
3.
What
are macros? How they are implemented in C++?
Macros: These are very simple inline functions which are written
before main().These are on line functions returning very simple calculations eg
area of square circle etc.When the compiler encounter a function call the
function call is replaced by the program code. This ensures faster processing
by removing the overhead required for transferring control to function
definition.
eg
#include
<iostream.h>
#define
area_square(s) s*s
void main()
{
cout<<"Area of square: "<<area_square(4);
}
output:
Area of
square: 16
4.
What
is typedef? How to define another name for string, int, float or char
datatypes?
Used to define new data type name.
e.g. typedef char Str80[80];
Str80 str;
So the new
name for char data type here will be Str80. str is a variable of Str80
having size as 80 char.
eg 2. typedef
int age;
age x;
Here Age is
the new name for int data type . x is a variable having age data type.
5.
How
can you call a variable by two names?
By using alias name
as in reference variables. Eg When we pass a variable by reference in a function,
the same variable has two names, one in the calling function and the other in
the function definition.
Eg
void func1( int & marks)
{ if(marks>90) alias
name
cout<<”V.Good”;
else
Cout<<”Good”;
}
void main()
{ int m;
cout<<”Enter
marks”;
cin>> m;
func1(m);
} actual name
6.
What
are reference variables?
A reference is
an alternative name for an object or variable. A reference variable provides an
alias for a previously defined variable. A reference declaration consists of
base type , an & (ampersand), a reference variable name equated to a
variable name .the general syntax form of declaring a reference variable is as
follows.
Type &
ref_variable = variable_name;
Where
type is any valid C++ datatype, ref_variable is the name of reference variable
that will point to variable denoted by variable_name.
e.g int a= 10;
int
&b= a;
then the value
of a is 10 and the value of b is also 10;
7.
Diff
between ‘’h’’ & ‘h’
Here “h” is a
string having size 2 bytes. ‘h’ is a character constant with size 1 byute.
8.
Diff
between getch ( ) & getche( )
getch() and
getche() both accept a single character from inout stream, getche also shows
the character on the screen( e stands for echo).
9.
Diff
between toupper( ) & isupper( )
toupper()-converts
given character to uppercase
isupper()- returns
true if the character is uppercase else returns false.
10. Diff between if
(i=2) & if(i= =2)
(i=2) : this
assigns value 2 to i
if(i= =2): this checks whether the value of I
is 2 or not and returns true or false accordingly.
11. use of # include
#include is
the preprocessor directive used in C++ programs. This statement tells the
compiler to
include the specified file into the program. This line is compiled by the
processor
before the
compilation of the program.
e.g
#include<iostream.h>
the above line
include the header file iostream into the program for the smooth running of the
program.
12. What is typecasting?
Type
Casting
Explicit
type casting operator
Type casting
operators allow you to convert the data type of a given variable to another.
There are several ways to do this
1.To precede
the expression to be converted by the new type enclosed between
parentheses ( ) :
int i;
float f =3.14;
i = ( int ) f;
The previous
code converts the float number 3.14 to an integer value (3), the remainder is
lost. Here, the typecasting operator was (int).
2. Another way
to do the same thing in C++ is using the functional notation: preceding the
expression to be converted by the type and enclosing the expression between
parentheses:
i = int
(f );
Both ways of
type casting are valid in C++.
Implicit conversions are automatically performed when a value is
copied to a compatible type. For example:
Char ch=’A’;
Int b=ch;
Here, the value of ch is promoted from char to int without the need of any explicit operator.
13. Compilation and Linking
Compilation
refers to the processing of source code files (.c, .cc, or .cpp) and the
creation of
an 'object'
file. This step doesn't create anything the user can actually run. Instead, the
compiler
merely produces the machine language instructions that correspond to the source
code file that
was compiled. For instance, if you compile (but don't link) three separate
files,
you will have
three object files created as output, each with the name <filename>.o or
<filename>.obj
(the extension will depend on your compiler). Each of these files contains a
translation of
your source code file into a machine language file -- but you can't run them
yet!
You need to
turn them into executables your operating system can use. That's where the
linker comes
in.
Linking refers
to the creation of a single executable file from multiple object files. In this
step,
it is common
that the linker will complain about undefined functions (commonly, main
itself).
During
compilation, if the compiler could not find the definition for a particular
function, it
would just
assume that the function was defined in another file. If this isn't the case,
there's no
way the
compiler would know -- it doesn't look at the contents of more than one file at
a time.
The linker, on
the other hand, may look at multiple files and try to find references for the
functions that
weren't mentioned.
14. Diff between
local(automatic) & global variables.
The lifetime and
scope of local variables is the function or block in which they are declared.
The lifetime and
scope of global variables is the program in which they are declared.
15. How many cases are
possible in a select case?
256, range of char.
16. What is difference
between actual and formal parameters?
Actual Parameters :Variables associated with function name
during function call statement.
Formal Parameters:Variables which contains copy of actual
parameters inside the function definition.
17. What do you mean by
entry controlled and exit controlled loop?
Entry control loop works for true condition and
preferred for fixed no.of times.eg for, while
Exit Control Loop execute at least once if the condition
is false at beginning.eg do while
18. Difference between
signed and unsigned.
The range of signed
data type is lower than unsigned as one byte is reserved to store the sign(-,
+)
Eg
For char datatype.
1byte
signed: -128 to 127
unsigned: 0 to 255
19. What do you
understand by .h in header file declarations?
.h stands for
header files , an extension given to these type of files.
20. Why do we use
comments? Declare a single line comment and a multi line comment.
Comments are
the line that compiler ignores to compile or execute. There are two types of
comments in C++.
1.
..Single line
comment: This type of comment deactivates only that line where comment is
applied.
Single line comments are applied with the help of “ //” .
e.g //
cout<<tomorrow is holiday
the above line
is proceeding with // so compiler wont access this line.
2. Multi line
Comment : This Type of comment deactivates group of lines when applied. This
type of comments are applied with the help of the operators “/*” and “*/ ”.
These comment mark with /*
and end up
with */. This means every thing that falls between /*and */ is considered even
though it
is spread
across many lines.
e.g
#include<iostream.h>
int main
()
{
cout<<
“ hello world”;
/* this is the
program to print hello world
For
demonstration of comments */
}
In the above
program the statements between /* and */ will be ignored by the compiler.
21. Why do we use iostream.h?
To be able to
connect the program to the input and output stream.
22. What is the
difference between gets() and getline()?
Gets():It reads up to the '\n' and leaves it in the stream This
effectively prevents any further stream processing until the '\n' is cleared
with clear() or possibly ignore().
Getline(): It reads up to the '\n' and then discards it.
What type of
function is main()- user defined or in-built?
in-built
23. What happens during
running
During running .exe
and .bak files are created and the program is loaded in the ram.
24. Diff. between
continue & break & exit
exit()- defined in process.h and used to terminate the program
depending upon certain condition.
break- exit from the current loop depending upon certain condition.
continue- to skip the remaining statements of the
current loop and passes control to the next loop control statement.
25. What are default
arguments?
26. Function Prototype Function Defintion
Function Header with list of parameters
passed , return type mentioned , ended with a ; Must match with Function header
of defined body.
Function definition :Function containing
body/statements to be executed.
27.
Compile Time Errors: Syntax errors occurs
at compile time.
Run Time Errors: Logical
Errors occurs at Run Time
28.
Switch Case : Only used with char / int,
Only used for equality comparison
29.
If..else:Can be used with all data types,
Mix expressions can be evaluated.
30.
What is preprocessor directive?
The preprocessor is
used to modify your program according to the preprocessor directives in your
source code. Preprocessor directives (such as #define) give the preprocessor
specific instructions on how to modify your source code. The preprocessor reads
in all of your include files and the source code you are compiling and creates
a preprocessed version of your source code. This preprocessed version has all
of its macros and constant symbols replaced by their corresponding code and
value assignments. If your source code contains any conditional preprocessor
directives (such as #if), the preprocessor evaluates the condition and modifies
your source code accordingly. The preprocessor contains many features that are
powerful to use, such as creating macros, performing conditional compilation,
inserting predefined environment variables into your code, and turning compiler
features on and off. For the professional programmer, in-depth knowledge of the
features efficient programs.
Comments
Post a Comment