In how many ways can a variable be declared in C++?

Q11. In how many ways can a variable be declared in C++?

Ans. In C++, a variable can be declared in 3 ways:

  1. Uninitialized variable, for example, int val;
  2. Initialized variable, for example, int val=10;
  3. Dynamically initialized variable, for example,

Int val = (b*c)-p;

Variables and how many values are associated.

Q10. What is a variable? How many values are associated with it?

Ans. A variable is a named storage location that can hold any data value. A variable has two associated values:

  1. rvalue which is its data value that is, its contents.
  2. lvalue which is its location value that is, memory address.

How is a structure different from a class?

Q9. How is a structure different from a class?

Ans. 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.

How is structure different from an array?

Q8. How is structure different from an array?

Ans. An array can hold multiple elements of same data type whereas a structure can hold multiple elements of different data types.

The component element of an array is referenced by the array name and the index value, for example, NAME[3], FILE[7] etc. On the other hand, the component element of a structure is referenced by the structure name and the element name for example, style.main, check.value etc.

Class definition of employee.

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


char employee


int emp_no;

char name[25];

char design[15],dept[10];

float basic; Read More …

Reference Variable.

Q6. What is a reference variable? What is its usage?

Ans. 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.

Data type modifiers and How they affect a base data type.

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

Ans. The keywords which, when appears 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 and 32767 Read More …

Advantages and Disadvantages of floating-point numbers over integers.

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

Ans. 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. be represented.
  2. Much larger range of values can be represented using floating-point numbers.


Floating-point operations are slower than integer operations.