MCQ and T (Or) F C++

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

MCQ and T/F Questions for C++(All Chapter)

1. cin used to display information on computer screen. (False)


2. The correct value to return to the operating system upon the successful completion of a program is 0.
(True)
3. The manipulators are operators used with the insertion operator (<<) to modify or manipulate the way
data is displayed. (True)
4. In an assignment statement, the value on the left of the equal sign is always equal to the value on the
right. (False)
5. Implicit conversion also called type casting is user defined and the user can type cast the result to make
it of a particular data type. (False)
6. Preprocessor directives begin with _____.
(a) ! (b) @ (c) # (d) %
7. The _____ operator are used on single operand, so it is also called as unary operator.
(a) assignment (b) relational (c) arithmetic (d) increment
8. The data type bool has only _____ possible values.
(a) one (b) two (c) three (d) four
9. The setw manipulator changes the field width of _____.
(a) program (b) input (c) output (d) array
10. Every C++ programs must contain _____.
(a) start() (b) main() (c) program() (d) system()

1. A relational operator compares two values and the results can either be true or false.
Ans: True

2. The repetition of a loop continues while a condition is either true or false.


Ans: False

3. The for loop contains three expressions: the initialization expression, the _________ expression, and the
increment/decrement expression.
Ans: test

4. The while loop contains a ______ expression only.


A. initialization expression
B. test expression
C. increment expression
Ans: B

5. In _____ loop, the test expression is placed at the end of the loop.
A. for
B. while
C. do
Ans: C
6. The exit() function causes the C++ program to terminate.
Ans: True

7. The value of alpha is 5 and beta is 2 then output the value for min.
min=(alpha<beta)?alpha:beta;
Ans: 5
8. ________ operators combine two or more relational operators or expressions.
A. Relational
B. Logical
C. Arithmethic assignment
Ans: B
9. The break statement stops the execution of the outermost loop.
Ans: False

10. The continue statement takes to the top of the loop when something unexpected happens.
Ans: True

1. The main difference between structure and array is that arrays are collection of the different data type
and structure is a collection of same data types. (False)
2. Structures are built-in data types. (False)
3. A structure definition creates space in memory for a variable. (True)
4. Structure is declared by using keyword struct followed by structure name called tag. (True)
5. Enumeration is user defined type which is used to assign names to integral constants. (True)
6. When accessing a structure member, the identifier to the left of the dot operator is the name of ______.
(a) a structure member (b) a structure tag
(c) a structure variable (d) the keyword struct.
7. An enumeration brings together a group of _____.
(a) items of different data types (b) integers with user-defined names
(c) related data variables (d) constant values
8. The first three enumerators of an enum type are normally represented by the values.
(a) 0 (b) 1 (c) 2 (d) 3
9. Internally the compiler treats enumeration variables as ______.
(a) string (b) character (c) integer (d) float
10. the structure members can be accessed by using member access operator also called _____ operator.
(a) reference (b) dereferencing (c) insertion (d) dot

1). Which of the following is used to terminate the function declaration in C++?
a) ;
b) ]
c) )
d) :

2). Which is more effective while calling the C++ functions?


a) call by object
b) call by pointer
c) call by value
d) call by reference
3). At first, C++ program performs _____ .
a) recursive( )
b) main( )
c) library( )
d) inline( )

4). In function declaration, structure can use as an argument.


a) True
b) False

5). Inline function is used to save _____ time in short functions.


a) execution
b) looping
c) returning
d) calling

6). The outputs of the following program are


void demo ( )
{ int count=0;
cout<<count<<",";
count++;}
int main( )
{ for (int i=0;i<3;i++)
demo( );
return 0; }
a) 3,3,3
b) 0,0,0
c) 0,1,2
d) 1,2,3

7). Variables defined outside a function are called _____ variables.


a) global
b) static
c) constant
d) local

8). To use library function in C++ program, it must use _____.


a) keyword
b) variable
c) header file
d) array

9). In C++ program, to define the function before it’s called.


a) True
b) False
10). The function doesn’t provide default arguments.
a) True
b) False

1.The elements of an array is stored in memory locations

A. Randomly
B. Sequentially
C. Both of them
D. None of above

2. An array element is accessed using

A. A first-in-first-out approach
B. The dot operator
C. A member name
D. An index

3.The item in an array is called

A. Index
B. Array name
C. Size
D. Element

4. All the elements in an array are of the _____ type.

A. Same
B. Different
C. Either same or different
D. Neither same nor different

5. The elements of a 10-element array are numbered from _____ to _____.


A. 0,10
B. 1,10
C. 0,9
D. 1,11

6. If you want to store the values in the form of the list, which type of array you can use :

A. Single Dimensional Array


B. Multidimensional Array
7. Which is(are) the outputs of the following statements?

Int array[] = {0, 2, 4, 6, 7, 5, 3}; int n, result = 0;


For (n= 0;n< 8;n++)
{
Result += array[n];
}
Cout << result;
A. 55
B. 34
C. 29
D. 27

8. Which is(are) the outputs of the following statements?


Char str2[10], str1[]="hello_ _";
Int number,n;
Number=strlen(str1);
Cout<<number;
N=strlen(str2);
Cout<<n;
A. 50
B. 07
C. 70
D. 80

9. When a multidimensional array is accessed, each array index is


A. Separated by brackets.
B. Surrounded by brackets and separated by commas.
C. Separated by commas and surrounded by brackets.
D. Surrounded by commas.

10. String concatenation is a way of


A. Merging two strings
B. Partitioning a substring
C. Combining two strings to one string
D. Comparing two strings

1. The operator used for dereferencing or indirection is ____


a) *
b) &
c) ->
d) –>>

2. Choose the right option.


string* x, y;

a) x is a pointer to a string, y is a string

b) y is a pointer to a string, x is a string

c) both x and y are pointers to string types

d) y is a pointer to a string
3. What will be the output of the following C++ code?

int main() {
int a = 5, b = 10, c = 15;
int *arr[] = {&a, &b, &c};
cout << arr[1];
return 0;
}
a) 5

b) 10

c) 15

d) it will return some random number

4. What will be the output of the following C++ code?


int main() {
char *ptr;
char str[] = 'abcdefg';
ptr = str;
ptr += 5;
cout << ptr;
return 0;
}
a) fg
b) cdef
c) Defg
d) abcd

5. A pointer variable store a/an


a) value of another value.
b) value of another variable.
c) address of another pointer.
d) address of another variable.
6. If ptr is a pointer variable pointing to an array, then cout<< *(ptr++); statement will print:
a) Next location address
b) Next location index value
c) Next location value
d) Compile time error

7. Are the expression *ptr++ and ++*ptr are same?


a) True
b) False

8. Specify whether the statement below is true or false.int i;double * dp = &i;


a) True
b) False

9. Can we point to a datatype using a pointer?

a) True
b) False

10. Which of the following is the correct option?


int* a, b;

a) a is a pointer to an integer and b is an integer variable


b) b is a pointer to an integer and a is an integer variable
c) both a and b are pointers.

1. By default, all the files are opened in ___________mode .

a) Binary
b) Text
c) Can’t say

2. It is not possible to combine two or more file opening mode in open () method.

a) True
b) False

3. __________ is return type of is_open() function.


a) int
b) bool
c) float
d) char *

4. Which function is used to reposition the file pointer?


a) moveg()
b) fseek()
c) changep()
d) go_p()

5.Which function is used in C++ to get the current position of file pointer in a file?
a) ftell()
b) get_pos()
c) get_p()
d) tell_pos()

6. Which of the following is used to move the file pointer to start of a file?
a) ios::beg

b) ios::start

c) ios::cur

d) ios::first

7. It is not possible to combine two or more file opening mode in open () method.
a) True

b) False

c) May be

d) None of these

8. Which of these is the correct statement about eof() ?


a) Returns true if a file open for reading has reached the next character.

b) Returns true if a file open for reading has reached the next word.

c) Returns true if a file open for reading has reached the end.

d) Returns true if a file open for reading has reached the middle.
9. Which of the following true about FILE *fp
a) FILE is a structure and fp is a pointer to the structure of FILE type

b) FILE is a buffered stream

c) FILE is a keyword in C for representing files and fp is a variable of FILE type

d) FILE is a stream

10. Which operator is used to insert the data into file?

a) >>
b) <<
c) <
d) None of the above

You might also like