GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Integer Variable in C++ Programming with Examples | Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
C++ Programming Tutorial
  • C++ Basic Concepts
    • Introduction
    • Variable
    • Data Types and Modifiers
    • Naming Conventions
    • Integer Variable
    • Float and Double Variables
    • Character Variable
    • Boolean Variable
    • Constant Variable
    • Typecasting
  • Operators in C++
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Operator Precedence
  • Input and Output in C++
    • Environment Setup
    • Program Basic Structure
    • cout Statement
    • cin Statement
    • Comments
  • Decision Making in C++
    • Decision Making
    • if Statement
    • if else Statement
    • if else if Statement
    • Conditional Operator
    • switch case Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in C++
    • What are Loops
    • for Loop
    • while Loop
    • do while Loop
  • Arrays in C++
    • One Dimensional Array
    • Two Dimensional Array
  • String in C++
    • C-Style String
    • C-Style String Methods
    • String
    • String Methods
  • Searching in C++
    • Linear Search
    • Binary Search
  • Sorting in C++
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Pointer in C++
    • Pointer
    • Dynamic Memory Allocation
    • References
  • User Defined Datatype in C++
    • Structure
    • Union
    • Enum
  • Function in C++
    • Function
    • Recursive Function
    • Function Overloading
    • Storage Classes
    • User-Defined Header Files
  • Data Structures in C++
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • OOPs in C++
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Access Specifiers
    • Constructor
    • Destructor
    • Static Variables
    • Static Methods
    • Friend Function
    • Friend Class
    • Inheritance
    • Types of Inheritance
    • Polymorphism
    • Abstract Class
  • File Handling in C++
    • Text File Handling
    • Binary File Handling

bookmark
Table of Contents

    Integer Variable in C++ Programming

    In this lesson, we will learn about the Integer Variable in C++ programming language. We will go through some examples of it and a quiz on it.

    Integer Type Variable

    In our earlier lesson we have learned about variable and how they are used to store values in computer memory. Now in this lesson we will learn how to declare variable in C++ programming using an Integer Data Type.

    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image

    So the first type of variable we need to know about is of type int - short for integer. This type of variable is used to store a whole number either positive or negative only (example: 10, 89, -24 etc). But if you try to store a fractional value (example: 12.36) in it then it will only store the integer part 12 but not the decimal part 36.

    The memory storage capacity of an integer variable is 4 bytes and the range of an int variable is between -2,147,483,648 to 2,147,483,647.

    Syntax of Declaring Integer Variable in C++
    int variable_name;

    Here int is used for declaring Integer data type and variable_name is the name of variable (you can use any name of your choice for example: a, b, c, alpha, etc. but remember the Naming Conventions while declaring an integer variable) and ; is used for line terminator (end of line).

    Now let's see some examples for more understanding.

    Example 1

    Declare a signed integer variable x.

    signed int x;
    Note

    In C++ programming there is no need to write signed data type modifier as because it is the default modifier of int and char data type if no modifier is specified.

    Example 2

    Declare an integer variable x to assign an integer value 10.

    int x = 10;
    Example 3

    Declare 3 integer variables x, y and z in a single line.

    int x, y, z;
    Example 4

    Declare 3 integer variables x, y and z to assign the integer value 42, 67 and 85 respectively in a single line.

    int x=42, y=67, z=85;
    Example 5

    Declare an integer variable x and assign the integer value 18 in the second line.

    int x;
    x = 18;
    Example 6

    Declare an integer variable x and assign the integer value 76 and change its value to 54 in the next line.

    int x = 76;
    x = 54; // now the new value of x is 54
    Example 7

    Declare a short integer variable x and assign the value 9432.

    short int x = 9432;

    A short integer variable can store numbers between range -32,768 to 32,767.

    Example 8

    Declare 2 unsigned integer variables x, y and assign the value 7645 and 24861 respectively.

    unsigned int x = 7645, y = 24861;

    An unsigned integer variable can store only positive numbers between range 0 to 4,294,967,295.

    Example 9

    Declare an integer variable x with a long long data type modifier and assign the value 9832567.

    long long int x = 9832567;

    Test Your Knowledge

    Attempt the questions in the exercise to check whether you have understood the lesson clearly.

    Exercise
    Test Your Knowledge
    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.