0% found this document useful (0 votes)
31 views

Questions C ++: Compare and Contrast The Loops That Used A For With Those

This document contains questions about C++ concepts including: 1) The differences between for and while loops and their advantages/disadvantages. 2) Writing a lambda function that captures and decrements a local variable. 3) Explaining the differences between the three kinds of insert iterators.

Uploaded by

saurabh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Questions C ++: Compare and Contrast The Loops That Used A For With Those

This document contains questions about C++ concepts including: 1) The differences between for and while loops and their advantages/disadvantages. 2) Writing a lambda function that captures and decrements a local variable. 3) Explaining the differences between the three kinds of insert iterators.

Uploaded by

saurabh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

QUESTIONS C ++

1)

2)

3)
4)
5)
6)

Compare and contrast the loops that used a for with those
using a while. Are there advantages or disadvantages to using either
form?
Write a lambda that captures a local int variable and
decrements that variable until it reaches 0. Once the variable is 0
additional
calls should no longer decrement the variable. The lambda should
return a
bool that indicates whether the captured variable is 0.
Explain the differences among the three kinds of insert
iterators.
Use reverse_iterators to print a vector in reverse
order.
List the five iterator categories and the operations that each
supports.
Give an example of when each of list, vector, deque,
map, and set might be most useful.
1.
2.
3.
4.
5.
6.
7.

Use of this pointer


Explain what happens when a pointer is deleted twice - C++
What is a smart pointer?
Difference between an inspector and a mutator - C++
Pointer to constant vs. pointer constant - C++
What are function pointers?
What is pointer to member? - C++

8. What is const pointer and const reference? - C++


9. What is NULL pointer and void pointer and what is their use?
10. Which member function is used to determine whether the stream object is
currently associated with a file?
a) is_open
b) buf
c) string
d) None of the mentioned
11) By seeing which operator thus this program stops getting the input?
#include <iostream>
#include <fstream>

using namespace std;


int main ()
{
char ch;
streambuf * p;
ofstream os ("test.txt");
pbuf = os.rdbuf();
do {
ch = cin.get();
p -> sputc(ch);
} while (ch != '.');
os.close();
return 0;
}
a) dot operator
b) insertion operator
c) $ symbol
d) None of the mentioned
12) What is the output of this program?

#include <iostream>
using namespace std;
template<typename T>
void loopIt(T x)
{
int count = 3;
T val[count];
for (int ii=0; ii < count; ii++)
{
val[ii] = x++;
cout << val[ii] << endl;
}
};
int main()
{

float xx = 2.1;
loopIt(xx);
}
13) How many streams are automatically created when executing a program?
a) 1
b) 2
c) 3
d) 4

14) What is the output of this program in the text file?


#include <stdio.h>
int main ()
{
FILE * pFile;
char c;
pFile = fopen("sample.txt", "wt");
for (c = 'A'; c <= 'E'; c++)
{
putc (c, pFile);
}
fclose (pFile);
return 0;
}
a)ABCD
b)ABC
c)ABCDE
d) None of the mentioned

You might also like