Loading....
Coupon Accepted Successfully!

 

Question-1

Why do you think C++ was not named ++C?

Solution:
C++ is a super set of language C. All the basic features of C are used in C++ in their original form C++ can be described as C+ some additional features. Therefore, it has followed the rule of use-and-then change. Thus C++ is more appropriate name for it rather than ++C.

Question-2

Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

Solution:
A unary operator requires a single operand. Unary+, unary+, unary–, ++, ––, size of etc., are some unary operators in c++.

A binary operator requires two operands. + (add), – (subtract), *, /, % etc., are some binary operators in C++. A ternary operator requires three operands: (the conditional operator) is a ternary operator in C++.

Question-3

The value of e is known to be 2.71828… Using this value, write a program to determine the value of the expression 2-ye2y + 4y

Solution:
#include<iostream.h>

#include<math.h>

int main()

{

Const double e = 2.71828;

double result , y;

cout<< "enter the value of y";

cin >>y;

result = 2-y * exp(2*y) + Pow(4,y);

cout <<" the result of the given expression is :" << result;

return 0;

}

Question-4

Write a program to find the smallest among the given numbers using relational operator

Solution:
#include<iostream.h>

#include<conio.h>

void main()

{

int a,b,c;

cout << " Enter the value for a,b,c";

cin>>a>>b>>c;

if((a<b) && (a<c))

cout<<"a is smaller"<<a<<endl;

else if ((b< a)&&(b<c))

cout<<" b is smaller"<<b<<endl;

else

cout<<"c is smaller"<<c<<endl;

getch();

}

Question-5

Write a program using condition operator to check the given number is greater or not.

Solution:
#include <iostream.h>

using namespace std;

int main() {

int a= 1, b = 2;

cout << ( a > b ? a : b ) << " is greater." << endl;

}

Question-6

Define Unary operator.

Solution:
Operators that act on one operand are referred to as Unary Operators.

Question-7

What is modular operator?

Solution:
Modulus operator %: The % operator finds the modulus of its first operand relative to the second. That is, it produces the remainder of dividing the first by the second operand. For example,

19 % 6 evaluates to 1, since 6 goes into 19 three times with a remainder 1.

Both operands must be integer types here.

Question-8

Explain relational operator.

Solution:
In the term relational operator, relational refers to the relationships that values (or operands) can have with one another. Thus, the relational operators determine the relation among different operands. C++ provides six relational operators for comparing numbers and characters. But they don’t work with strings. If the comparison is true, the relational expression results into the value 1 and to 0, if the comparison is false. The six relational operators are:

 

<(less than),        <=(less than or equal to),                 == (equal to)

> (greater than),   >= (greater than or equal to) and      != (not equal to)

Table 8.2 summarizes the action of these relational operators.

Question-9

Explain Conditional operator.

Solution:
C++ offers a conditional operator (?:) that stores a value depending upon a condition. This operator is ternary operator i.e., it requires three operands. The general form of conditional operator (?:) is as follow:

Expression1? Expresson2: Expresson3

If expresson1 evaluates to true i.e., 1, then the value of the whole expression is the value of expression2, otherwise, the value of the whole expression is the value of expression3. For instance,

Result = marks>=50? ‘P’ : ‘F’ ;

 

The identifier result will have value ‘P’ if the test expression marks>=50 evaluates to true (1) otherwise result will have value ‘F’. Following are some more examples of conditional operator?:

6>4? 9:7               evaluates to 9 because test expression 6>4 is true.

4==9 ? 10 : 25      evaluates to 25 because test expression 4== 9 is false.

Question-10

Define expression.

Solution:
An expression in C++ is any valid combination of operators, Constants, and variables.

Question-11

Define type casting.

Solution:
The explicit conversion of an operand to a specific type is called type casting.

Question-12

What is type conversion and its types.

Solution:
The process of converting one predefined type into another is called Type conversion. C++ facilitates the type conversion in two forms are implicit and explicit

Question-13

Explain C++ shorthand operators.

Solution:
C++ offers special short hand notation. The operator is used with an equal to symbol (=). The syntax is

 

Variablename1=variable operator expression

 

For example

 

A+=10; // A= A+ 10

 

The other operators are in the given table

 

Operator

Definition

Example

*=

Multiply and equal to

a*=b;

a=a*b;

/=

Divide and equal to

a/=b;

a=a/b;

+=

Add and equal to

a+=b;

a=a+b;

-=

subtract and equal to

a-=b;

a=a-b;

%=

Modulus and equal to

a%=b;

a=a%b;

 

 

Question-14

What are real expressions?

Solution:
Real expressions are combination of arithmetic operators. real constants and/or real variables.

Question-15

What are assignment statements?

Solution:
An assignment statement assigns value to a variable. The general form of an assignment is as shown below:

a= cve ;

Where a is the target variable and cve can either be a constant or variable or an expression.





Test Your Skills Now!
Take a Quiz now
Reviewer Name