Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is the return type open() method?(a) int(b) char(c) bool(d) floatI got this question by my school principal while I was bunking the class.I want to ask this question from File Handling topic in chapter Strings, Streams & Numerics in C++ of C++

Answer»

The correct OPTION is (c) bool

The EXPLANATION: open() METHOD returns a bool value indicating whether the FILE is opened or some error has occurred.

2.

What is the use of accumulate function in a numeric library?(a) Returns the number(b) Returns the result of accumulating all the values in the range(c) Returns the number & result(d) Return the charactersThis question was addressed to me in semester exam.This intriguing question comes from Generalized Numeric Algorithms topic in division Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT choice is (b) RETURNS the result of ACCUMULATING all the VALUES in the RANGE

Explanation: Returns the result of accumulating all the values in the range from first to last.

3.

With which does the trigonometric functions work with angles in c++?(a) Degrees(b) Radians(c) Both Degrees & Radians(d) CelsiusThe question was posed to me during an internship interview.My question is from Standard Mathematical Functions in section Strings, Streams & Numerics in C++ of C++

Answer»

Correct OPTION is (B) RADIANS

The explanation: The TRIGONOMETRIC functions work with ANGLES in radians rather than degrees.

4.

What kind of locale does every program is having in C++?(a) local locale(b) global locale(c) temp locale(d) set localeThis question was addressed to me during an interview for a job.Question is taken from Locale topic in portion Strings, Streams & Numerics in C++ of C++

Answer» CORRECT option is (B) global LOCALE

To explain I would say: Every program has a SINGLE locale object which is its global locale.
5.

How many tests are available in read and write operations?(a) 1(b) 2(c) 3(d) 4This question was addressed to me by my college director while I was bunking the class.This key question is from Buffering in chapter Strings, Streams & Numerics in C++ of C++

Answer»

The correct option is (b) 2

Easiest explanation - There are TWO types of READ and write tests. They are throughput in RANDOM READS and throughput in contiguous reads.

6.

Where are the strings stored?(a) Stack(b) Heap(c) Both Stack & Heap(d) QueueThis question was addressed to me in a job interview.This intriguing question comes from String Characters topic in section Strings, Streams & Numerics in C++ of C++

Answer»

Right option is (c) Both Stack & Heap

Explanation: Dynamic strings(dynamic LENGTH) are STORED in heap and static string(with FIXED SIZE) are stored in stack.

7.

Which of the following is not used to seek file pointer?(a) ios::set(b) ios::end(c) ios::cur(d) ios::begThis question was posed to me in class test.My enquiry is from File Handling in division Strings, Streams & Numerics in C++ of C++

Answer»

Correct choice is (a) ios::SET

For explanation: ios::set is not used to seek FILE pointer. ios::end is used to seek from the end of the file. ios::curr from the CURRENT POSITION. ios::BEG from the beginning.

8.

What is the main feature of locale in C++?(a) Sustainability(b) Portability(c) Reliability(d) Sustainability & ReliabilityThis question was posed to me in a national level competition.Origin of the question is Locale topic in division Strings, Streams & Numerics in C++ of C++

Answer»

The correct option is (b) Portability

Easiest explanation - A locale is a SET of features that are culture-specific, which can be USED by programs to be more PORTABLE INTERNATIONALLY.

9.

Which of the following have their changes in their declaration related to constness of parameter?(a) strchr(b) string(c) memory(d) strcybrkThis question was addressed to me in an online quiz.I'm obligated to ask this question of C Standard Library topic in portion Strings, Streams & Numerics in C++ of C++

Answer»

The correct choice is (a) strchr

Easy explanation - These are the ITEMS which will have their CHANGE in declaration related to CONSTNESS of parameter. They are strchr, STRPBRK, strrchr, strstr, memchr.

10.

How does the strings are stored in the memory?(a) Contiguous(b) Non-contiguous(c) Null(d) sequenceI had been asked this question by my college professor while I was bunking the class.Question is from String Characters topic in chapter Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT ANSWER is (a) Contiguous

Easy explanation - The characters of a STRING are STORED contiguously in the memory.

11.

Which of the following library is used to do vector arithmetic?(a) Boost(b) Time(c) OpenGL(d) OpenDLThe question was posed to me in an interview.I want to ask this question from Vector Arithmetic in portion Strings, Streams & Numerics in C++ of C++

Answer»

Right CHOICE is (a) BOOST

Easiest explanation - Boost package has a linear ALGEBRA package that may well suits for vector ARITHMETIC.

12.

Where does the member should be defined if it is used in the program?(a) Namespace scope(b) Character scope(c) Namespace & Character scope(d) Directional scopeI have been asked this question in an interview for job.I'm obligated to ask this question of Numeric Limits topic in section Strings, Streams & Numerics in C++ of C++

Answer»

The correct choice is (a) NAMESPACE scope

Explanation: The MEMBER shall still be defined in a namespace scope if it is USED in the PROGRAM.

13.

What can be used to input a string with blank space?(a) inline(b) getline(c) putline(d) setlineI had been asked this question at a job interview.This intriguing question comes from Input Stream in portion Strings, Streams & Numerics in C++ of C++

Answer» RIGHT choice is (b) GETLINE

Explanation: If a USER wants to input a sentence with blank spaces, then he may USE the function getline.
14.

How many groups of output of operation are there in c++?(a) 1(b) 2(c) 3(d) 4I have been asked this question in final exam.Origin of the question is Output Stream topic in division Strings, Streams & Numerics in C++ of C++

Answer» CORRECT OPTION is (b) 2

Best explanation: There are two GROUPS of output OPERATION in c++. They are formatted output and UNFORMATTED output.
15.

Which of the following is used to create a stream that performs both input and output operations?(a) ofstream(b) ifstream(c) iostream(d) fstreamThis question was posed to me in class test.This intriguing question comes from File Handling in chapter Strings, Streams & Numerics in C++ of C++

Answer»

Right choice is (d) fstream

Easy EXPLANATION - fstream is used to CREATE a stream that performs both input and output OPERATIONS in C++ FILE handling.

16.

Which function is used to optimize the space in vector?(a) at(b) bool(c) operator(d) operandI had been asked this question by my school principal while I was bunking the class.This question is from Vector Arithmetic in section Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT answer is (b) bool

Easy EXPLANATION - This is a SPECIALIZED version of VECTOR, which is used for elements of type bool and optimizes for space.

17.

How many types of output stream classes are there in c++?(a) 1(b) 2(c) 3(d) 4This question was addressed to me during an internship interview.I need to ask this question from Output Stream topic in portion Strings, Streams & Numerics in C++ of C++

Answer»

Right OPTION is (C) 3

The best I can explain: There are three output STREAM classes in c++. They are ostream, ofstream and ostrstream.

18.

What is the difference between unsigned int length() and unsigned int size()?(a) Returns a different value(b) They are same(c) Returns a different value but they are same(d) Returns a lengthI have been asked this question in homework.This interesting question is from Basic String topic in division Strings, Streams & Numerics in C++ of C++

Answer»

Correct ANSWER is (b) They are same

To explain I WOULD say: Both of them will return the LENGTH of strings in the same NOTATIONS.

19.

How many objects are used for input and output to a string?(a) 1(b) 2(c) 3(d) 4This question was addressed to me during an interview.Question is from File Streams and String Streams topic in section Strings, Streams & Numerics in C++ of C++

Answer»

Right choice is (C) 3

The explanation: The STRINGSTREAM, ostringstream, and istringstream OBJECTS are used for input and OUTPUT to a string.

20.

Which is an instantiation of the basic_string class template?(a) Character(b) String class(c) Memory(d) IteratorThis question was posed to me by my college director while I was bunking the class.I want to ask this question from String Characters in chapter Strings, Streams & Numerics in C++ of C++

Answer» RIGHT ANSWER is (b) STRING class

To EXPLAIN I would say: The string class is an instantiation of the basic_string class template.
21.

How many streams are automatically created when executing a program?(a) 1(b) 2(c) 3(d) 4I got this question in an interview for job.This question is from C Input Output topic in section Strings, Streams & Numerics in C++ of C++

Answer»

The correct option is (c) 3

For EXPLANATION: There are streams that are AUTOMATICALLY created when executing a program. They are stdin, stdout and stderr.

22.

Which header file is used with input and output operations of C in C++?(a) stdio.h(b) cstdio(c) iostream(d) streamioI got this question during a job interview.This interesting question is from C Input Output topic in section Strings, Streams & Numerics in C++ of C++

Answer»

Right option is (B) cstdio

Explanation: Input and OUTPUT operations of c can be performed in C++ using the C Standard Input and Output LIBRARY.

23.

Where does a cin stops it extraction of data?(a) By seeing a blank space(b) By seeing ((c) By seeing a blank space & ((d) By seeing

Answer»

Right OPTION is (a) By seeing a blank SPACE

The best explanation: cin will STOP its extraction when it encounters a blank space.

24.

Which of the following is not used as a file opening mode?(a) ios::trunc(b) ios::binary(c) ios::in(d) ios::ateI have been asked this question in an online interview.My doubt stems from File Handling topic in section Strings, Streams & Numerics in C++ of C++

Answer»

Right option is (a) ios::TRUNC

The EXPLANATION is: ios::trunc is USED to TRUNCATE a file if it exists. It is not a file opening mode.

25.

How many categories are available in facets?(a) 4(b) 5(c) 6(d) 3I got this question in an online interview.The question is from Locale topic in section Strings, Streams & Numerics in C++ of C++

Answer»

The correct option is (c) 6

To explain: There are 6 CATEGORIES of FACET in c++. They are collate, ctype, MONETARY, numeric, TIME and MESSAGES.

26.

What is meant by ofstream in c++?(a) Writes to a file(b) Reads from a file(c) Writes to a file &Reads from a file(d) delete a fileThis question was posed to me in an interview.The question is from Output Stream topic in chapter Strings, Streams & Numerics in C++ of C++

Answer» RIGHT option is (a) WRITES to a file

Easy EXPLANATION - OFSTREAM is a stream class to write on FILES.
27.

Which function is used in C++ to get the current position of file pointer in a file?(a) tell_p()(b) get_pos()(c) get_p()(d) tell_pos()I had been asked this question in an interview.This intriguing question comes from File Handling in portion Strings, Streams & Numerics in C++ of C++

Answer»

Right option is (a) tell_p()

Explanation: C++ PROVIDES tell_p() function to get the CURRENT position of the FILE POINTER in a file.

28.

By default, all the files in C++ are opened in _________ mode.(a) Text(b) Binary(c) ISCII(d) VTCI got this question in examination.The query is from File Handling in section Strings, Streams & Numerics in C++ of C++

Answer»

The correct option is (a) TEXT

To EXPLAIN: By DEFAULT, all the files in C++ are opened in text mode. They read the FILE as normal text.

29.

What will act as a intermediate between i/o operations and physical file?(a) Memory(b) Ram(c) Stream buffer(d) StorageThis question was addressed to me in an interview for internship.Origin of the question is Buffering topic in division Strings, Streams & Numerics in C++ of C++

Answer»

Correct answer is (c) STREAM buffer

The best I can EXPLAIN: A stream buffer is a block of data that ACTS as INTERMEDIARY between the i/o operations and the physical file associated to the stream.

30.

What will be the type of output of vector cross product?(a) Scalar(b) Vector(c) Both Scalar & Vector(d) LinearThe question was asked in an online quiz.Question is taken from Vector Arithmetic in section Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT answer is (b) VECTOR

Easiest EXPLANATION - Cross product of two vectors results into a vector.

31.

Which of the following mathematical function is overloaded in and ?(a) cos(b) tan(c) sin(d) modI had been asked this question in an interview for job.The above asked question is from Standard Mathematical Functions in chapter Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT choice is (B) tan

The explanation is: Because tan has more DIFFERENT definition in NORMAL case and in case of complex NUMBER i.e. tan = sin/cos(normally) and tan = y/x in complex numbers.

32.

Which header file is required for manipulation of math functions in c++?(a) cmath(b) maths(c) math(d) dmathThe question was asked in a job interview.This interesting question is from Standard Mathematical Functions in portion Strings, Streams & Numerics in C++ of C++

Answer» CORRECT choice is (a) cmath

Explanation: #INCLUDE is a HEADER file REQUIRED for MANIPULATION of math functions.
33.

Where are standard C libraries defined in C++?(a) Container(b) std namespace(c) list(d) iteratorsThis question was posed to me during a job interview.I would like to ask this question from C Standard Library in section Strings, Streams & Numerics in C++ of C++

Answer»

Correct answer is (b) std NAMESPACE

To explain I would say: EVERY ELEMENT of the C LIBRARY is defined within the std namespace.

34.

Which character is used to terminate the string?(a) $(b) Null(c) Empty(d) @This question was posed to me during an interview.Enquiry is from String Characters topic in division Strings, Streams & Numerics in C++ of C++

Answer»

Right answer is (b) Null

The best EXPLANATION: A STRING of CHARACTERS is stored in successive elements of a character ARRAY are TERMINATED by the NULL character.

35.

What type of reference should be used in vector arithmetic?(a) dynamic(b) const(c) both dynamic & const(d) staticThe question was posed to me in an international level competition.The query is from Vector Arithmetic topic in chapter Strings, Streams & Numerics in C++ of C++

Answer»

Correct choice is (B) CONST

Explanation: As we are using the vector and it will give accurate RESULT if we USE const reference.

36.

Which header file is used to manipulate the vector algebra in c++?(a) math(b) cmath(c) vmath(d) dmathThis question was addressed to me in exam.Question is from Vector Arithmetic topic in portion Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT choice is (C) vmath

Best explanation: vmath is set of C++ classes for VECTOR and Matrix ALGEBRA USED in the programs.

37.

Which will be used with physical devices to interact from C++ program?(a) Programs(b) Library(c) Streams(d) IteratorsThis question was addressed to me in final exam.My question is based upon C Input Output in portion Strings, Streams & Numerics in C++ of C++

Answer»

The correct CHOICE is (c) Streams

Easiest explanation - C++ library uses streams to OPERATE with physical devices such as KEYBOARDS, Printers, Terminals or with any other type of FILES SUPPORTED by the system.

38.

Which one is always faster in writing on C++?(a) Writing to a file(b) Writing to memory(c) Reading from the network(d) Deleting a fileI got this question during an interview.The doubt is from Buffering in section Strings, Streams & Numerics in C++ of C++

Answer»

Correct choice is (b) Writing to MEMORY

The EXPLANATION is: For the stand of file operations, writing to memory (RAM) is always FASTER than writing to the file on the DISK directly.

39.

How many parameters are there in getline function?(a) 1(b) 2(c) 2 or 3(d) 3The question was asked by my school teacher while I was bunking the class.I'd like to ask this question from Input Stream topic in portion Strings, Streams & Numerics in C++ of C++

Answer»

Correct choice is (C) 2 or 3

Easiest EXPLANATION - There are TWO or three parameters in getline() function. They are a POINTER to an ARRAY of characters and maximum number of characters and an optional delimiter.

40.

Which header file is required to use file I/O operations?(a) (b) (c) (d) I had been asked this question by my college director while I was bunking the class.My doubt is from File Handling in division Strings, Streams & Numerics in C++ of C++

Answer» RIGHT CHOICE is (C)

Best explanation: header file is needed to use file I/O OPERATIONS in C++. This header file contains all the file I/O operations definition.
41.

Which mathematics library is used for vector manipulation in c++?(a) cli++(b) vec++(c) blitz++(d) stac+++I have been asked this question during an interview for a job.This interesting question is from Generalized Numeric Algorithms in portion Strings, Streams & Numerics in C++ of C++

Answer»

The correct OPTION is (C) BLITZ++

Explanation: Blitz++ is a high-performance vector MATHEMATICS LIBRARY written in C++.

42.

By using which function does the buffer are automatically flushed?(a) fopen(b) copy(c) compare(d) fcloseThis question was addressed to me in an interview.This intriguing question originated from Buffering topic in division Strings, Streams & Numerics in C++ of C++

Answer» CORRECT option is (d) fclose

The best I can EXPLAIN: fclose() is used to close the file and FLUSH it out of memory for safe CLOSING of FILES opened during the execution of program. In short to avoid memory faults during the execution of the program.
43.

Which function is used to position back from the end of file object?(a) seekg(b) seekp(c) both seekg & seekp(d) seekfI had been asked this question by my school teacher while I was bunking the class.My doubt stems from File Streams and String Streams topic in section Strings, Streams & Numerics in C++ of C++

Answer» CORRECT OPTION is (a) seekg

To explain: The MEMBER function seekg is used to position back from the end of FILE object.
44.

Which is used to get the input during runtime?(a) cout(b) cin(c) coi(d) cinoutI got this question during an online exam.My doubt stems from Input Stream in portion Strings, Streams & Numerics in C++ of C++

Answer» RIGHT option is (b) cin

The EXPLANATION is: cin is MAINLY USED to get the INPUT during the runtime.
45.

How many elements does a floating point number is composed of?(a) 1(b) 2(c) 3(d) 4I have been asked this question in an online interview.This intriguing question originated from C Standard Library topic in chapter Strings, Streams & Numerics in C++ of C++

Answer»

The correct choice is (d) 4

The best I can EXPLAIN: The floating POINT NUMBER composed of four ELEMENTS. They are sign, Base, Significand and EXPONENT.

46.

Which of the following is the default mode of the opening using the fstream class?(a) ios::in(b) ios::out(c) ios::in|ios::out(d) ios::truncThis question was posed to me during an online interview.The origin of the question is File Handling topic in chapter Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT choice is (c) ios::in|ios::out

For explanation: By DEFAULT, the FILE is opened in ios::in|ios::out mode if the file object we are USING is of fstream CLASS.

47.

Which of the following is the default mode of the opening using the ifstream class?(a) ios::in(b) ios::out(c) ios::app(d) ios::truncThe question was asked in exam.My query is from File Handling topic in section Strings, Streams & Numerics in C++ of C++

Answer»

Correct answer is (a) ios::in

Explanation: By DEFAULT, the FILE is opened in ios::in MODE if the file object we are USING is of IFSTREAM class.

48.

How many parameters are available in partial_sum function in c++?(a) 2(b) 3(c) 2 or 3(d) 3 or 4This question was addressed to me in quiz.The question is from Generalized Numeric Algorithms in section Strings, Streams & Numerics in C++ of C++

Answer»

The correct option is (d) 3 or 4

The explanation: There are three or four parameters available in partial_sum FUNCTION in C++. They are first and last element, RESULT and an optional binary OPERATOR.

49.

To which type does the numeric limits are suitable?(a) Character types(b) Mixed type(c) Arithmetic types(d) Relational typesI got this question in a national level competition.Query is from Numeric Limits topic in section Strings, Streams & Numerics in C++ of C++

Answer»

The CORRECT option is (c) ARITHMETIC TYPES

To explain I WOULD say: Numeric limits provides the information about the PROPERTIES of arithmetic types.

50.

Which operator is used for input stream?(a) >(b) >>(c)

Answer»

The CORRECT choice is (B) >>

For explanation: The OPERATOR of extraction is >> and it is used on the STANDARD input STREAM.