Addison Wesley - C++ Common Knowledge Essential Intermediate Programming . Addison Wesley - Effcient C++ Performance Programming portal7.info The C++ programming language is thus platform-independent in the main with a majority In order to test and expand your acquired knowledge, you can download sample pro- grams and . common mistakes and how to avoid making them. General Structure of a Simple C++ Program. current standard URL is http ://portal7.info sophisticated software with little or no interest or knowledge of the actual computer system.
|Language:||English, Spanish, German|
|ePub File Size:||28.40 MB|
|PDF File Size:||9.13 MB|
|Distribution:||Free* [*Sign up for free]|
“We live in a time when, perhaps surprisingly, the best printed works on C++ are just now emerging. This is one of those works. Although C++ has been at the. From C++ Common Knowledge. Item Pointers to Class Members Are Not Pointers. It's unfortunate that pointers to class members have the term "pointer" in . This book introduces embedded systems to C and C++ programmers. the detailed explanations and source code solutions to common embedded software The book does not assume that you have a great deal of knowledge about.
Object Oriented Programming System. What is a class? Class is a blue print which reflects the entities attributes and actions. Technically defining a class is designing an user defined data type. What is an object?
Only public inheritance corresponds to what is usually meant by "inheritance". The other two forms are much less frequently used.
If the access specifier is omitted, a "class" inherits privately, while a "struct" inherits publicly. Base classes may be declared as virtual; this is called virtual inheritance. Virtual inheritance ensures that only one instance of a base class exists in the inheritance graph, avoiding some of the ambiguity problems of multiple inheritance. Some other languages, such as C or Java , accomplish something similar although more limited by allowing inheritance of multiple interfaces while restricting the number of base classes to one interfaces, unlike classes, provide only declarations of member functions, no implementation or member data.
The member functions of such an abstract base class are normally explicitly defined in the derived class, not inherited implicitly. Almost all operators can be overloaded for user-defined types, with a few notable exceptions such as member access.
Overloading an operator does not change the precedence of calculations involving the operator, nor does it change the number of operands that the operator uses any operand may however be ignored by the operator, though it will be evaluated prior to execution.
Polymorphism enables one common interface for many implementations, and for objects to act differently under different circumstances.
Compile-time polymorphism does not allow for certain run-time decisions, while runtime polymorphism typically incurs a performance penalty. Function overloading allows programs to declare multiple functions having the same name but with different arguments i. The functions are distinguished by the number or types of their formal parameters. Thus, the same function name can refer to different functions depending on the context in which it is used. The type returned by the function is not used to distinguish overloaded functions and would result in a compile-time error message.
When declaring a function, a programmer can specify for one or more parameters a default value.
Doing so allows the parameters with defaults to optionally be omitted when the function is called, in which case the default arguments will be used. When a function is called with fewer arguments than there are declared parameters, explicit arguments are matched to parameters in left-to-right order, with any unmatched parameters at the end of the parameter list being assigned their default arguments.
In many cases, specifying default arguments in a single function declaration is preferable to providing overloaded function definitions with different numbers of parameters.
In particular, through the curiously recurring template pattern , it's possible to implement a form of static polymorphism that closely mimics the syntax for overriding virtual functions. Contrary to some opinion, template code will not generate a bulk code after compilation with the proper compiler settings. This allows arrays and other kinds of containers to hold pointers to objects of differing types references cannot be directly held in containers.
This enables dynamic run-time polymorphism, where the referred objects can behave differently depending on their actual, derived types. The attempt is necessary as often one does not know which derived type is referenced. Ordinarily, when a function in a derived class overrides a function in a base class, the function to call is determined by the type of the object. A given function is overridden when there exists no difference in the number or type of parameters between two or more definitions of that function.
Hence, at compile time, it may not be possible to determine the type of the object and therefore the correct function to call, given only a base class pointer; the decision is therefore put off until runtime. This is called dynamic dispatch. Virtual member functions or methods  allow the most specific implementation of the function to be called, according to the actual run-time type of the object.
If the object type is known, this may be bypassed by prepending a fully qualified class name before the function call, but in general calls to virtual functions are resolved at run time.
In addition to standard member functions, operator overloads and destructors can be virtual. As a rule of thumb, if any function in the class is virtual, the destructor should be as well. As the type of an object at its creation is known at compile time, constructors, and by extension copy constructors, cannot be virtual.
Nonetheless a situation may arise where a copy of an object needs to be created when a pointer to a derived object is passed as a pointer to a base object. In such a case, a common solution is to create a clone or similar virtual function that creates and returns a copy of the derived class when called. A class containing a pure virtual function is called an abstract class.
Objects cannot be created from an abstract class; they can only be derived from. Any derived class inherits the virtual function as pure and must provide a non-pure definition of it and all other pure virtual functions before objects of the derived class can be created. A program that attempts to create an object of a class with a pure virtual member function or inherited pure virtual member function is ill-formed.
The [ capture ] list supports the definition of closures. Such lambda expressions are defined in the standard as syntactic sugar for an unnamed function object. An example lambda function may be defined as follows:.
Exception handling is used to communicate the existence of a runtime problem or error from where it was detected to where the issue can be handled. The exception causes the current scope to be exited, and also each outer scope propagation until a suitable handler is found, calling in turn the destructors of any objects in these exited scopes. The exception-causing code is placed inside a try block. The exceptions are handled in separate catch blocks the handlers ; each try block can have multiple exception handlers, as it is visible in the example below.
It is also possible to raise exceptions purposefully, using the throw keyword; these exceptions are handled in the usual way. In some cases, exceptions cannot be used due to technical reasons.
One such example is a critical component of an embedded system, where every operation must be guaranteed to complete within a specified amount of time.
This cannot be determined with exceptions as no tools exist to determine the maximum time required for an exception to be handled. Useful tools provided by the STL include containers as the collections of objects such as vectors and lists , iterators that provide array-like access to containers, and algorithms that perform operations such as searching and sorting.
Furthermore, multi maps associative arrays and multi sets are provided, all of which export compatible interfaces. Therefore, using templates it is possible to write generic algorithms that work with any container or on any sequence defined by iterators. As in C, the features of the library are accessed by using the include directive to include a standard header. The standard incorporates the STL that was originally designed by Alexander Stepanov , who experimented with generic algorithms and containers for many years.
The downside of this decision is that object code produced by different compilers is expected to be incompatible. Such a function may not rely on features depending on name mangling i. As expressed by Joshua Bloch:.
But what you do is you force people to subset it. The problem that I have with them today is that At the moment, it's impossible for me to write portable code that I believe would work on lots of different systems, unless I avoid all exotic features.
So the language is too baroque for my taste. Ken Thompson , who was a colleague of Stroustrup at Bell Labs, gives his assessment: It certainly has its good points. Stroustrup campaigned for years and years and years, way beyond any sort of technical contributions he made to the language, to get it adopted and used. And he sort of ran all the standards committees with a whip and a chair.
He put every feature in that language that ever existed. And I think it suffered drastically from that. However Brian Kernighan , also a colleague at Bell Labs, disputes this assessment: Other complaints may include a lack of reflection or garbage collection , slow compilation times, perceived feature creep ,  and verbose error messages, particularly from template metaprogramming.
From Wikipedia, the free encyclopedia. For the Roman numerals, see number. Main article: See also: Template metaprogramming and Generic programming.
Polymorphism computer science. Parametric polymorphism and ad hoc polymorphism. Further information: Computer programming portal. Journal of Computing Sciences in Colleges.
Cray Inc. Retrieved 14 January Archived from the original on Retrieved Chaudhary 28 July Retrieved 29 May Classes — Python 3. University of Edinburgh". Retrieved 12 June Retrieved 5 May International Organization for Standardization.
Retrieved 16 September InfoWorld, 10 February Retrieved 16 January Northeastern University. Archived from the original on 17 November Retrieved 7 September Sutter's Mill.
Stroustrup interviewed by Sergio De Simone 30 April Retrieved 8 July This code is copied directly from Bjarne Stroustrup's errata page p. Also see Can I write "void main "? This implicit return is not available in other functions. Part 5: Template Code Bloat". EmptyCrate Software. Retrieved 8 March I was thinking about it the other day and thought to myself, "self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?
Non-template version: Prentice Hall. A virtual member function is sometimes called a method. Cambridge Computer Laboratory - Course Materials Retrieved 30 August A namespace is the logical division of the code which can be used to resolve the name conflict of the identifiers by placing them under different name space. What are command line arguments?
All the arguments sent are the strings only. What is a class template? A template class is a generic class. The keyword template can be used to define a class template.
How can we catch all kind of exceptions in a single catch block? By default every local variable of the function is automatic auto. What is a static variable? A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice. What is the purpose of extern storage specifier. The starting address of the array is called as the base address of the array. When should we use the register storage specifier?
If a variable is used most frequently then it should be declared using register storage specifier, then possibly the compiler gives CPU register for its storage to speed up the look up of the variable. Can a program be compiled without main function? Yes, it can be but cannot be executed, as the execution requires main function definition. Where an automatic variable is stored? Every local variable by default being an auto variable is stored in stack memory What is a container class?
A class containing at least one member variable of another class type in it is called so. What is a token? What is a preprocessor? Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins. The arguments which we pass to the main function while executing the program are called as command line arguments. The parameters are always strings held in the second argument below in args of the function which is array of character pointers.
First argument represents the count of arguments below in count and updated automatically by operating system. Which to use when? We choose this if we do not want the actual parameters to be modified with formal parameters but just used. We choose this if we do want the actual parameters to be modified with formal parameters. What is reminder for 5. No, there is no such provision available. Bjarne Stroustrup. We can apply scope resolution operator :: to the for the scope of global variable.
What are valid operations on pointers? Function calling itself is called as recursion.
What is the first string in the argument vector w. Program name. What is the maximum length of an identifier? Ideally it is 32 characters and also implementation dependent. What is the default function call method? By default the functions are called by value. What are available mode of inheritance to inherit one class from another? Delete is used to release the array allocated memory which was allocated using new and delete is used to release one chunk of memory which was allocated using new.
Not necessarily, a class having at least one pure virtual function is abstract class too. Is it legal to assign a base class object to a derived class pointer? No, it will be error as the compiler fails to do conversion.
What happens if an exception is thrown outside a try block? The program shall quit abruptly. Are the exceptions and error same? No, exceptions can be handled whereas program cannot resolve errors. What is function overriding? Which function is used to move the stream pointer for the purpose of reading data from stream? No, only the class member variables determines the size of the respective class object.
Can we create and empty class? If so what would be the size of such object. We can create an empty class and the object size will be 1. What is the full form of STL? It is used to specify the namespace being used in. If a pointer declared for a class, which operator can be used to access its class members? What is the difference between actual and formal parameters?
The parameters sent to the function at calling end are called as actual parameters while at the receiving of the function definition called as formal parameters.
What is the difference between variable declaration and variable definition? Declaration associates type to the variable whereas definition gives the value to the variable. Which key word is used to perform unconditional branching?
Is a valid octal number? No, it contains invalid octal digits. What is the purpose of undef preprocessor? It will be used to undefine an existing macro definition. No, we cannot. What is a virtual destructor? A virtual destructor ensures that the objects resources are released in the reverse order of the object being constructed w. What is the order of objects destroyed in the memory? The objects are destroyed in the reverse order of their creation.
What is a friend class? What is Next? Further you can go through your past assignments you have done with the subject and make sure you are able to speak confidently on them. If you are fresher then interviewer does not expect you will answer very complex questions, rather you have to make your basics concepts very strong.
Second it really doesn't matter much if you could not answer few questions but it matters that whatever you answered, you must have answered with confidence.