Data types

Introduction

In computer programming, data types are used to define the type of data that a variable can hold. This helps the compiler or interpreter to allocate memory and perform operations on the data accurately. Commonly used data types in programming include integers, booleans, floats, doubles, and strings. Table 1 presents a summary of the most commonly used programming data types.

Table 1. Summary of common programming data types
Data Type Description Example

boolean

A binary data type that can have one of two values: true or false.

true, false

int

A whole number data type, including negative numbers.

42, -10, 0

float

A decimal number data type, also known as a floating-point number.

3.14, -2.5, 0.0

double

A data type that can store larger decimal values with higher precision than a float.

3.14159265359, -0.00001

char

A data type that represents a single character.

'a', 'B', '%'

String

A data type that represents a sequence of characters.

"hello", "world", "123"

int[], double[], String[]

A data type that stores a fixed-size sequential collection of elements of the same type.

"[1, 2, 3], ["apple", "banana", "cherry"]"

Object[]

A data type that represents a complex data structure with properties and methods.

company = { name: "Powerspex", age: 25 }

The datatypes primarily used in PsxCad are boolean, integer, double and object.

Boolean

A boolean is a data type that represents a logical value, which can be either True or False.

Example of a boolean
boolean value = True;

Integer

An integer is a whole number data type that represents a numerical value without a fractional component. Integers can be positive, negative, or zero, and can be used in mathematical operations such as addition, subtraction, multiplication, and division.

Example of an integer
int age = 25;

Float

A float (short for floating-point) is a data type that represents a numerical value with a fractional component. Floats are often used to represent real numbers, such as decimal numbers or scientific notation.

Example of a float
float pi = 3.14159;

Double

A double is a data type that represents a floating-point number with double precision. Doubles are similar to floats, but they have a higher precision and can represent larger or smaller values with greater accuracy.

Example of a double
double weight = 75.5;

Character

A character is a data type that represents a single character, such as a letter, digit, or symbol.

Example of a character
char letter = 'A';

String

A string is a sequence of characters that represents a text or a message. The characters in a string can be letters, digits, symbols, or spaces,

Example of a string
String message = "Hello, world!";

Array

An array is a data structure that stores a collection of values of the same type in a contiguous block of memory. The values are typically accessed using an index, which is an integer value that indicates the position of the value in the array.

Arrays can be used to store and manipulate large sets of data efficiently, such as lists of numbers, strings, or other objects.

Example of an array
int[] numbers = {1, 2, 3, 4, 5};

The elements are accessed using their index value, such as "numbers[0]" to access the first element, which has a value of 1 in the example above.

Object

The object data type is a very general and flexible data type that can represent any kind of value in a programming language.

Example of an object
Object[] company = { name: "Powerspex", age: 25 };