Short Data Type in C

C-Short Data Type

On this page we will discuss about Short Data Type which is used in C.
The Short data type is a data type that represents a signed integer that is typically at least 16 bits long.
short data type in C

Short Data Type used in C

In C Programming, short data type is typically used to store small integer values that do not require the full range of a 32-bit int type. The short data type can be both signed and unsigned similar to int data type.

The short data types with their storage size, range and format specifier are given in the table below:

Data TypeStorage sizeRangeFormat Specifier
short int/signed short int2 bytes-32768 to 32767%hd
unsigned short int2 bytes0 to 65535%hu
In general, the short data type is a useful and efficient way to store and manipulate small integer values in C programs.

Declaration of Short Data type variable

 short int p,q;

Here variables p and q can store both positive and negative values.

Initialization of Short Data type variable

A short data type variable can be initialized in two ways as follows:

1. By assigning value to a variable using assignment operator.

p = 8;
q = -5;

2. By assigning value to a variable during declaration only using an assignment operator.

short int p = 8;
short int q = -5;

Program to print Short Data Types

Example 1:

Run
#include <stdio.h>

int main(void) {
  
  // Initializing variables of short data type    
  short a = 5;
  short b = -10;
  short c = 0;

  // Displaying the values of variables
  printf("The value of a is %hd\n", a);
  printf("The value of b is %hd\n", b);
  printf("The value of c is %hd\n", c);

  return 0;
}

Output:

The value of a is 5
The value of b is -10
The value of c is 0

Example 2:

Run
#include <stdio.h> 

int main(void) {
  // Array using short data type
  
  // Declaring and Initializing array having short values 
  short values[3] = {5, -10, 0};
  
  // Displaying the array
  printf("The values of array are: %hd, %hd, %hd\n", values[0], values[1], values[2]);
  return 0;
}

Output:

The values of array are: 5, -10, 0

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription