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

Paper Solution(1 Mark)

Uploaded by

mohanbrana894
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Paper Solution(1 Mark)

Uploaded by

mohanbrana894
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

C++ Question & Answer (1 Mark)

1. What is POP/C?
Procedural Oriented Programming is a programming language that follows a step-by-step approach to break
down a task into a collection of variables and routines (or subroutines) through a sequence of instructions.

2. What is C++/OOP?
Object-oriented Programming is a programming language that uses classes and objects to create models
based on the real world environment. In OOPs it makes it easy to maintain and modify existing code as new
objects are created inheriting characteristics from existing ones.

3. What is reference variable?


Reference variable is an alternate name of already existing variable. It cannot be changed to refer another
variable and should be initialized at the time of declaration and cannot be NULL. The operator ‘&’ is used to
declare reference variable.

4. what is symbolic constant?


c++ any value declared as constant(const) can not be modified by the program in any way.
const float pi=3.14;
#define pi 3.14

5. What is main function?


main() function is the entry point of any C++ program. It is the point at which execution of program is
started. When a C++ program is executed, the execution control goes directly to the main() function. Every
C++ program have a main() function.
Syntax:
void main()
{
............
............
}

6. What is Namespace?

Namespaces in C++ are used to organize too many classes so that it can be easy to handle the
application.
For accessing the class of a namespace, we need to use namespacename::classname. We can
use using keyword so that we don't have to use complete name all the time.

In C++, global namespace is the root namespace. The global::std will always refer to the namespace
"std" of C++ Framework.

7. What is Derived data type?

8. What is Identifier?
C++ identifiers in a program are used to refer to the name of the variables, functions, arrays, or other user-
defined data types created by the programmer. They are the basic requirement of any language. Every
language has its own rules for naming the identifiers.

9. What is MIL?
Member Initialization List
Initialize List is used in initializing the data members of a class.

10. What is Local Class?


A class declared inside a function becomes local to that function and is called Local Class in C++.

11. What is Nested Class?


A nested class is a class that is declared in another class.
12. What is Member Function?
Member functions are operators and functions that are declared as members of a class.

13. What is Static Data Member?


Static data members are class members that are declared using static keywords. A static member has certain
special characteristics. These are: Only one copy of that member is created for the entire class and is shared
by all the objects of that class, no matter how many objects are created.

14. What is Friend/Friendly Function?


A friend function of a class is defined outside that class' scope but it has the right to access all private and
protected members of the class. Even though the prototypes for friend functions appear in the class
definition, friends are not member functions.

15. What is Explicit Constructor?


Invoked constructor by using two ways:
1. Implicit
Ex: A a1(2,3); //call implicitly
2. Explicit
A a1=A(10,5); //call explicitly
A is a constructor and a1 is object for that

16. What is Copy Constructor?


In the below cases we can use copy constructor.
1. When creating one object from an existing object of the same type.
2. When you pass an object by value to a function.
3. When a function returns an object.

17. What is Derived Class?


A derived class is a class created or derived from another existing class. The existing class from which the
derived class is created through the process of inheritance is known as a base class or superclass.

18. What is Type Conversion?


C++ allows us to convert data of one type to that of another. This is known as type conversion.

There are two types of type conversion in C++.

1. Implicit Conversion
2. Explicit Conversion (also known as Type Casting)
19. What is Single Inheritance?
If a single class is derived from one base class then it is called single inheritance. In C++ single inheritance base
and derived class exhibit one to one relation.

20. What is Hybrid Inheritance?


Hybrid Inheritance is the combination of two or more inheritances: single, multiple,multilevel or hierarchical .

21. What is Abstract Class?


An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at
least one pure virtual function.

22. What is Multi Level Inheritance?


If a class is derived from another derived class, it is called multilevel inheritance.
23. What is Containership?
The parameter if a certain class contains another class is called as containership. The inside class is called
contained class, while the class in which it is present is called container class.

For Ex: 1. Computer system has a hard disk


2.Car has an Engine, chassis, and steering wheels.

24. What is Hierarchical Inheritance?


If more than one class is inherited from the one base class, it's known as hierarchical inheritance.

25. What is Pointer to Object?


A variable that holds an address value is called a pointer variable or simply pointer.
Pointer can point to objects as well as to simple data types and arrays.
We know that by using object and dot operator ( . ), we can call a member function of the class.

Now if we want to call a member function of a class with the help of pointer to object than it is possible
by two ways:
Arrow ( -> ) Operator (Member Access Operator ->)
Dot ( . ) Operator

26. What is Virtual Function?


If we use the same member function in both base and derived class then the function in base class is made
virtual.

27. What is C++ Stream?


In C++ stream refers to the stream of characters that are transferred between the program thread and i/o.

Stream classes in C++ are used to input and output operations on files and io devices. These classes have
specific features and to handle input and output of the program.

28. What is RTTI?


In C++, RTTI (Run-time type information) is a mechanism that exposes information about an object’s data type
at runtime and is available only for the classes which have at least one virtual function.
It allows the type of an object to be determined during program execution.

29. What is this pointer?


Every object in C++ has access to its own address through an important pointer called as this pointer.
This pointer stores the memory address of the object of the class.

30. What is pure virtual function?


A pure virtual function is a function declared in a base class which has no definition part in base class.
We cannot create object of the base class in the inheritance, the function in the base class is defined
“Empty”. So this type function is called as “Do nothing” function.
“Do nothing” functions are defined as
virtual void display() = 0;
“Do nothing” functions are also known as pure virtual functions.

31. What is a formatted I/O operation?


There are three types of formatted io operations.
1) ios class functions
2) Manipulators
3) User Defined Output Functions

32. What is use of manipulator?


Manipulators are helping functions that can modify the input/output stream. It does not mean that we change
the value of a variable, it only modifies the I/O.

33. What is a File Stream class?


We use the header file C++ provides the following classes to perform output and input of characters to/from
files:
1. ofstream: Stream class to write on files
2. ifstream: Stream class to read from files
3. fstream: Stream class to both read and write from/to files.

34. What is File Mode?


1. ios::in Open for input operations.
2. ios::out Open for output operations
3. ios::binary Open in binary mode.
4. ios::ate Set the initial position at the end of the file. If this flag is not set, the initial position is the
beginning of the file.
5. ios::app All output operations are performed at the end of the file, appending the content to the
current content of the file.
6. ios::trunc If the file is opened for output operations and it already existed, its previous content is
deleted and replaced by the new one.

35. What is a sequential I/O Operation?


 The file stream classes support a number of member functions for performing the input and output
operations on files.
 The functions get() and put() are capable of handling a single character at a time.
 The function getline() lets you handle multiple characters at a time.

36. What is a class template?


A class template starts with the keyword template followed by template parameter(s) inside <> which is
followed by the class declaration.

Syntax:
template <class T>
class className
{
private:
T var;
... .. ...
public:
T functionName(T arg);
... .. ...
};

37. What is Error Handling?


It is quite common that errors may occur while reading data from a file in C++ or writing data to a file.
For example, an error may arise due to the following:
 When trying to read a file beyond indicator.
 When trying to read a file that does not exist.
 When trying to use a file that has not been opened.
 When trying to use a file in an inappropriate mode i.e., writing data to a file that has been opened
for reading.
 When writing to a file that is write-protected i.e., trying to write to a read-only file.

38. What is File Pointer?


Each File has two Pointer:
1. Input Pointer (get Pointer)
2. Output Pointer (put Pointer)
We can use these pointers to move through the files while reading and writing.
Input Pointer (get Pointer): It is used for reading the contents of given file location.
Output Pointer (put Pointer): It is used for writing the contents of given file location.

39. What is Function template?


A function template starts with the keyword template followed by template parameter(s) inside <> which
is followed by the function definition.
Syntax:
template <typename T>
T functionName(T parameter1, T parameter2, ...)
{
// code
}

40. What is Exception Handling?


An exception is a problem that arises during the execution of a program. A C++ exception is a response to
An exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.

41. Wrapping up of data and function together is known as


Encapsulation

42. When c++ was released?


In 1985 by Bjarne Stroustrup

43. Give name and symbol of output operator


Name: cout
Symbol: cout<<”hello”;

44. Full Form of OOP.


Object Oriented Programming
45. A class is ________ Data type.
User defined

46. The member function inside the body of the class is automatically become.
Private

47. Friend function can access any private member (true / false)
A function which can access all the private, protected and public members of a class.
Answer is true

48. class C: public A, public B is example of ____________


Hierarchical Inheritance

49. When class is derived from more than one from of inheritance then it called
___________
Multiple Inheritance

50. ___________ Keyword IS used multipath inheritance to avoid ambiguity.


Virtual

51. Inheritance is the concept of _________


Code Reusability

52. Which type of class cannot created any instance?


Abstract class

53. What is the output?


void main( )
{
char *s2="krishty";
char *s1="patel";
strcat(s1,s2);
cout<<s1;
}
Output: patelkrishty
54. What is the output?

55. The base class for most stream classes is the class.
ios class

56. The mode is used to open a file for reading.


Ios::in

57. Full name STL.


Standard template library

58. ________Function return true if operation is successful in file without any


error.
good( )

59. Which block is received the enol' information in exception handling?


Catch block

60. To use the setw manipulator, you have to include the _________ header file.
iomanip.h

61. Give syntax of new operator.


The new operator denotes a request for memory allocation on the Free Store. If sufficient memory is available,
a new operator initializes the memory and returns the address of the newly allocated and initialized memory to
the pointer variable.

Syntax to use new operator


data-type pointer-variable = new data-type;

62. Define: Data Encapsulation.


Wrapping up of data and function together is known as Data Encapsulation.

63. What is dynamic initialization of objects?


Dynamic initialization of object refers to initializing the objects at a run time i.e., the initial value of an object is
provided during run time.

64. Friend function can declare in public section only. (True/False)


False
65. Give syntax to define a member function outside the class.
return_type class_name::function_name(parameters)
{
function_body;
}

66. The destructor is written by specifying a ____________ SIgn before its name.
~
67. Operator overloading is also known by the term ____________.
Compile time

68. Overloading a unary operator using member function will require ________
arguments.
No arguments

69. List out manipulator functions.


setw (val): It is used to set the field width in output operations.
setfill (c): It is used to fill the character ‘c’ on output stream.
setprecision (val): It sets val as the new value for the precision of floating-point values.

70. Give difference between get() and getline().

71. Which function returns the current position of the output pointer?
tellg() function

72. Give syntax of seekg() function


seekg(Position,Mode);

You might also like