General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Programming Fundamentals
  2. Datatypes
  3. Primitive Datatypes

Integer

The integer data type in computer programming is used to represent whole numbers, both positive and negative, without fractions or decimals. Integers are one of the fundamental data types supported by virtually all programming languages, and they are used extensively in various types of calculations, loops, array indexing, and more.

Characteristics of the Integer Data Type:

  • Whole Numbers: Integers include the set of positive whole numbers, negative whole numbers, and zero. For example, -3, 0, and 15 are all integers.

  • No Fractions or Decimals: Unlike floating-point numbers, integers cannot represent fractions or decimal values.

  • Fixed or Variable Size: Depending on the programming language and the specific type of integer, they can have a fixed size (such as 32-bit or 64-bit) or vary based on the language's implementation. Fixed-size integers have a minimum and maximum value they can represent, determined by their bit-width.

  • Signed and Unsigned: Integers can be "signed" (capable of representing both positive and negative values) or "unsigned" (capable of representing only non-negative values). The choice between signed and unsigned integers affects the range of values that can be represented.

Usage in Different Programming Languages:

  • C/C++: Offers several specific types of integers, such as int, short, long, and their unsigned variants like unsigned int. The size of these types can vary based on the compiler and platform but is generally consistent within modern systems (e.g., int is often 32 bits).

  • Java: Has fixed-size integer types, including byte (8 bits), short (16 bits), int (32 bits), and long (64 bits). By default, integers in Java are signed.

  • Python: Python's int type is flexible and can grow to accommodate any size of integer, limited only by the available memory of the system. This is in contrast to many other languages that have fixed-size integer types.

Example Usage:

#include <stdio.h>

int main() {
    int a = 10;
    int b = -5;
    int sum = a + b;

    printf("The sum of a and b is: %d", sum);
    return 0;
}

In this C program example, a and b are integers used in a simple arithmetic operation. The %d format specifier in the printf function is used to print integer values.

PreviousCharacterNextBoolean

Last updated 1 year ago

Was this helpful?