A bit copy of an object is an exact, bit-by-bit, copy of that object. The default copy constructor generated by the compiler makes a bit copy.
This is potentially a problem if the object contains pointers to other objects...
A bit copy of a pointer copies the pointer, but not its data. This means that you have two pointers pointing at the same object in memory. If you delete one of them, the other becomes invalid, and this can (usually does) cause corruption.
If an object contains a pointer, the object's copy constructor should provide for proper allocation and copying of any pointed to objects within that object.
Does break statement terminate only the inner loop in c?
Yes. Break terminates only the innermost control structure, loop, switch, etc. If you want to break out of nested control structures, you can set a variable to induce a second break, or you can throw an exception.
The only things that may be different for all objects of a class are their member variables. They represent the object's data. The only things that remain the same are the static members -- they are akin to global variables, but are local to all objects of the class type.
A C plus plus program is a collection of one or more what?
A C plus plus program is a collection of one or more translation units. Every C++ program requires at least one translation unit that defines the global main function, the entry point of the application. Typically, the global main function is used to parse any command line switches and delegate primary operations to one or more lower-level functions.
A translation unit is the smallest unit that can be processed by the C++ compiler. During compilation, only those units that have changed since the previous compilation need be recompiled. A unit is essentially a source file (typically a *.cpp file) and source files are typically divided up by the classes and/or functions they define, thus allowing programmers to create self-contained code modules that can used by other applications. Typically, a source file has a corresponding header file (typically a *.h file) which must be included by the source file (using the #include precompiler directive). The header typically describes the translation unit's interface and may be included in other translation units that require access to that interface.
A class is a user-defined type, in much the same way that an int or float is a built-in type. The class definition describes the type's representation and interface; the operations that are valid for the type. Class interfaces are typically defined in header files and implemented in source files. However, class templates need to be completely defined in the header as these are used by the compiler to generate types at the point of instantiation and the compiler needs to "see" the complete template definition in advance of any usage of that template.
Why doesn't the main function need a prototype statement?
Because we usually don't call it from the program, but if we do, you should have a prototype:
int main (int argc, char **argv);
int foobar (const char *progname)
{
char *param[2];
...
param[0]= progname;
param[1]= "help";
main (2, param);
...
}
int main (int argc, char **argv)
{
...
foobar (argv[0]);
...
}
How do you search a character in a inputted string?
#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::getline;
int main()
{
string myString = "";
cout << "Enter a string: ";
getline(cin, myString);
char mySymbol = 'a';
cout << "Enter a symbol to search for: ";
mySymbol = getchar();
bool symbolFound = false;
for (int index = 0; index < myString.length(); index++)
{
if (mySymbol false)
{
cout << "The symbol " << mySymbol << " was not found!";
}
cin.get();
cin.get();
return 0;
}
Why a static data member can be accessed through main?
Static data members are local to the class, not to any instance of the class. That is, you do not need to instantiate an object of the class to access them. They are shared variables, not unlike global variables, the only difference being that that can also be hidden behind static member accessors and/or mutators (get and set methods) of the class. However, a public static data member is a global variable in all but name.
Since they do not belong to any instance of the class, they must be initialised outside of the class, and outside of any other code blocks. In other words, they are initialised at compile time and are therefore available at runtime, and can therefore be accessed from the main function if a public interface is implemented or the member is declared public. If it is declared private, the variable is treated as a shared variable that is only accessible to all static members of the class, to all instances of the class and to all friends of the class. If declared protected, it is also accessible to derived classes.
How you can use while loop in place of select case?
While is NOT a replacement for SWITCH -- CASE
However , still if this is the requirement then , you can do this :
While (1)
{
if (case1 ) {}
if (case2 ) {}
:
:
:
if (case n ) {}
if (case default ) {}
} //end of while loop
There are several ways to do this in C:
// nums to swap
int a = 5;
int b = 10;
// using a temporary variable - often the fastest method
int temp;
temp = a;
a = b;
b = temp;
// using addition (no additional storage needed)
a = a + b;
b = a - b;
a = a - b;
// using xor (no additional storage needed)
a = a^b;
b = a^b;
a = a^b;
// using only one line (no additional storage needed) // note, this appears to be a compiler-dependent way to swap variables
a = a + b - (b=a);
Can the parameter of the copy constructor be passed by value?
No. The parameter of the copy constructor is always passed by reference, specifically, a const reference to the class.
Think about it. If it were passed by value, then the compiler would already know how to copy the object into the formal parameter, but the purpose of the copy constructor is to provide the code to copy the object, so its kind of a "cart before the horse" thing to think about call by value here.
What is meant by interface of a class and implementation of a class in c plus plus?
The interface of a class is defined as being the methods that allow the outside world to interact with objects instantiated from that particular class type. That interface may be declared within the class itself or it may be inherited from base classes, or it may be some combination of the two. The interface may also be virtual or even pure-virtual, either in whole or in part.
The implementation determines how that interface operates. Although the interface and the implementation go hand-in-hand they are treated separately because a derived class can override the generic interface exposed by the base class in order to provide a more specialised implementation of the base class interface, as well as provide new interfaces of its own.
The generic interface needn't be virtual in order to be overridden, but it must be virtual in order to allow polymorphic behaviour. Where the base class cannot provide an implementation because it is intentionally abstract and therefore relies solely upon a derived implementation, it will provide a pure-virtual interface that absolutely must be implemented by all derivatives. If a class declares or inherits a pure-virtual interface with no implementation, that class automatically becomes abstract. Only classes that provide a complete implementation for all pure-virtual interfaces (including any generic implementations inherited from base classes derived from the base class), can actually be instantiated.
When calling a base class method from a non-member function, one would rightly expect the implementation of the derived class to be executed. In order to achieve this, the generic interface must be virtual and the virtual table ensures the call is routed to the correct implementation. Without this, only the base class method can be called, which may result in unexpected behaviour in the derived class since the base class would be unaware of its specific behaviour.
While it is possible to allow a base class to gain access to a derived class interface without exposing a virtual interface, this can only be done when the base class already knows exactly what type of derivative to expect. Knowing the type of its derivative allows the base class to make an explicit dynamic cast of itself in order to call the appropriate interface. But it cannot predict the future: if you derive a new class of object that it knowns nothing about, it cannot gain access to its specialised interface. Even dynamic casting is impossible without knowing what type of object to cast to. Virtual interfaces overcome this problem by ensuring that no matter what derivatives are created either now or in the future, the base class can access each of their specific implementations through just one generic interface, without the need for any dynamic casting (which is almost always a sign of poor design).
When a base class interface is routed to a derived class implementation, that specific implementation has complete access to the derived class' interface. Thus interfaces that the base class doesn't even know exist can be implemented via calls through the base class' virtual interface which is the only interface the base class really needs to know anything about. To put it another way, all derivatives of the same base class can be treated just as if they were the base class itself, with a common, generic interface, and yet each instance can exhibit entirely different behaviour, according to the specific implementations defined by each derivative. That is, one interface/multiple implementations.
Derived class implementations may also, optionally, call any base class method and access any base class variable (other than the base class' private members, of course). This makes it possible to provide a generic implementation of the virtual interface that can then be augmented or replaced completely by the more specific implementations of the derived interface. Even pure-virtual methods, which are normally not implemented in an abstract base class, can provide a generic implementation where appropriate. Although the implementation cannot be inherited, the interface must be inherited because it is virtual. However, once a derived class implements a pure-virtual interface, that implementation can then be inherited by its derivatives, to be further specialised and or augmented as necessary.
Program for derived class in cpp?
#include<iostream>
class base
{
int m_data;
public:
base(const int data):m_data(data){}
base(const base& cpy):m_data(cpy.m_data){}
base& operator=(const int rhs){m_data=rhs;return(*this);}
base& operator=(const base& rhs){m_data=rhs.m_data;return(*this);}
virtual ~base(){}
};
class derived
{
public:
derived(const int data):base(data){}
derived(const derived& cpy):base(cpy){}
derived& operator=(const int rhs){return(base::operator=(rhs));}
derived& operator=(const derived& rhs){return(base::operator=(rhs));}
virtual ~derived(){}
};
int main()
{
derived d=42;
}
Which header file must be included to use the function pow?
The std::pow() function can be found in the <cmath> header.
Polymorphism is used whenever you wish to achieve specific behaviour from a generic object, where the object's actual type may not be known or would be impossible to determine at compile time. By declaring virtual methods in the generic type (the base class), and overriding them in the derived type, you ensure that the derived object does "the right thing" regardless of its actual type, and regardless of whether the method is called directly or indirectly via the base class. With polymorphism, there is no need to determine the actual runtime type of the object, you get that for free simply by calling the appropriate virtual methods.
Sorting in programming is the process of arranging elements in some prescribed order.
An example might be, given arrays of people's names and birthdates, to sort them by birthdate.
You can do this by creating a forwarddeclaration of the function. You can call the forward drclared function inside the main to use it.
int result(float num1, float num2);
int
main(void)
{
int value = result(3.14, 2.74);
return (0);
}
int
result(float num1, float num2)
{
int value = 0;
// function codes goes here
// you can alter the value of variable 'value'
return (value);
}
The returning value of the 'result()' function is assigned to variable 'value' in 'main()'.
What is the function of the shift plus tab?
<Shift><Tab> takes you backwards through the tab order instead of forwards.
How do DriveSpy specify file headers?
The file header section conatins the hexidecimal number values for many knownfile types. These hexidecimal numbers are the header data contained in the first several bytesof all specialized data files, such as Microsoft word documents or excel spreadsheets and any associated templates. The file header uniquely identifies the file type.
You can use the file header information in Drivespy to search for specific files that might have had their extensions changed.
Which type of programming error leads to garbage stink value in a c plus plus program?
The most common error in C/C++ is a buffer overrun. Even if no problems arise through normal use, hackers can exploit the overrun to inject their code into yours. While this can highlight the problem, not all hackers have good intentions...
Another common error is to assign instead of compare a value, due to the similarity between the operators. The compiler can't always see the problem and replicating the problem at runtime may not be obvious.
if( x = y) // should be x == y
{
// always executes
}
else
{
// never executes
}
What is the conversion 77f to c?
To convert F to C, subtract 32, then multiply by 5/9
77-32 = 45
45x5/9 = 25
Going the other way, to convert C to F
Multiply by 9/5, then add 32