CBSE Guess > Papers > Important Questions > Class XI > 2013 > Computer Science > Computer Science By Mr. Prabhuji Gupta
CBSE CLASS XI
Operator and Expressions in C++
Most Important Questions
Q 1 Why do you think C++ wasn’t named ++C?
Q 2 What does the modulo operator % do? What is the result of the expression 22.6%5.2 ?
Q 3 Given the following two definitions:
Unsigned int x1=0, x2=0;
What will be the result of each of the following expressions?
(a) x1 && x2
(b) x1 || x2
(c) ! x1
(d) !! x2
Q 4 Why should we avoid equality comparisons between floating point numbers?
Q 5 What is the value of expression ! (1 &&0 || !1).
Q 6 Why should we avoid comparing signed and unsigned values?
Q 7 State the reason why the code given below is illegal. And how can we correct it?
main()
{
int i=j=k=0;
}
Q 8 Evaluate x+=x++ + ++x if, initially x=15.
Q 9 Given the following code fragment
int marks=25;
cout << ++marks <<”n”;
cout << marks<<”n”;
(i) What output does the above code fragment produce?
(ii) What is the effect of replacing ++marks with marks++?
(iii) What is the effect of replacing ++marks with marks+1?
Q 10 What will be the result of expression : result>70?400:500 if
(i) result=35
(ii) result=100
Q 11 What will be the output of the code segment given below:
int a = 200, b=7;
cout << a/b << endl;
Q 12 If initially, the value of name =100, then what will be the output of the code given below:-
cout << name -- ; cout << ++ name ;
Q 13 What will be the result of the following expressions, if initial value of I = 20?
1) ++I<=20 2) I++<=20
Q 14 State the reason why the code given below is illegal.
main()
{
int x, y;
int *ipr;
x=y=ipr=10;
}
Q 15 Construct logical expressions to represent the following conditions:
(a) exp is a lowercase letter
(b) Marks is in the range 400-500 or grade is ‘A’
(c) Grade is ‘B’ and experience is more than 5 years.
Q 16 The following code segment is not producing the expected result. Find the error, if any, in the following code segment:
int x= -10;
unsigned y= 354576;
cout<< ”x < y= “ << x <<="" “n”;
Q 17 The following code segment is not producing the expected result. Correct the error, if any, in the following code segment:
int x= -10;
unsigned y= 354576;
cout<< ”x< y= “ << x <<="" “n”;
Q 18 Write a statement that uses a conditional operator to set grade =’A’, if marks is more than 70 and B otherwise.
Q 19 Given the two expressions
marks=10
marks==10
What is the difference between the two expressions?
Q 20 In the following code:
int func=3;
cout << “ func is equal to“ << func==10 << “ n” ;
(i) What will be the output of the above code?
(ii) What is the effect of replacing func==10 with func=10 ?
Q 21 Suppose a and b are two type double variables that we want to add as integers and assign to an integer variable. Construct a C++ statement for doing so?
Q 22 Given the following set of declarations :
char ch;
int i, j, k;
float a, b, c;
double p,q;
Which of the following are valid arithmetic expressions?
a) ch=100
b) i-j+k
c) i%k
d) a%b+c-k
e) p+q/b>i
Q 23 What will be the resultant type of the following expression if int is an integer variable and fl is a float variable?
Q 24 Write the corresponding C++ expressions for the following mathematical expressions:
(a) (cos x/sin-1 x )+ y
(b) (x2 + y2 + z2 )1/2
(c) | ey + y |
(d) a+ b/ (x +y)7
Q 25 Given the following set of declarations:
int x, y, z, d; float p, q, r; double a, b, c ;
Which of the following are valid arithmetic expressions and which are invalid. And state the reason why they are invalid.
(a) (ceil (p) + x ) z.
(b) a b * c / d.
(c) c/p +y * x / z.
(d) log (-18) + x/ y.
(e) x*+d
Q 26 Which header file must be included to make use of C++‘s built-in mathematical functions?
Q 27 Evaluate the following C++ expression
int x, ch=5, n=10;
x = ch * 7/ 4 + ch/5 +25 –ch +7/2 +3 /11
Q 28 What is type conversion? What is meant by implicit and explicit type conversion?
Q 29 Given the following set of identifiers:
char ch;
short sh;
int inval;
long lg;
float fl;
double db;
Identify the data type of the following expressions:
a) 4.55 +’z’
b) (fl * lg) +inval
c) ch/inval +fl *db – (long/sh)
Q 30 Write a statement to print the size of
(i) double type on your machine.
(ii) a long int variable result.
Q 31 Suppose a and b are two type float variables that we want to add as integers and assign to an integer variable marks. Construct a C++ statement to do so.
Q 32 Write a program to input three integers and print the largest of them.
Q 33 The following code is giving error. Can you detect the error and help in successful compilation of this code?
Code:
# include < iostream.h >
void main ()
{ int x, y ;
cin >> y;
cout << “The square root of y is :“ << sqrt (x) ;
}
Submitted By Mr. Prabhuji Gupta
Email: [email protected] |