1. What will be the output of the following C++ code by manipulating the text file?
#include <stdio.h>
int main ()
{
if (remove( "myfile.txt" ) != 0 )
perror( "Error" );
else
puts( "Success" );
return 0;
}
#include <stdio.h>
int main ()
{
if (remove( "myfile.txt" ) != 0 )
perror( "Error" );
else
puts( "Success" );
return 0;
}2. Pick out the in correct type of function in header file.
3. What will act as a intermediate between i/o operations and physical file?
4. What will happen when an exception is not processed?
5. Which operator is used to insert the data into file?
6. What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
int mycount = count (myints, myints + 8, 10);
cout << mycount;
vector<int> myvector (myints, myints + 8);
mycount = count (myvector.begin(), myvector.end(), 20);
cout << mycount;
return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
int mycount = count (myints, myints + 8, 10);
cout << mycount;
vector<int> myvector (myints, myints + 8);
mycount = count (myvector.begin(), myvector.end(), 20);
cout << mycount;
return 0;
}7. What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
class A
{
public:
A(){
cout<<"Created\n";
}
~A(){
cout<<"Destroyed\n";
}
};
int main(int argc, char const *argv[])
{
A <int>a1;
A <char>a2;
A <float>a3;
return 0;
}
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
template<class T>
class A
{
public:
A(){
cout<<"Created\n";
}
~A(){
cout<<"Destroyed\n";
}
};
int main(int argc, char const *argv[])
{
A <int>a1;
A <char>a2;
A <float>a3;
return 0;
}8. What will be the output of the following C++ code in text file?
#include <stdio.h>
int main ()
{
FILE * p;
char buffer[] = { 'x' , 'y' , 'z' };
p = fopen ( "myfile.txt" , "wb" );
fwrite (buffer , 1 , sizeof(buffer) , p );
fclose (p);
return 0;
}
#include <stdio.h>
int main ()
{
FILE * p;
char buffer[] = { 'x' , 'y' , 'z' };
p = fopen ( "myfile.txt" , "wb" );
fwrite (buffer , 1 , sizeof(buffer) , p );
fclose (p);
return 0;
}Read More Section(C plus plus miscellaneous)
Each Section contains maximum 100 MCQs question on C plus plus miscellaneous. To get more questions visit other sections.
- C plus plus miscellaneous - Section 1
- C plus plus miscellaneous - Section 2
- C plus plus miscellaneous - Section 3
- C plus plus miscellaneous - Section 4
- C plus plus miscellaneous - Section 5
- C plus plus miscellaneous - Section 6
- C plus plus miscellaneous - Section 7
- C plus plus miscellaneous - Section 8
- C plus plus miscellaneous - Section 9
- C plus plus miscellaneous - Section 10
