Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C++ Tutorial

C++ HOME C++ Intro C++ Get Started C++ Syntax C++ Output C++ Comments C++ Variables C++ User Input C++ Data Types C++ Operators C++ Strings C++ Math C++ Booleans C++ If...Else C++ Switch C++ While Loop C++ For Loop C++ Break/Continue C++ Arrays C++ Structures C++ Enums C++ References C++ Pointers

C++ Functions

C++ Functions C++ Function Parameters C++ Function Overloading C++ Scope C++ Recursion

C++ Classes

C++ OOP C++ Classes/Objects C++ Class Methods C++ Constructors C++ Access Specifiers C++ Encapsulation C++ Inheritance C++ Polymorphism C++ Files C++ Exceptions C++ Date

C++ Data Structures

C++ Data Structures & STL C++ Vectors C++ List C++ Stacks C++ Queues C++ Deque C++ Sets C++ Maps C++ Iterators C++ Algorithms

C++ How To

C++ Add Two Numbers C++ Random Numbers

C++ Reference

C++ Reference C++ Keywords C++ <iostream> C++ <fstream> C++ <cmath> C++ <string> C++ <cstring> C++ <ctime> C++ <vector> C++ <algorithm>

C++ Examples

C++ Examples C++ Real-Life Examples C++ Compiler C++ Exercises C++ Quiz C++ Syllabus C++ Study Plan C++ Certificate


C++ int Keyword

❮ C++ Keywords


Example

int myNum = 100000;
cout << myNum;

Try it Yourself »


Definition and Usage

The int keyword is a data type that is usually 32 bits long which stores whole numbers. Most implementations will give the int type 32 bits, but some only give it 16 bits.

With 16 bits it can store positive and negative numbers with values between -32768 and 32767, or between 0 and 65535 when unsigned.

With 32 bits it can store positive and negative numbers with values between -2147483648 and 2147483647, or between 0 and 4294967295 when unsigned.

Modifiers

The size of the int can be modified with the short and long modifiers.

The short keyword ensures a maximum of 16 bits.

The long keyword ensures at least 32 bits but may extend it to 64 bits. long long ensures at least 64 bits.

64 bits can store positive and negative numbers with values between -9223372036854775808 and 9223372036854775807, or between 0 and 18446744073709551615 when unsigned.


More Examples

Example

Create signed, unsigned, short and long integers:
int myInt = 4294967292;
unsigned int myUInt = 4294967292;
short int mySInt = 65532;
unsigned short int myUSInt = 65532;
long int myLInt = 18446744073709551612;
unsigned long int myULInt = 18446744073709551612;
cout << " size: " << 8*sizeof(myInt)   << " bits  value: " << myInt   << "\n";
cout << " size: " << 8*sizeof(myUInt)  << " bits  value: " << myUInt  << "\n";
cout << " size: " << 8*sizeof(mySInt)  << " bits  value: " << mySInt  << "\n";
cout << " size: " << 8*sizeof(myUSInt) << " bits  value: " << myUSInt << "\n";
cout << " size: " << 8*sizeof(myLInt)  << " bits  value: " << myLInt  << "\n";
cout << " size: " << 8*sizeof(myULInt) << " bits  value: " << myULInt << "\n";

Try it Yourself »


Related Pages

The unsigned keyword can allow an int to represent larger positive numbers by not representing negative numbers.

The short keyword ensures that an int has 16 bits.

The long keyword ensures that an int has at least 32 bits.

Read more about data types in our C++ Data Types Tutorial.


❮ C++ Keywords

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.