Chapter-Getting Started With C++
Important MCQ questions for Class 11 Computer Science Chapter-Getting Started With C++
Get Important MCQ questions for Class 11 Computer Science Chapter-Getting Started With C++ with a detailed explanation of all the MCQ questions asked from Chapter-Getting Started With C++ prepared by the experts.
Get Selected MCQ-based questions with solutions for Chapter-Getting Started With C++
MCQ Questions set-1 for chapter-Getting Started With C++ class 11 Computer Science
Computer Science - MCQ on Getting Started With C++
Class XI
Q. 1. Values can be input to variables in the program, using the stream
a. cin.
b. cout.
c. iostream.
d. istream.
Answer:
(a)
Explanation: cin is a stream used to input the variables in a C++ program.
cin is an object of class istream that represents the standard input stream.
Q. 2. The operator, that will be evaluated first is
a. ||.
b. !.
c. &&.
d. ?:.
Answer:
(c)
Explanation: && is having highest precedence among the following operators.
Q. 3. In C and C++, if I is an integer then, I=7/9*9 evaluates to
a. 0.
b. 0.08462.
c. 0.08642.
d. 1.
Answer:
(a)
Explanation: Both / and * are having the same priority, but they are left to right associative. On checking, / is operated first so the result is 0.
Q. 4. The statement valid in C is
a. // A comment //;
b. char x=12;
c. struct s{int I;};
d. class aClass{public:int x;};
Answer:
(c)
Explanation: In C++, struct s {int I;}; is a valid declaration of a structure.
Q. 5. Among the following, an invalid declaration for main() is
a. int main().
b. int main(int argc, char *argv[]).
c. they both work.
d. void main().
Answer:
(d)
Explanation: void main() is not allowed since, the keyword is void and not Void.
Thus, it would return a syntax error.
Q. 6. The character that terminates all character array strings is
a. /n.
b. /0.
c. /s.
d. .
Answer:
(b)
Explanation: /0 is the null character which marks the end of a string.
Q. 7. The result of the expression 22%5 is
a. 0.
b. 1.
c. 2.
d. 4.
Answer:
(c)
Explanation: The modulus operator returns the remainder, when 22 is divided by 5, which is 2.
Q. 8. C++ is case sensitive. This statement is
a. false.
b. depends on implementation.
c. depends on operating system.
d. true.
Answer:
(d)
Explanation: C++ is case sensitive, as the code is written in C++ turbo compiler. The syntax makes the language case sensitive.
Q. 9. The data type in C++, that is the equivalent of Pascal's Real is
a. unsigned int.
b. float .
c. char.
d. signed int.
Answer:
(b)
Explanation: float data type represents a class of objects that are real numbers, or numbers having decimal. Example-4.56.
Q. 10. The expression: ! (1 &&0 || !1) evaluates to
a. false.
b. error.
c. run time error.
d. true.
Answer:
(d)
Explanation: In the above expression, first && operators executes, followed by ||. Thus, the result 1 is obtained which corresponds to true.
Q. 11. C++ was developed by
a. Bjarne Stroustrop.
b. Dennis Ritchie.
c. James Gosling.
d. Bill Gates.
Answer:
(a)
Explanation: Originally designed for systems programming, C enables programmers to write efficient code and provided close access to the machine. Then, C++ originated with Bjarne Stroustrop.
Q. 12. C++ was introduced in the year
a. 1981.
b. 1983.
c. 1980.
d. 1985.
Answer:
(d)
Explanation: In 1980, Bjarne Stroustrup, from Bell labs, began the development of the C++ language, which received formally this name at the end of 1983, when its first manual was published. In October 1985, the first release of the language appeared.
Q. 13. Among the following, whitespace character is
a. @.
b. /n.
c. !.
d. _.
Answer:
(b)
Explanation: Blank space, horizontal tab, carriage return, newline, form feed
all come under whitespace, used in a C++ program.
Q. 14. Lexical units is another name for
a. tokens.
b. keywords.
c. identifiers.
d. literals.
Answer:
(a)
Explanation: Lexical units are the tokens that combined together to form the translation unit.
Q. 15. In C++, a valid keyword is
a. num.
b. real.
c. dowhile.
d. switch.
Answer:
(d)
Explanation: switch is a valid keyword in C++, and is used in place of many if statements.
MCQ Questions set-2 for chapter-Getting Started With C++ class 11 Computer Science
Q. 16. In C++, a valid variable name is
a. 1class.
b. _student.
c. $$1.
d. My student 1.
Answer:
(b)
Explanation: Variable names in C++ cannot start with a number.
Q. 17. The keyword used to declare an enumeration in C++ is
a. enum.
b. enumerate.
c. enums.
d. enumeration.
Answer:
(a)
Explanation:Enumeration is used in an ordered list context, which is declared using the keyword enum in C++.
Q. 18. The character /? is used to denote a
a. question mark.
b. conditional operator.
c. literal question mark.
d. literal conditional operator.
Answer:
(c)
Explanation: A ? denotes a question mark but when / is used along with it, its meaning changes and it becomes a character constant , that is a literal.
Q. 19. In C++ /xhhhh is used to denote a
a. ASCII character in hexadecimal notation.
b. ASCII character in octal notation.
c. horizontal tab.
d. Unicode character in hexadecimal notation.
Answer:
(d)
Explanation: It represents a Unicode character in hexadecimal notation. If this escape sequence is used, in a wide-character constant or a Unicode string literal.
Q. 20. The statement a=++b; would
a. increment the value of b to 4 before assignment.
b. increment the value of b to 4 after assignment.
c. assign b to a and increment their sum.
d. calculate the sum of a and b two times.
Answer:
(a)
Explanation: ++ is a pre-increment operator. Therefore, it would increment the value of b and assign it to a.
Q. 21. In C++, the output of the statement 7==5 ? 4 : 3 is
a. 3.
b. 4.
c. 5.
d. 7.
Answer:
(a)
Explanation: 7==5 ? 4 : 3 returns 3, since 7 is not equal to 5.
Q. 22. In C++, the output of the statement 7==5+2 ? 4 : 3 is
a. 2.
b. 3.
c. 4.
d. 5.
Answer:
(c)
Explanation: 7==5+2 ? 4 : 3 returns 4, since 7 is equal to 5+2.
Q. 23. The output of the code is
#include <iostream>
using namespace std;
int main () { int a,b,c; a=5; b=9; c = (a>b) ? a : b; cout << c; return 0;}
a. 0.
b. 1.
c. 2.
d. 9.
Answer:
(d)
Explanation: a was 5 and b was 9, so the expression being evaluated (a>b) was not true. Thus, the first value specified after the question mark was discarded, in favour of the second value (the one after the colon), which was b, with a value of 9.
Q. 24. The operator used to separate two or more expressions that are included, where only one expression is expected is
a. .
b. ?
c. >
d. ,
Answer:
(d)
When the set of expressions has to be evaluated for a value, only the rightmost expression is considered. These expressions are separated with the help of a comma operator.
Q. 25. The name given to a label is an example of
a. keyword.
b. identifier.
c. character literal.
d. literal constant.
Answer:
(b)
Explanation: An identifier is a sequence of characters, used to denote a label name.
Q. 26. In C++, ## is used to
a. perform token replacement.
b. perform preprocessor operations.
c. include two header files at the same time.
d. include a library function.
Answer:
(a)
Explanation: # is used for preprocessor directives and ## is used to perform token replacement and merging, during the preprocessor scanning phase.
Q. 27. Assume that X has been declared as an integer variable in a C++ program. If the program encounters, non-integer data while reading the value of X then,
a. run time error occurs.
b. type casting occurs.
c. semantic error occurs.
d. type error occurs.
Answer:
(d)
Explanation: If non-integer data like a string is entered for integer data type, then type error occurs. It can be rectified by retyping the data in an integer form or by converting the non-integer data into integer form.
Q. 28. The error in the given code is
int main(){ cout<<“enter variable”; cin>>var; sqrs1=var*var; cout<<“The square is”<<sqrs1;}
a. sqrs1 cannot be a variable name.
b. >> should be used in place of <<.
c. variables are not declared before use.
d. main can not have int as its data type.
Answer:
(c)
Explanation: Since, variables are not declared before their use, a syntax error occurs.
Q. 29. The error in the given code is
#include<iostream.h> void main() { int sum,9var,sum-3; cin>>sum;sum=sum+1;cout<<sum;}
a. conio.h is not included.
b. sum should be float.
c. 9var and sum-3 are invalid identifiers.
d. There should be a semicolon after}.
Answer:
(c)
Explanation: A variable name can never start with a number. A variable name cannot include any special characters except, _ and $.
Q. 30. The procedure marking the start of execution of a C++ program is
a. exe().
b. main().
c. void().
d. start().
Answer:
(b)
Explanation: main() indicates the start of any program. A program cannot
execute without a main() in C++.
Q. 31. In our human body, we have brain, that stores all the functions to be performed by our body. For C++ these functions are stored in
a. header files.
b. library functions.
c. iostream.
d. main().
Answer:
(a)
Explanation: A header file is a file containing C declarations and macro definitions to be shared between several source files. They supply the definitions and declarations required to invoke system calls and libraries.
Q. 32. Keywords are also called as
a. literals.
b. reserved words.
c. separators.
d. punctuators.
Answer:
(b)
Explanation: Keywords are also called as reserved words. Punctuators are {},[],; *
Q. 33. During a program run, literals are
a. constants.
b. varying float numbers.
c. varying integers.
d. string.
Answer:
(a)
Explanation: Literals are data items, which never change their value during a program run. They are integer constant, character-constant, floating constant and string –literal.
Q. 34. The assignment operator used in C++ program
a. assigns the l value to the r value (left to right rule).
b. assigns the r value to the l value (right to left rule).
c. can be in either way.
d. compare two values.
Answer:
(b)
Explanation: The assignment operation always takes place from right to left, and never the other way. Example: a=b; this statement assigns to variable a (the l value) the value contained in variable b (the r value).
Q.35. Every function in c++ has its code
a. within square brackets.
b. within angular bracket.
c. within curly braces.
d. no bracket used etc.
Answer:
(b)
Explanation: Every function in C++ has its code within curly braces. {}
Q. 36. The error in this statement is
cout<<computers can be fun ;
a. >> should be used instead of <<.
b. double quotes are not used.
c. there should be a space between < and <.
d. semicolon should not be used.
Answer:
(b)
Explanation: Correct sentence is cout<<”computers can b fun”;
Q. 37. The function of endl is
a. same as ‘\n’.
b. to send a newline character ‘\n’ and then, flush the output buffer.
c. it flushes the output buffer.
d. to send a newline character ‘\n’ but, does not flush the output buffer.
Answer:
(b)
Explanation: ‘\n’ and endl manipulator sends a new line character ‘\n’ but endl also flushes the output buffer whereas, ‘\n’ does not flush the output buffer.
Q. 38. Manipulators used in C++ are
a. setw, setiosflags, setfill, setprecision.
b. cout, cin.
c. ‘\n’.
d. setw, endl and scope resolution operator.
Answer:
(a)
Explanation: setw, setiosflags, setfill, setprecision, endl are manipulators.
Manipulators are used to change formatting parameters on streams, and to insert or extract certain special characters.
Q. 39. The invalid form of a real constant is
a. –0.00625.
b. 35.66.
c. + 5.0.
d. 15,356.30.
Answer:
(d)
Explanation: The form of a real constant is basic real constant, basic real constant followed by a real exponent, integer constant followed by a real exponent. A real exponent is the letter E, followed by an optionally signed integer constant. Basic real constant is an optional sign, an integer part, a decimal point and a fractional part.
Q. 40. A character constant is
a. enclosed in double quotes .
b. enclosed in single quotes.
c. enclosed in brackets.
d. enclosed in parenthesis.
Answer:
(b)
Explanation: Text enclosed in single quotes is treated as character constant. The type of character constant is int. Its value is the ASCII code for the character.
Related Links
- Chapter-Computer Overview
- Chapter-Working with Operating System
- Chapter-Nature and Purpose of the Business
- Chapter-Input/Output and Memory Devices
- Chapter-General OOP Concepts
- Chapter-Getting Started With C++
- Chapter-Data Handling
- Chapter-Operators and Expressions in C++
- Chapter-Flow Of Control
- Chapter-Standard Library Functions
- Chapter-User Defined Functions
- Chapter-Structured Data Type: Array
- Chapter-Programming methodology