
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

5K+ Views
The main reason for segmentation fault is accessing memory that is either not initialized, out of bounds for your program or trying to modify string literals. These may cause a segmentation fault though it is not guaranteed that they will cause a segmentation fault. Here are some of the common reasons for segmentation faults −Accessing an array out of boundsDereferencing NULL pointersDereferencing freed memoryDereferencing uninitialized pointersIncorrect use of the "&" (address of) and "*" (dereferencing) operatorsImproper formatting specifiers in printf and scanf statementsStack overflowWriting to read-only memory

7K+ Views
Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled access modifiers − public, private, and protected sections within the class body.The default access for members and classes is private.Exampleclass Base { public: // public members go here protected: // protected members go here private: // private members go here };A public member is accessible from anywhere outside the class but within a program. ... Read More

2K+ Views
The output stream cout allows using manipulators that you can use to set the precision directly on cout and use the fixed format specifier. To get the full precision of a double, you can use the limits library. For example,Example#include #include using namespace std; int main() { // Get numeric limits of double typedef std::numeric_limits< double > dbl; double PI = 3.14159265358979; cout.precision(dbl::max_digits10); cout

5K+ Views
The compilation of a C++ program consists of three steps −Preprocessing − In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. It handles preprocessing directives like #include, #define, etc.Compilation − The compilation takes place on the preprocessed files. The compiler parses the pure C++ source code and converts it into assembly code. This in turn calls the assembler that converts the assembly code to machine code(binary) as Object files. These Object files can refer to symbols that are not defined. The compiler won't give ... Read More

1K+ Views
You can use a string stream to parse an int in c++ to an int. You need to do some error checking in this method.example#include #include using namespace std; int str_to_int(const string &str) { stringstream ss(str); int num; ss >> num; return num; } int main() { string s = "12345"; int x = str_to_int(s); cout

4K+ Views
A portable solution doesn't exist for doing this. On windows, you can use the getch() function from the conio(Console I/O) library to get characters pressed.example#include #include using namespace std; int main() { char c; while(1){ // infinite loop c = getch(); cout

3K+ Views
C++ has header and .ccp files for separating the interface from the implementation. The header files declare "what" a class (or whatever is being implemented) will do, ie the API of the class, kind of like an interface in Java. The cpp file on the other hand defines "how" it will perform those features, ie, the implementation of these declared functionality.This reduces dependencies. The code that uses the header doesn't need to know all the details of the implementation and any other classes/headers needed only for that. It just needs to focus on things it is trying to implement. This ... Read More

875 Views
In C++, calling a virtual function inside a constructor or destructor is dangerous and should generally be avoided. Following are the reasons to avoid calling: When a constructor (or destructor) is running, the object is not fully built (or fully destroyed). At that time, the virtual function table (vtable) points to the version of the class currently being constructed or destructed, not the most derived version. What Happens When You Call a Virtual Function in a Constructor? If you call the virtual function inside a constructor: ... Read More

9K+ Views
A segmentation fault occurs when your program attempts to access an area of memory that it is not allowed to access. In other words, when your program tries to access memory that is beyond the limits that the operating system allocated for your program.Seg faults are mostly caused by pointers that are −Used to being properly initialized.Used after the memory they point to has been reallocated or freed.Used in an indexed array where the index is outside of the array bounds.