- 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 34483 Articles for Programming
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
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
719 Views
In C language, the void pointers are converted implicitly to the object pointer type. The function malloc() returns void * in C89 standard. In earlier versions of C, malloc() returns char *. In C++ language, by default malloc() returns int value. So, the pointers are converted to object pointers using explicit casting.The following is the syntax of allocating memory in C language.pointer_name = malloc(size);Here, pointer_name − Any name given to the pointer.size − Size of allocated memory in bytes.The following is an example of malloc() in C language.Example Live Demo#include #include int main() { int n = 4, ... Read More
8K+ Views
Variables are the names given by the user. A datatype is also used to declare and initialize a variable which allocates memory to that variable. There are several datatypes like int, char, float etc. to allocate the memory to that variable.There are two ways to initialize the variable. One is static initialization in which the variable is assigned a value in the program and another is dynamic initialization in which the variables is assigned a value at the run time.The following is the syntax of variable initialization.datatype variable_name = value;Here, datatype − The datatype of variable like int, char, float ... Read More
523 Views
The following is an example to catch a divide by zero error.Example Live Demo#include using namespace std; int display(int x, int y) { if( y == 0 ) { throw "Division by zero condition!"; } return (x/y); } int main () { int a = 50; int b = 0; int c = 0; try { c = display(a, b); cout
2K+ Views
We can calculate the execution time of a code snippet by using following syntax −auto start = high_resolution_clock::now(); // Start time // Code snippet auto stop = high_resolution_clock::now(); // Stop time auto duration = duration_cast(stop - start); // DurationThe class high_resolution_clock is defined in “chrono” header file. The function now() is returning a value corresponding to the call’s point in time.A header file is used to record the time taken by that particular code.#include using namespace std::chrono;The following is an example to calculate execution time of a code snippet.Example Live Demo#include #include using namespace std::chrono; using namespace std; ... Read More
10K+ Views
Enumeration is a user defined datatype in C/C++ language. It is used to assign names to the integral constants which makes a program easy to read and maintain. The keyword “enum” is used to declare an enumeration.The following is the syntax of enums.enum enum_name{const1, const2, ....... };Here, enum_name − Any name given by user.const1, const2 − These are values of type flag.The enum keyword is also used to define the variables of enum type. There are two ways to define the variables of enum type as follows −enum colors{red, black}; enum suit{heart, diamond=8, spade=3, club};The following is an example of ... Read More