- 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++
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
16K+ Views
A static variable is a variable that is declared using the keyword static. The space for the static variable is allocated only one time and this is used for the entirety of the program.Once this variable is declared, it exists till the program executes. So, the lifetime of a static variable is the lifetime of the program.A program that demonstrates a static variable is given as follows.Example Live Demo#include using namespace std; void func() { static int num = 1; cout
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
326 Views
Structures and classes are very similar in C++ except for some differences. So details about these differences are given below that help to decide when to use a class or structure in C++.Differences between Class and StructureAll the members of a class are private by default. This is different compared to structures as all the members of a structure are public by default.A program that demonstrates a class in C++ is given as follows −Example#include using namespace std; class Example { int val; }; int main() { Example obj; obj.val = 20; return 0; }This ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
20K+ Views
Some of the methods to find the length of an array are given as follows −Method 1 - Using sizeof operatorThe sizeof() operator can be used to find the length of an array. A program that demonstrates the use of the sizeof operator in C++ is given as follows.Example Live Demo#include using namespace std; int main() { int arr[5] = {4, 1, 8, 2, 9}; int len = sizeof(arr)/sizeof(arr[0]); cout
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
407 Views
Reference variableReference variable is an alternate name of already existed variable. It cannot be changed to refer another variable and should be initialized at the time of declaration. It cannot be NULL. The operator ‘&’ is used to declare a reference variable.The following is the syntax of reference variable.datatype variable_name; // variable declaration datatype& refer_var = variable_name; // reference variableHere, datatype − The datatype of variable like int, char, float etc.variable_name − This is the name of variable given by user.refer_var − The name of reference variable.The following is an example of reference variable.Example Live Demo#include using namespace std; int ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
10K+ Views
External variables are also known as global variables. These variables are defined outside the function and are available globally throughout the function execution. The “extern” keyword is used to declare and define the external variables.The keyword [ extern “C” ] is used to declare functions in C++ which is implemented and compiled in C language. It uses C libraries in C++ language.The following is the syntax of extern.extern datatype variable_name; // variable declaration using extern extern datatype func_name(); // function declaration using externHere, datatype − The datatype of variable like int, char, float etc.variable_name − This is the name of ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
19K+ Views
Reference variable is an alternate name of already existing variable. It cannot be changed to refer another variable and should be initialized at the time of declaration and cannot be NULL. The operator ‘&’ is used to declare reference variable.The following is the syntax of reference variable.datatype variable_name; // variable declaration datatype& refer_var = variable_name; // reference variableHere, datatype − The datatype of variable like int, char, float etc.variable_name − This is the name of variable given by user.refer_var − The name of reference variable.The following is an example of reference variable.Example Live Demo#include using namespace std; int main() { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
intThe datatype int is used to store the integer values. It could be signed or unsigned. The datatype int is of 32-bit or 4 bytes. It requires less memory area than long to store a value. The keyword “int” is used to declare an integer variable.The following is the syntax of int datatype.int variable_name;Here,variable_name − The name of variable given by user.The following is an example of int datatype.Example Live Demo#include using namespace std; int main() { int a = 8; int b = 10; int c = a+b; cout
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
20K+ Views
We should use “%zu” to print the variables of size_t length. We can use “%d” also to print size_t variables, it will not show any error. The correct way to print size_t variables is use of “%zu”.In “%zu” format, z is a length modifier and u stand for unsigned type.The following is an example to print size_t variable.Example Live Demo#include int main() { size_t a = 20; printf("The value of a : %zu", a); return 0; }OutputThe value of a : 20In the above program, a variable of size_t length is declared and initialized with a value.size_t ... Read More