Working with Unsigned Integers - C++ Data Type

C++ examples for Data Type:int

Introduction

C++'s built-in unsigned types

Type NameNumber of Bytes Minimum Value Maximum Value
unsigned char1 0 255
unsigned short 2 0 65,535
unsigned int 4 0 4,294,967,295
unsigned long4 0 4,294,967,295
unsigned long long 8 0 18,446,744,073,709,551,615

The cinttypes header file's unsigned integer types

Type Name Number of BytesMinimum Value Maximum Value
uint8_t 1 0 255
uint16_t 2 0 65,535
int 4 0 4,294,967,295
uint64_t 8 0 18,446,744,073,709,551,615

Demo Code

#include <iostream>
#include <cinttypes>

using namespace std;

int main(int argc, char* argv[])
{
    int whole32BitNumber1{ 64 };
    cout << "whole32BitNumber1 equals " << whole32BitNumber1 << endl;

    int whole32BitNumber2{ whole32BitNumber1 + 32 };
    cout << "whole32BitNumber2 equals " << whole32BitNumber2 << endl;

    int whole32BitNumber3{ whole32BitNumber2 + whole32BitNumber1 };
    cout << "whole32BitNumber3 equals " << whole32BitNumber3 << endl;

    int whole32BitNumber4{ whole32BitNumber2 * whole32BitNumber1 };
    cout << "whole32BitNumber4 equals " << whole32BitNumber4 << endl;

    int whole32BitNumber5{ whole32BitNumber4 / whole32BitNumber1 };
    cout << "whole32BitNumber5 equals " << whole32BitNumber5 << endl;

    int whole32BitNumber6{ whole32BitNumber2 % whole32BitNumber1 };
    cout << "whole32BitNumber6 equals " << whole32BitNumber6 << endl;

    return 0;//w w w .j  a va  2s .  co  m
}

Result


Related Tutorials