

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
What is the difference between an int and a long in C++?
int
The 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
#include <iostream> using namespace std; int main() { int a = 8; int b = 10; int c = a+b; cout << "The value of c : " << c; return 0; }
Output
The value of c : 18
long
The datatype long is used to store the long integer values. It could be signed or unsigned. The datatype long is of 64-bit or 8 bytes. It requires more memory area than int to store the value. The keyword “long” is used to declare a long integer variable.
The following is the syntax of long datatype.
long variable_name;
Here,
variable_name − The name of variable given by user.
The following is an example of long datatype.
Example
#include <iostream> using namespace std; int main() { int a = 8; long b = 28; long c = long(a+b); cout << "The value of c : " << c; return 0; }
Output
The value of c : 36
- Related Questions & Answers
- Difference Between int and long
- What is the difference between size_t and int in C++?
- What is the difference between int and Int32 in C#?
- What is difference between int and const int& in C/C++?
- What is the difference between const int*, const int * const, and int const *?
- What is the difference between int and integer in MySQL?
- What is the size of int, long type in C++ standard?
- Difference between const int*, const int * const, and int const * in C/C++?
- Difference between an Integer and int in Java
- Difference between const int*, const int * const, and int const * in C
- What is the difference between a class and an object in C#?
- What is the difference between a list and an array in C#?
- What is the difference between an interface and a class in C#?
- What is the size of int, long type as per C++ standard?
- What is the difference Between C and C++?