Question-1
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
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
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
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
Solution:
#include <iostream.h>
using namespace std;
int main() {
int a= 1, b = 2;
cout << ( a > b ? a : b ) << " is greater." << endl;
}
Question-6
Solution:
Operators that act on one operand are referred to as Unary Operators.
Question-7
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
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
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
Solution:
An expression in C++ is any valid combination of operators, Constants, and variables.
Question-11
Solution:
The explicit conversion of an operand to a specific type is called type casting.
Question-12
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
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
Solution:
Real expressions are combination of arithmetic operators. real constants and/or real variables.
Question-15
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.