i) Uninitialized and Initialized.
ii) Implicit and Explicit.
The postfix increment/decrement operators need a little more understanding. The compiler makes a temporary copy of x, increments x, and then evaluates the temporary copy of x.
Z =a*x*x+b*x+c
=2*3*3+4*3+5
=6*3+12+5
=18+12+3
= 35
a) In i=8 and j=7 statement j++ will assign the current value of i(7).Then it will increase the value of i from 7 to 8
b) In i=7 and j=7 (Statement will first decrease the value of i from 8 to 7. Then only will j be assigned the new value of i ,i.e., 7. j will therefore be assigned the value of 7.
i) An example of a Mathematical expression is x2+3x-2.
ii) Relational expression results in either true or false. Eg. X-3>0
iii) Logical expression returns the truth of a complex relational expression.Eg:- (x>6)OR (x<6)
Followings are the solutions:-
a) 0
b) 0
c) 1
i) a>=b&&(a+b)>a
Ans) a=6,b=1
ii) a=b|| b=a
Ans) a=9 b=9
Header files are enclosed within < > as it signifies that these header files are a part of C++ standard library and the compiler searches for them in the standard library path.
The following chart explain the differences along with the explanations
|
Operator |
Symbol |
Form |
Explanation |
|
Prefix increment |
++ |
++x |
Increment x, then evaluate x |
|
Prefix decrement |
-- |
--x |
Decrement x, then evaluate x |
|
Postfix increment |
++ |
x++ |
Evaluate x, then increment x |
|
Postfix decrement |
-- |
x-- |
Evaluate x, then decrement x |
i) The name is more appropriate as C++ as C++ is built from C and it is the superset of C language.
ii) shorthand
iii) Arguments are values required by a function to work upon.
iv) Floating point arithmetic is not exact as integer arithmetic.
v) order of evaluation of logical operators is NOT, AND i.e. &&, OR i.e. ||
A. token/lexical unit.
B. keyword.
C. identifier.
D. functions.
A token is the smallest element of a C++ program that is meaningful to the compiler. It includes keywords, identifiers and literals.
A. cascading stream.
B. stream.
C. cascading stream of input and output operators.
D. keywords.
<< is called insertion or put to operator. It directs the contents of the variable on its right to the object on its left. >> is extraction operator. Together these are called as cascading stream of input and output operators.
A. instead of commas semicolon should be used.
B. there should be a semicolon at the end of the statement.
C. there is no error.
D. the increment should always be ++k.
In for loop the proper syntax is for (initialization; condition; increment). So it should be for (k=0; k<10; k++).
A. y=5
B. y=6
C. error.
D. y=7
The following code will result an error called Lvalue required, because the prefix operator ++in C++ works on the operand rather than the value.
A. only operators.
B. only constants.
C. only variables.
D. operators, constants and variables.
An expression is composed of one or more operations. The objects of the operation(s) are referred to as operands.The operations are represented by operators.
A. double fmod( double x, double y)
B. double mod( int y, int x)
C. int fmod( double x, double y)
D. int fmod( double x, double y)
Example: fmod( 10.0, 4.0 ) returns 2.0
A. integral promotion.
B. type casting.
C. type promotion.
D. type conversion.
Whenever a variable or expression of smaller type is converted to operand of larger type, it is called type promotion.
A. char.
B. float.
C. int.
D. long.
i) 'z' is char and char is converted to an int using implicit conversion. ii) 5 is int. iii) therefore together the expression is int.
A. programmer.
B. compiler.
C. by both programmer and compiler.
D. users.
An implicit conversion sequence is the sequence of conversions required to convert an argument in a function call to the type of the corresponding parameter in a function declaration.
A. 300
B. 600
C. 1570
D. 1500
? is a conditional operator. If yes do this Else do something else.
Result is 1 ,i.e., True.
In an assignment statement, the type conversion rule states : The value of the right side (expression side) of the assignment is converted to the type of the left side(target variable).
i) a+b-c+count
ii) a%b
iii) a/b
iv) –a+b*c
The process of converting one predefined type into another is called Type conversion. It is also known as type-casting. C++ provides two types of type-casting -
(i) Implicit type-casting
(ii) Explicit type-casting
Integer expressions are formed by connecting i) integer constants ii) and/or integer variables iii) and/or integer arithmetic operators.
The conditional operator in C++ is (? :). It stores a value depending upon a condition and requires three operands. It works like an if-else statement.
a) Logical OR ||
b) Logical AND &&
c) Logical NOT !
In the prefix version – first change the value ie.- increase or decrease) the value and then use it in the expression.
In the postfix version, first use the value and then change it either by increasing or decreasing it.
When an increment and decrement operator follows the operand it is called the postfix form. In this C++ first uses the value of the operand in evaluating the expression, before incrementing or decrementing the operator’s value.
Two type of unary operators are :-
i) unary + and
Binary operators need 2 operands (i.e. values) whereas Unary operators need one operand.
There are 5 arithmetical operators. These are -
i) +
ii) –
iii) *
iv) division as / and
v) remainder as %
A. goto statement.
B. return statement.
C. break statement.
D. continue statement.
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after where the subroutine was called — known as its return address.
A. for, goto and switch.
B. goto, switch and while.
C. for, switch and do-while.
D. for, while and do-while.
C++ provides three kinds of loops: for loop, while loop, and do-while loop. All three loops construct of C++ repeat a set of statements as long as a specified condition remains true.
A. two.
B. three.
C. four.
D. five.
C++ provides three loops: for, while and do-while.
A. if and else.
B. if and not.
C. if and switch.
D. goto and switch.
An if statement is a selection statement that allows more than one possible flow of control. A switch statement is a selection statement that transfers control to different statements within the switch body depending on the value of the switch expression.
A. if statement.
B. else statement.
C. if-else statement.
D. go statement.
The conditional operator (?:) takes three operands. It tests the result of the first operand and then evaluates one of the other two operands based on the result of the first. It is similar to if-else statement.
A. two.
B. three.
C. four.
D. five.
The two types of selection statements are :- if and switch statement.
A. entry condition.
B. out condition.
C. exit condition.
D. control condition.
The set of statements that are repeated again and again is called the body of the loop. The condition on which the execution or exit of the loop depends is called the exit condition.
A. closed construct.
B. open construct.
C. decision construct.
D. looping construct.
The iteration construct means repetition of a set of statements depending upon a condition test. Till the condition is true, a set-of-statements are repeated again and again. This construct is also known as looping construct.
A. sequence construct.
B. decision construct.
C. iteration construct.
D. order construct.
The iteration construct means repetition of a set of statements depending upon a condition test. Till the condition is true, a set-of-statements are repeated again and again.
A. sequence construct.
B. order construct.
C. inline construct.
D. straight construct.
The sequence construct means the statements are being executed sequentially. This represents a default flow of statements.
A. flow of control.
B. sequence construct.
C. database.
D. statement.
Statements are the instructions given to the computer to perform any kind of action, be it data movements, making statements, making decisions or repeating actions.
A. document construct.
B. sequence construct.
C. decision construct.
D. iteration construct.
The looping construct is known as iteration construct because it helps in repeating the task until exit condition met.
A. sequence construct.
B. iteration construct.
C. selection construct.
D. operation construct.
In selection construct, if a condition evaluates to true, a course-of-action is followed otherwise another course of action is followed.
A. two.
B. three.
C. four.
D. five.
There are three ways: sequentially, selectively and iteratively.
A. executable statements.
B. compound statements.
C. simple statements.
D. complex statements.
Compound statements contain (groups of) other statements; they affect or control the execution of the other statements in some way.
A. .
B. ;
C. :
D. : -
A semi-colon (;) terminates statements in C++.
A. flow of control.
B. sequence construct.
C. database.
D. statements.
Statements are the instructions given to the computer to perform any kind of action, be it data movements, making statements, making decisions or repeating actions.
A. continue statement.
B. break statement.
C. goto statement.
D. return statement.
The continue statement immediately transfers control to the evaluation of the test-expression of the loop for the next iteration of the loop.
A. 10 8 6.
B. 8 6.
C. 10 8.
D. 10 8 7 6.
The variable is initialised from 10 and then two is subtracted each time. This continues till the time i>6.
A. 1 2 3 4 5 6 7 8 9.
B. 0 1 2 3 4 5 6 7 8.
C. 1 2 3 4 5 6 7 8 10.
D. 3 4 5 6 7 8 9 10.
Here the variable is initialized from 1 and will continue up to 9 as, i<10.
A. -3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11.
B. -2,-1,0,1,2,3,4,5,6,7,8,9,10,11.
C. -2,-1,0,1,2,3,4,5,6,7,8,9,10.
D. an error message.
It will produce an error message ’Declaration terminated incompletely’ during compilation as the declaration int = -3 does not declare a variable.
A. break statement.
B. continue statement.
C. switch statement.
D. default statement.
The switch statement body consists of a series of case labels and an optional default label. The default label can appear only once.
A. entry( ) function.
B. quit( ) function.
C. exit( ) function.
D. close( ) function.
The exit( ) function causes the program to terminate as soon as it is encountered, no matter where it appears in the program listing.
A. empty statement.
B. blank statement.
C. free statement.
D. closed statement.
The simplest statement is an empty or null statement. It takes the form: ; // it is a null statement, just a semi-colon.
A. i=i+1.
B. i=i-1.
C. i=i+i.
D. i=i+0.
i-- is equal to i-1. -- is a decrement operator which decrements value by 1. For example a--is equal to a-1.
A. i=i+1.
B. i=i-1.
C. i=i+i.
D. i=i+0.
i++ is equal to i+1. ++ is an increment operator which increments value by 1.
A. bottom of the loop.
B. top of the loop.
C. middle loop.
D. top or bottom of the loop.
In most computer programming languages, a do while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. Here, the evaluation is done at the bottom of the loop.
A. bottom of the loop.
B. top of the loop.
C. middle loop.
D. top or bottom of the loop.
In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. Here the evaluation is done at the top of the loop.
A. bottom of the loop.
B. top of the loop.
C. middle loop.
D. top or bottom of the loop.
In computer science, a for loop is a programming language statement, which allows code to be repeatedly executed at the top of the loop. A for loop is classified as an iteration statement.
A. the logical operator && cannot be used with while statement.
B. the while loop is an exit condition loop.
C. the test condition is always false.
D. the test condition is always true.
Here, the condition controlling the execution of the loop is always false. It will never be true.
A. document construct.
B. sequence construct.
C. decision construct.
D. iteration construct.
The selection construct is known as decision construct because it helps in making decision about which set-of-statements is to be executed.
A. i=i+1.
B. i=i-1.
C. i=i+i.
D. i=i+0.
i++ is equal to i+1. ++ is an increment operator which increments value by 1.
A. cascading stream.
B. stream.
C. cascading stream of input and output operators.
D. keywords.
<< is called insertion or put to operator. It directs the contents of the variable on its right to the object on its left. >> is extraction operator. Together these are called cascading stream of input and output operators.
A. return 0; statement.
B. the first statement after the loop.
C. the statement following the continue statement.
D. the next iteration of the loop.
Continue statement ends the current iteration of a loop. Program control is passed from the continue statement to the end of the loop body and continue next iteration.
A. token/lexical unit.
B. keyword.
C. identifier.
D. functions.
A token is the smallest element of a C++ program that is meaningful to the compiler. It includes keywords, identifiers and literals.
A. parenthesis ().
B. braces {}.
C. brackets [].
D. arrows <>.
{} are used for more than one statement in the block of a for loop. When there is a single statement then () are used. Example: for (i=0;i<10;i++). It will execute the code within for loop 10 times.
A. 5
B. 0
C. 3
D. 2
Any number * 0= 0
A. int i=1;
B. while condition after closing braces.
C. int sum;
D. (i<10)
The while condition should be after closing braces so that the statements executed at least once. the correct code is: int sum=0; int i=1; do {sum=sum+1; i=i+1; }while(i<10);
A. int i=1;
B. while(i<10)
C. both (a) and (b)
D. cout<<5*i;
Both a) and b) are correct so answer is c
int i=1;
While(i<10)
A. for loop.
B. do loop.
C. if-else loop.
D. switch statement.
The for loop executes a section of code a fixed number of times. It defines number of times we want to execute the code.
A. update expression.
B. Test expression.
C. Initialization expression.
D. Declaring expression.
for loop is having following form:
for(initialization expression; test expression ; update expression)
Example:
for(i =0; i<=15; i++)
A. semicolon.
B. double quotes.
C. comma.
D. single quotes.
Example:
for(i=1, sum =0; i<= n; i++)
here two varialbe i and sum is initialised with for loop both these variables are seperated by comma.
A. While loop
B. For loop
C. do while
D. All of the above
do-while is exit controlled loop, it evaluates the test expression after executing its loop body statements. This means that a body of loop executed at least once.
A. break.
B. continue.
C. switch
D. both a and b
Jump statements are used to transfer program control unconditionally. There are following jump statements:
break, continue, goto, return
A. while
B. for
C. do while
D. all of the above
for loop is the simplest loop among all loops. All its loop-control elements are gathered in one place(on the top of loop).Therefore it is convnient to use for loop when number of iterations are known.
A. switch statement.
B. If else.
C. next iteration.
D. none of the above.
The continue statement skips the remaining statements in the body of the loop, and continues with the next iteration of the loop.
A. library function main.
B. break.
C. continue.
D. exit function.
exit function : is terminates entire program. Here it is used in for loop when the value of i is eqauls to 100 then exit(0) will be executed and the program will be terminated.
#include
#include
#include // requires to include for exit() function
main()
{
clrscr();
for (int i=1;i<=100; i++)
{
cout << i <
exit(0); // it will termiate entire program
}
cout << "hello" <
}
A. A constant.
B. Switch statement.
C. break statement.
D. A variable definition.
You cannot use a goto statement to jump over initializations. A goto statement is allowed to jump within the scope of a variable length array, but not past any declarations of objects with variably modified types.
A. function.
B. Iteration loop.
C. program.
D. do while loop.
A return statement ends the processing of the current function and returns control to the caller of the function.
A. If.
B. Goto.
C. for statement.
D. do while.
A goto statement causes your program to unconditionally transfer control anywhere in the program or to the statement associated with the label specified on the goto statement.
A. Assignment statements.
B. Jump statements.
C. block statements.
D. looping statement.
Jump statement unconditionally transfer program control within a function.
A. One statement selection.
B. Multiple branch Selection.
C. Switch selection.
D.
switch statement is a multiway decisions that tests whether a variable or expression matches one of a number of constant integer values, and branches accordingly.
A. Multiple statements unit.
B. Single unit.
C. selection unit.
D. none of them.
A block is a single unit that contain group of statements which are separated by semicolon(;).
A. general statements.
B. Selection Statements.
C. Iteration statements.
D. jump statements.
Jump statements unconditionally transfer program control within a function. There are following jump statements: goto, return, continue, break and one library function exit( ).
A. Selection statements.
B. Iteration statements.
C. Conditional statements.
D. Decision making statements.
Iteration construct depends upon condition test which can be either true or false. There are following iteration construct: for, while and do-while.
A. selection statements.
B. jump statements.
C. repetitive statements.
D. loop statements.
They are together referred to as Selection construct. It means the execution of statement depending upon a condition test. It evaluates it to Truth value. It can also called as decision making statement.
A. control to the end of the program.
B. control to the next statement.
C. control to the next statement outside the loop.
D. none of the above.
A break statement enables a program to skip over part of the code and jumps to the statement following the loop.
A. *
B. **
C. ****
D. *****
Output here will be one star i.e. * while condition evaluated false so loop is terminated.
A. square of 2 is 1
B. square of 2 is 4
C. square of 3 is 9
D. square of 2 is 4.5
initial value of i = 2 and while condition evaluates to true, so cout statement is executed
therefore i*i = 2*2 =4
A. takes less processing time.
B. takes more processing time.
C. takes extremely less processing time.
D. takes average processing time.
There are 2 if statements, so takes more processing time.
A. forces termination.
B. forces next iteration.
C. forces exit and continue.
D. forces next termination.
A continue statement ends the current iteration of a loop. Program control is passed from the continue statement to the end of the loop body. Thus forces next iteration.
A. Block statement.
B. Set statement.
C. Group statement.
D. collective statement.
A. putting semicolon after paranthesis in for statement.
B. terminating for loop by colon.
C. just by terminating paranthesis.
D. putting a fullstop after paranthesis.
Time delay loop can be made by putting semicolon(;) after closing parenthesis of loop
Example:
for(t=0; t<300; t++);
A. colon :
B. double quotes “ “
C. semicolon ;
D. single quotes ‘ ‘
An empty statement does nothing.
empty statement
;
An empty statement is used when there are no operations to perform in a context where a statement is required.
A. braces.
B. single quote.
C. double quotes.
D. ending parenthesis in for statement by a semicolon.
For attaching null with given for loop, the code will be written as:
for(a=1,total=0;++a)
;
A. only decision making tasks.
B. only repetitive tasks.
C. any types of tasks.
D. both repetive tasks as well as decision making tasks.
Repetitive and decision making tasks Eg:- Calculating pay structure for all say 10,000 employees of an organization. Or making voters list depending on age
A. colon ( : ).
B. double quotes (" " ).
C. semicolon( ;).
D. single quotes ( ' ' ).