Which Data Type Have Size That Is Variable?


Scott Campbell

In programming, data types are used to classify the type of data that a variable can hold. Each data type has a specific size and range of values that it can store.

However, there are certain data types that have a size that is variable. Let’s explore these data types in detail.

1. Strings

A string is a sequence of characters enclosed within single quotes (”) or double quotes (“”).

Unlike other data types, the size of a string can vary depending on the number of characters it contains. For example:

  • Example 1: “Hello, World!” – This string has 13 characters.
  • Example 2: “Lorem ipsum dolor sit amet..” – This string has 26 characters.

Strings are commonly used to store textual data such as names, addresses, and messages in programming languages.

2. Arrays

An array is a collection of elements of the same data type stored in contiguous memory locations. The size of an array can be variable depending on the number of elements it holds.

To declare an array with a variable size, you need to specify the size during runtime using variables or user input. For example:

var length = prompt("Enter the length of the array:");
var myArray = new Array(length);

In this example, the user is prompted to enter the length of the array, and then an array called myArray is created with a size specified by the user.

3. Lists

A list is another data type that can have a variable size.

Lists are similar to arrays but offer more flexibility in terms of size management.

In HTML, you can create lists using the <ul> (unordered list) and <li> (list item) tags. Here’s an example:

  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>

The above code will display an unordered list with three items. You can add or remove items from the list as needed, making the size of the list variable.

4. Dynamic Data Types

Some programming languages have dynamic data types that can change their size dynamically during program execution. These data types are often used to store collections of data with varying lengths.

For example, in Python, the list and tuple data types are dynamic and can be resized easily by adding or removing elements.


In conclusion, there are several data types that have a variable size. Strings, arrays, lists, and certain dynamic data types allow for flexibility in storing varying amounts of data. Understanding these variable-sized data types is essential for efficient programming and managing different types of information in your code.

By utilizing these HTML styling elements such as bold text, underlined text,

  • lists

, and subheaders like

, you can visually enhance your content while keeping it organized and engaging for readers.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy