- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 7346 Articles for C++
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
294 Views
A smart pointer is a class that wraps a 'raw' (or 'bare') C++ pointer. It is used to manage resources the pointer points to. For example, if the reference to that memory location is lost. It kind of acts like a garbage collector. There are multiple smart pointer types.You should almost always use a smart pointer. This is because the main pain point of using pointers is manual memory management and memory leaks. The smart pointer tries to get rid of both of these. If you don't want to do either of these in practice, you should use a smart ... Read More
![Priya Pallavi](https://www.tutorialspoint.com/assets/profiles/13562/profile/60_91320-1512544134.jpg)
166 Views
Forward declaration lets the code following the declaration know that there is are classes with the name Person. This satisfies the compiler when it sees these names used. Later the linker will find the definition of the classes. exampleClass Person; void myFunc(Person p1) { // ... } Class Person { // Class definition here };So in this case when compiler encounters myFunc, it'll know that its going to encounter this class somewhere down in the code. This can be used in cases where code using the class is placed/included before the code containing the class definition.
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
110 Views
Arrays and pointers work quite similarly in C/C++. But there are some subtle differences. For example, the sizeof operator works quite differently on the two. When you convert an array in a pointer,Example#include int main() { const int a[] = { 2, 3, 5, 7, 11 }; const int* p = a; std::cout
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
145 Views
The difference between sizeof for a struct and the sum of sizeof of each member of that struct is due to byte padding and alignment. Every data type in C/C++ has a alignment requirement. A processor will have processing word length of its architecture. On a 32 bit machine, the processing word size will be 4 bytes or 32 bits. For example, If you have the struct −Example#include using namespace std; struct X { char b[3]; int c; }; int main() { char b[3]; int c; int total = sizeof(b) + sizeof(c); cout
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
309 Views
Copy elision is an optimization implemented by most compilers to prevent extra (potentially expensive) copies in certain situations. So if you have some code that is creating objects not being used or don't have side effects, examplestruct MyStruct { MyStruct() {} MyStruct(const MyStruct&) { std::cout
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
971 Views
ReferencesWhen a variable is declared as a reference, it becomes an alternative name for an existing variable.Syntax Type &newname = existing name;InitializationType &pointer; pointer = variable name;PointersPointers are used to store the address of a variable.SyntaxType *pointer;InitializationType *pointer; pointer = variable name;The main differences between references and pointers are -References are used to refer an existing variable in another name whereas pointers are used to store the address of a variable.References cannot have a null value assigned but pointer can.A reference variable can be referenced bypass by value whereas a pointer can be referenced but pass by referenceA reference must ... Read More
![Srinivas Gorla](https://www.tutorialspoint.com/assets/profiles/13556/profile/60_78057-1512712331.jpg)
275 Views
An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. To use an array in C++, you'll need to declare it first, for example, int arr[10];This declares an array of type int of size 10. This can store 10 integers in contiguous memory. To Refer to any of its element, you need to use the array access operator and provide it the index of the element you want to access. The indexing in C++ array start from 0. So in the ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
200 Views
In C++, it is faster to process a sorted array than an unsorted array because of branch prediction. In computer architecture, a branch prediction determines whether a conditional branch (jump) in the instruction flow of a program is likely to be taken or not.Let’s take an example −if(arr[i] > 50) { Do some operation B } else { Do some operation A }If we run this code for 100 elements in unsorted and sorted order below things will be happened −For sorted array −1, 2, 3, 4, 5, …… 50, 51………100 A, A, A, A, A A, B ... Read More
![Abhinanda Shri](https://www.tutorialspoint.com/assets/profiles/13552/profile/60_73264-1512711555.jpg)
281 Views
Undefined behavior is simply behavior that is not defined by the C++ specification. For example, if you have multiple unary increment/decrement operations in an expression like i++ + ++i, they result in behavior that is not defined. This is simply due to the fact that some language constructs are syntactically valid but you can't predict the behavior when the code is run. Another example is the expression: u = (u++);Implementation-defined behavior is behavior unspecified by the specification and left for the implementor to decide and document how the choice is made. In this case, the choice that is made must ... Read More
![Nitya Raut](https://www.tutorialspoint.com/assets/profiles/13573/profile/60_92249-1512715559.jpg)
2K+ Views
The return value for main is used to indicate how the program exited. If the program execution was normal, a 0 return value is used. Abnormal termination(errors, invalid inputs, segmentation faults, etc.) is usually terminated by a non-zero return. There is no standard for how non-zero codes are interpreted.You can define your own status codes though and use them to represent different types of failures in the program.GCC recommends using either EXIT_SUCCESS or EXIT_FAILURE defined in stdlib.h for sending exit signals.In C++, int main() can be left without a return value at which point it defaults to returning 0.Read More