
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
PointersPointers are used to store the address of variable.SyntaxType *pointer;InitializationType *pointer; Pointer = variable name;Functionspointers are used to store address of variable.pointers can have a null value assigned.pointer can be referenced by pass by reference.a pointer has its own memory address and size on the stack.Example Live Demo#include using namespace std; int main() { // A normal integer variable int a = 7; // A pointer variable that holds address of a. int *p = &a; // Value stored is value of variable "a" cout

1K+ Views
The void pointer is a pointer which is not associate with any data types. It points to some data location in storage means points to the address of variables. It is also called general purpose pointer. Is It Safe to Delete a Void Pointer in C/C++? It is not safe to delete a void pointer in C/C++ because delete needs to call the destructor of whatever object it's destroying, and it is impossible to do that if it doesn't know the type. C Example of Void Pointer In this example, a void pointer (void *p) can store the address of ... Read More

493 Views
A pointer is used to store the address of the variables. To declare pointer variables in C/C++, an asterisk (*) used before its name.Declaration*pointer_nameIn CExample Live Demo#include int main() { // A normal integer variable int a = 7; // A pointer variable that holds address of a. int *p = &a; // Value stored is value of variable "a" printf("Value of Variable : %d", *p); //it will print the address of the variable "a" printf("Address of Variable : %p", p); // reassign the value. *p = 6; printf("Value ... Read More

8K+ Views
The pointers can be directly compared using relational operators. In this article, we will learn about the comparisons of the pointers with the help of examples. Pointers Comparison in C and C++ In C/C++, we can directly compare the pointers using relational operators (==, !=, , =). These operators are used to compare two variables, values, or pointers. It returns a Boolean true value when the comparison is correct otherwise, it is false. The core syntaxes of C and C++ pointers are similar such as declaration, dereferencing, and pointer arithmetic. All of these are identical in behavior and still use ... Read More

13K+ Views
In C++ , function pointers when dealing with member functions of classes or structs, it is invoked using an object pointer or a this call. We can only call members of that class (or derivatives) using a pointer of that type as they are type safe.Example Live Demo#include using namespace std; class AB { public: int sub(int a, int b) { return a-b; } int div(int a, int b) { return a/b; } }; //using function pointer int res1(int ... Read More

513 Views
A pointer can receive a null parameter whereas a reference can’t. You can only use pointer if you want to pass “no object”.Explicitly passing by pointer allow us to see the whether the object is passes by reference or value at call site.These are simple example of passing by pointer and passing by reference −Passing by pointerExample Live Demo#include using namespace std; void swap(int* a, int* b) { int c = *a; *a= *b; *b = c; } int main() { int m =7 , n = 6; cout

424 Views
Remove an element from C++ std::vector by index can be done by following way −Example Live Demo#include #include using namespace std; int main() { vector v; //declare vector //insert elements into vector v.push_back(-10); v.push_back(7); v.push_back(6); // Deletes the first element (v[0]) v.erase(v.begin() ); for (int i = 0; i < v.size(); i++) cout

18K+ Views
The only way to check if a file exist is to try to open the file for reading or writing.Here is an example −In CExample#include int main() { /* try to open file to read */ FILE *file; if (file = fopen("a.txt", "r")) { fclose(file); printf("file exists"); } else { printf("file doesn't exist"); } }Outputfile existsIn C++Example#include #include using namespace std; int main() { /* try to open file to read */ ifstream ifile; ifile.open("b.txt"); if(ifile) { cout

7K+ Views
In C++, we can read the integer values from text files using the ifstream class that allows the user to perform input operations from the files. Here, we have filename (tp.txt) that used in the program and store some integers value. 21 61 24 05 50 11 12 21 66 55 Example to Read Integers from a Text File In this example, we created one text file to save the integers values and then access those value using file handling operation. #include #include using namespace std; int main() { // Define the maximum ... Read More

1K+ Views
Here is a C++ program to read file content into isstringstream in C++.Example#include #include #include using namespace std; int main() { ifstream is("a.txt", ios::binary ); // get length of file: is.seekg (0, std::ios::end); long length = is.tellg(); is.seekg (0, std::ios::beg); // allocate memory: char *buffer = new char [length]; // read data as a block: is.read (buffer,length); // create string stream of memory contents istringstream iss( string( buffer ) ); cout