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 int Keyword

❮ C Keywords


Example

Print an integer:

int myNum = 1000;
printf("%d", myNum);
Try it Yourself »

Definition and Usage

The int keyword is a data type which stores whole numbers. Most implementations will give the int type 32 (4 bytes) bits, but some only give it 16 bits (2 bytes).

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;
printf("size: %zu bits value: %d\n", 8*sizeof(myInt), myInt);
printf("size: %zu bits value: %u\n", 8*sizeof(myUInt), myUInt);
printf("size: %zu bits value: %d\n", 8*sizeof(mySInt), mySInt);
printf("size: %zu bits value: %u\n", 8*sizeof(myUSInt), myUSInt);
printf("size: %zu bits value: %lld\n", 8*sizeof(myLInt), myLInt);
printf("size: %zu bits value: %llu\n", 8*sizeof(myULInt), myULInt);
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.