Coupon Accepted Successfully!



What are data types? What are all predefined types in data c++?

Data types are the means to identify the type of data and associated operations of handling it. C++ offers two types of data types


1. Fundamental data types: These are the data types that are not composed of any other data type. There are five fundamental data types: char, int, float, double and void.


2. Derived data types: These are data types that are composed of fundamental data types. They are: array, function, pointer, reference, constant, class, structure, union and enumeration.


The four integer data types are: char, short, int, long.


What are the advantages and disadvantages of floating point numbers over integers?

Advantages: 1. The values in between two integers can easily be represented. For example, all possible values between 1 and 2 such as 1.2, 1.313 etc., can be represented. Much larger range of values can be represented using floating-point numbers.



Disadvantages: 1. Floating point operations are slower than integer operations.


What are data type modifiers? How do they affect a base data type?

The key words which, when appear before a data type, change its meaning are modifiers. These are signed, unsigned, short and long.


When the data type modifiers appear before a data type, the meaning of the data type is changed in the sense that its size is affected thereby affecting minimal range of values the data type can represent. For instance, an int is by default 2 bytes long and hence can represent values –32768 to 32767 but when unsigned modifier appears before it, its range becomes 0 to 65,535. Similarly, if the long modifier is used, the range becomes -2,147,483,648 to 2,147,483,647.


Write definition for a class employee that can hold information like employee no., name, desig, dept, basic salary and have associated operations for printing pay slips, modifying as employee’s details, printing an employee’s work report.

Class employee

{         int emp_no;

          char name[25]

          char design[15], dept[10]

          float basic;

          payslip ();

          modify ();

          prnreport( );



A class can represent data elements as well as their associated functions that manipulate them whereas a structure can only represent the data elements. It has no control over the associated functions of data.


Consider the following two C++ statements. Are they equivalent?

char grade = 65;
char grade = ‘A’;


Yes, both these statements are equivalent as ASCII value of ‘A’ is 65 and it is 65 only that will be stored in the memory. Thus grade =65 or grade=’A’ mean the same thing.


What is the difference between 25L and 25?

An I or L suffix indicates it is long integer constant. Thus, 25L is a long integer constant and 25 is an integer constant.


What is a reference variable? What is its usage?

A reference variable is an alias name for a previously defined variable. The usage of it is that the same data object can be referred to by two names and these names can be used interchangeably.


What is modifier const?

This keyword before a variable’s definition, it modifies its access type i.e., the access of the constant variable is readable only; it can no more be written on to. For instance,

int val = 10;

Declares a variable val with initial Value 10. However, the value of val can be changed in the program at any time. But, if we modify the above definition of variable as follows:

const int val = 10;

The Variable val becomes constant and its value remains 10 throughout the program, it can never be changed during program run, Thus the keyword const becomes an access modifier for variables.


Explain Union.

A union as a memory location that is shared by two or more different variables, generally of different types at different times. Defining a union is similar to defining a structure. Following declaration declares a union share having two variables (integer and character type) and creates a union object cnvt of union type share:


Union share {

int i ;

char ch;



Union share cnvt;


The keyword union is used for declaring and creating a union. In the union cnvt, both integer i and character ch share the same memory location.


What is setprecision () manipulator?

The setprecision () manipulator sets the total number of digits to be displayed When floating point numbers are printed. For example, the code:

cout << setprecision (5) << 123.456;


How will you declare a variable?

The declaration of a variable generally takes the following type name;

Where type is any C++ data type and name is the name of the variable. A variable name is an identifier. Thus all rules of identifier naming apply to the name of a variable. Following declaration creates a variable age of int type:

int age ;


An signed int (size 2 bytes) can represent 0 to 65,535 i.e., 65,536 values in total whereas a signed int can represent – 32768 to 32767 i.e., 65,536 values in total. The total numbers represented by both (signed and unsigned) integers are the same, however, the highest number represented by unsigned int becomes double because in place of negative values, new positive values are represented thereby increasing the range by 32768 numbers as there are these many negative values represented by signed int. Thus, when signed int can represent max 32767, then unsigned int can represent max 65535 which is twice as large as the signed int.

Test Your Skills Now!
Take a Quiz now
Reviewer Name