Computer Science

Data Types in Programming

Data types in programming refer to the classification of data that a programming language can process. These types include integers, floating-point numbers, characters, strings, and Boolean values. Understanding data types is essential for writing efficient and effective code.

Written by Perlego with AI-assistance

11 Key excerpts on "Data Types in Programming"

  • Book cover image for: Programming language theory
    • Alvin Albuero De Luna(Author)
    • 2023(Publication Date)
    • Arcler Press
      (Publisher)
    DATA TYPES CHAPTER7 CONTENTS 7.1. Introduction .................................................................................... 188 7.2. Primitive Data Types ....................................................................... 191 7.3. Character String Types..................................................................... 195 References ............................................................................................. 199 Programming Language Theory 188 7.1. INTRODUCTION A data type specifies both a set of data elements as well as a set of activities that may be performed upon these values in a predetermined order. Data is manipulated by computer software to get the desired results. The degree whereby the data types that are accessible in the language that is used are similar to the things that exist in the actual world that are being addressed by the challenge is an essential component in deciding how easily they will be capable to do this job. As a result, a programming language must enable an adequate assortment of data types. For example, In the past 60 years, there has been an evolution in the ideas that constitute modern data types. All challenge space structures would have to be represented in the first languages using just a select handful of the most fundamental data structures that were supported by those languages. Linked sets and branching trees, for instance, were both implemented using arrays in versions of Fortrans before 1990 (Liskov and Zilles, 1974; Mitchell, 1996). In COBOL, the data models made the first step out from the Fortran I paradigm by enabling programers to define the precision of numeric data value, as well as by offering an organized data form for recordings of information (Scott, 1976; Herlihy and Liskov, 1982). This was the first move away first from Fortran I paradigm. The capacity of precision specification has been enhanced by PL/I to include both integer and flying types.
  • Book cover image for: Basic Data Structures and Program Statements
    • Xingni Zhou, Qiguang Miao, Lei Feng(Authors)
    • 2020(Publication Date)
    • De Gruyter
      (Publisher)
    3 Basic data types Main contents – Basic data types, the essence of types, storage mechanism of integers, and floating-point numbers – Definition of variables, referencing method, and their way of storage in memory – Operators and their usage, the concept of expressions, categorization of results of operations – Summary of data elements Learning objectives – Understand and master concept of data types, data storage, data referencing, and data operation – Know how to use common operators and expressions – Understand and master the usage of constants and variables 3.1 Constants and variables At the checkout in supermarkets, we are given a receipt by a cashier, on which in-formation of our purchases is written as shown in Figure 3.1. The column total is computed by multiplying per-unit price with quantity, where the per-unit price is a constant and quantity is a variable. Some values are fixed, whereas others keep changing in many problems. For example, we have speed, time, and distance in moving object problems. In circles, we have a radius, perimeter, and Pi. In the shopping example above, we have the number of purchased goods, per-unit price, and total. Data in programs can be categorized into two types based on how they are used: constants and variables. The value of a constant cannot be modified during the execu-tion of programs, whereas the value of a variable can be changed during execution. 3.1.1 Constants There are two kinds of constants: literals and symbolic constants. One can use lit-eral constants directly in programs as needed without having to define in advance. However, if a constant is used multiple times in a program, we can use a symbolic constant instead to allow easy modification. In this case, we only need to modify once if we need to change the value of the constant. Symbolic constants should be defined before being used.
  • Book cover image for: Introduction To Systems Development NQF2 SB
    • M Smit R Jonker(Author)
    • 2017(Publication Date)
    • Macmillan
      (Publisher)
    79 Module 10 Topic 3: Computer data storage Computer data types Module 10 Overview At the end of this module, you should be able to: • Unit 10.1: Distinguish between data types with examples and the way the data is stored in memory. • Unit 10.2: Distinguish between categories of coding systems and their uses in a business environment. • Unit 10.3: Explain and illustrate how data manipulation operations are performed on data types. Unit 10.1: Data types and the way data is stored in memory Data is classified into various types of information. For humans, it is easy to see the difference between data types, but in the case of computers you need to declare (specify) what data type it is. Computers use special internal codes to keep track of different types of data. 10.1.1 Data types A computer program consists of two elements: data and operations on that data. Computers can only represent very simple pieces of information. All complex information must be built up from basic data types. We will now discuss the most common data types. a) Characters and strings A character is a letter, number or symbol. The character data type contains only one character. A string is a linear (continuous) sequence of characters, words or other data that the user can input from the keyboard. This includes the letters of the alphabet, numbers, punctuation and other special characters. Example 10.1: Strings Each of the following is a string: “My name is Lebo.” “My name is Lebo and I am 20.” “My name is Lebo and I was born on 12 January 1970.” “(011) 812 4545” character: a letter, number or symbol string: a linear sequence of characters, words or other data that the user can input from the keyboard Words & Terms 80 Module 10 As you can see from Example 10.1, a string contains all sorts of characters that can be entered via the keyboard. The string is captured between double quotes. It is not possible to do calculations with numbers in a string.
  • Book cover image for: C# Programming
    eBook - PDF

    C# Programming

    From Problem Analysis to Program Design

    Neale Cousland / Shutterstock.com All Microsoft screenshots used with permission from Microsoft Corporation. D ATA T YPES AND E XPRESSIONS IN THIS CHAPTER, YOU WILL: ? Examine how computers represent data ? Declare memory locations for data ? Explore the relationship among classes, objects, and types ? Use predefined data types ? Use integral data types ? Use floating-point types ? Learn about the decimal data type ? Declare Boolean variables ? Declare and manipulate strings ? Work with constants ? Write assignment statements using arithmetic operators ? Learn about the order of operations ? Learn special formatting rules for currency ? Work through a programming example that illustrates the chapter’s concepts 2 CHAPTER © zeljkodan/Shutterstock.com Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 72 | Chapter 2: Data Types and Expressions Chapter 1 introduced you to the basic elements of a C# program. You discovered the requirements for developing, compiling, and executing applications. This chapter focuses on data. Data is the raw facts, the basic numbers and characters that are manipulated to produce useful information. In this chapter, you will begin to see the power of programming when you write applications to perform calculations. You will learn how to declare variables that hold different types of data in memory and see how arithmetic operators react given different kinds of data. Data Representation You might hear someone say that his computer has a 64-bit processor with 8 GB of RAM and 1 TB of hard disk space.
  • Book cover image for: C++ for Engineers and Scientists
    To prevent programmers from attempting to perform an inappropriate operation, C++ allows performing only certain operations on certain data types. The types of data permitted and the operations allowed for each type are referred to as a data type . Formally, a data type is defined as a set of values and a set of operations that can be applied to these values. For example, the set of all integer (whole) numbers constitutes a set of values, as does the set of all real numbers (numbers containing a decimal point). These two sets of numbers, however, don’t constitute a data type until a set of operations is included—in these examples, mathematical and comparison operations. The combination of a set of values plus operations becomes a true data type. C++ categorizes data types in two basic groupings: class data types and built-in data types. A class data type (referred to as a “class,” for short) is a programmer-created data type, which means the programmer defines the acceptable values and operations, using C++ code. This data type is discussed in Part II. Built-in data types , also called primitive types , are provided as part of the C++ compiler and require no external C++ code. They consist of the basic numerical types shown in Figure 2.5 and the operations listed in Table 2.2. As shown in this table, most operations for built-in data types are designated as symbols. For class data types, most operations are provided as functions. Copyright 2012 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 61 Chapter 2 Data Types To introduce C++’s built-in data types, literals are used.
  • Book cover image for: Programming Languages
    No longer available |Learn more

    Programming Languages

    Principles and Practices

    In this section, we give a brief description of the differences among three of the languages used in previous examples: C, Java, and Ada. Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 350 CHAPTER 8 Data Types 8.4.1 C An overview of C data types is given in Figure 8.5. The simple types are called basic types in C, and types that are constructed using type constructors are called derived types . The basic types include: the void type (in a sense the simplest of all types, whose set of values is empty); the numeric types ; the integral types, which are ordinal; and the floating types . There are three kinds of floating types and 12 possible kinds of integral types. Among these there are four basic kinds, all of which can also have either signed or unsigned attributes given them (indicated in Figure 8.5 by listing the four basic types with signed and unsigned in parentheses above them). Of course, not all of the 12 possible integral types are distinct. For example, signed int is the same as int . Other duplicates are possible as well. C Types Basic void Numeric Integral Floating float double long double enum (signed) (unsigned) char int short int long int Pointer struct union Derived Function Array Figure 8.5 The type structure of C 8.4.2 Java The Java type structure is shown in Figure 8.6. In Java the simple types are called primitive types , and types that are constructed using type constructors are called reference types (since they are all implicitly pointers or references).
  • Book cover image for: Abstraction and Closure in Computer Science
    ________________________ WORLD TECHNOLOGIES ________________________ Chapter 4 Abstract Data Type and Object (Computer Science) Abstract data type In computing, an abstract data type is a mathematical model for a certain class of data structures that have similar behavior; or for certain data types of one or more progra-mming languages that have similar semantics. An abstract data type is defined indirectly, only by the operations that may be performed on it and by mathematical constraints on the effects (and possibly cost) of those operations. For example, an abstract stack data structure could be defined by two operations: push , that inserts some data item into the structure, and pop , that extracts an item from it; with the constraint that each pop always returns the most recently pushed item that has not been popped yet. When analyzing the efficiency of algorithms that use stacks, one may also specify that both operations take the same time no matter how many items have been pushed into the stack, and that the stack uses a constant amount of storage for each element. Abstract data types are purely theoretical entities, used (among other things) to simplify the description of abstract algorithms, to classify and evaluate data structures, and to formally describe the type systems of programming languages. However, an ADT may be implemented by specific data types or data structures, in many ways and in many programming languages; or described in a formal specification language. ADTs are often implemented as modules: the module's interface declares procedures that correspond to the ADT operations, sometimes with comments that describe the constraints. This information hiding strategy allows the implementation of the module to be changed without disturbing the client programs. The notion of abstract data types is related to the concept of data abstraction, important in object-oriented programming and design by contract methodologies for software development.
  • Book cover image for: Connecting Discrete Mathematics and Computer Science
    2 Basic Data Types In which our heroes equip themselves for the journey ahead, by taking on the basic provisions that they will need along the road. 5 6 Basic Data Types 2.1 Why You Might Care It is a capital mistake to theorize before one has data. Sir Arthur Conan Doyle (1859–1930) A Scandal in Bohemia (1892) Imagine converting a color photograph to grayscale (as in Figure 2.1). Implementing this conversion requires interacting with a slew of foundational data types (the basic “kinds of things”) that show up throughout CS. A pixel is a sequence of three color values, red, green, and blue. (And an image is a two-dimensional sequence of pixels.) Those color values are integers between 0 and 255 (because each is represented as a sequence of 8 bits). The translation process is a function taking inputs (any of the set of possible color values) and producing outputs (any of the set of grayscale values) using a particular formula. Virtually every interesting computer science application uses these basic data types extensively. Cryp- tography, which is devoted to the secure storage and transmission of information so that a malicious third party cannot decipher that information, is typically based directly on integers, particularly large prime numbers. A ubiquitous task in machine learning is to “cluster” a set of entities into a collection of nonover- lapping subsets so that two entities in the same subset are similar and two entities in different subsets are dissimilar. In information retrieval, where we might seek to find the document from a large collection that is most relevant to a given query, it is common to represent each document by a vector (a sequence of numbers) based on the words used in the document, and to find the most relevant documents by identifying which ones “point in the same direction” as the query’s vector.
  • Book cover image for: Big C++
    eBook - PDF

    Big C++

    Late Objects

    • Cay S. Horstmann(Author)
    • 2017(Publication Date)
    • Wiley
      (Publisher)
    25 C H A P T E R 2 FUNDAMENTAL DATA TYPES C H A P T E R G O A L S To be able to define and initialize variables and constants To understand the properties and limitations of integer and floating-point numbers To write arithmetic expressions and assignment statements in C++ To appreciate the importance of comments and good code layout To create programs that read and process input, and display the results To process strings, using the standard C++ string type C H A P T E R C O N T E N T S © samxmeg/iStockphoto. 2.1 VARIABLES 26 SYN Variable Definition 27 SYN Assignment 30 CE 1 Using Undefined Variables 33 CE 2 Using Uninitialized Variables 33 PT 1 Choose Descriptive Variable Names 33 PT 2 Do Not Use Magic Numbers 34 ST 1 Numeric Types in C++ 34 ST 2 Numeric Ranges and Precisions 35 ST 3 Defining Variables with auto 35 2.2 ARITHMETIC 36 CE 3 Unintended Integer Division 39 CE 4 Unbalanced Parentheses 40 CE 5 Forgetting Header Files 40 CE 6 Roundoff Errors 41 PT 3 Spaces in Expressions 42 ST 4 Casts 42 ST 5 Combining Assignment and Arithmetic 42 C&S The Pentium Floating-Point Bug 43 2.3 INPUT AND OUTPUT 44 SYN Input Statement 44 2.4 PROBLEM SOLVING: FIRST DO IT BY HAND 47 WE1 Computing Travel Time 48 HT 1 Carrying out Computations 48 WE2 Computing the Cost of Stamps 51 2.5 STRINGS 51 C&S International Alphabets and Unicode 55 26 Numbers and character strings (such as the ones on this display board) are important data types in any C++ program. In this chapter, you will learn how to work with numbers and text, and how to write simple programs that perform useful tasks with them. 2.1 Variables When your program carries out computations, you will want to store values so that you can use them later. In a C++ program, you use variables to store values. In this section, you will learn how to define and use variables. To illustrate the use of variables, we will develop a program that solves the following problem.
  • Book cover image for: Java Concepts
    eBook - PDF

    Java Concepts

    Late Objects

    • Cay S. Horstmann(Author)
    • 2016(Publication Date)
    • Wiley
      (Publisher)
    2 C H A P T E R 31 FUNDAMENTAL DATA TYPES To declare and initialize variables and constants To understand the properties and limitations of integers and floating-point numbers To appreciate the importance of comments and good code layout To write arithmetic expressions and assignment statements To create programs that read and process inputs, and display the results To learn how to use the Java String type CHAPTER GOALS CHAPTER CONTENTS 2.1 VARIABLES 32 SYN Variable Declaration 33 SYN Assignment 36 SYN Constant Declaration 37 CE 1 Using Undeclared or Uninitialized Variables 39 PT 1 Choose Descriptive Variable Names 40 CE 2 Overflow 40 CE 3 Roundoff Errors 40 PT 2 Do Not Use Magic Numbers 41 ST 1 Numeric Types in Java 41 ST 2 Big Numbers 42 2.2 ARITHMETIC 43 SYN Cast 46 CE 4 Unintended Integer Division 48 CE 5 Unbalanced Parentheses 48 PT 3 Spaces in Expressions 49 J8 1 Avoiding Negative Remainders 49 ST 3 Combining Assignment and Arithmetic 49 VE 1 Using Integer Division C&S The Pentium Floating-Point Bug 50 2.3 INPUT AND OUTPUT 50 SYN Input Statement 51 PT 4 Use the API Documentation 55 HT 1 Carrying out Computations 56 WE 1 Computing the Cost of Stamps 2.4 PROBLEM SOLVING: FIRST DO IT BY HAND 59 WE 2 Computing Travel Time 2.5 STRINGS 61 ST 4 Instance Methods and Static Methods 66 ST 5 Using Dialog Boxes for Input and Output 67 VE 2 Computing Distances on Earth C&S International Alphabets and Unicode 68 ©sanxmeg/iStockphoto. 32 Numbers and character strings (such as the ones on this display board) are important data types in any Java program. In this chapter, you will learn how to work with numbers and text, and how to write simple programs that perform useful tasks with them. 2.1 Variables When your program carries out computations, you will want to store values so that you can use them later. In a Java program, you use variables to store values. In this section, you will learn how to declare and use variables.
  • Book cover image for: Principles Of Computer Programming NQF3 SB
    • S Sasti D Sasti(Author)
    • 2019(Publication Date)
    • Macmillan
      (Publisher)
    103 Module 6 Data storage and memory concepts in high-level programming Module 6 Overview At the end of this module, you will be able to: • Unit 6.1: Explain variables and constants. • Unit 6.2: Explain internal representation of data types. • Unit 6.3: Explain number conversion techniques between data types. • Unit 6.4: Understand and implement arithmetic operators in programming. Every software application needs to work with data whether it is stored or input by the user. In this module, we will revise these concepts, which were covered in Level 2, and introduce new concepts. We will also take an in-depth look at how the different types of data are stored in the computer’s memory and used by the software application to perform tasks or operations on the data. Unit 6.1: Variables and constants 6.1.1 Elements of a variable Definition: Variables Variables are used to store values that can change when an application is running. The values are stored temporarily in the computer’s random-access memory called RAM. A variable is a name given to a location which is a physical address in the computer’s RAM where data can be stored. A variable can hold only a single value at any given time. Since RAM is used for temporary storage, variables also hold data temporarily. For example, when the program ends, all data stored in RAM for those variables is erased. A variable consists of different elements as shown in Figure 6.1. The elements identified in Figure 6.1 are described in Table 6.1. Dim intNum AS Integer intNum = 10 Variable Scope Variable Name Variable Data type Variable Value to be stored Figure 6.1: Different elements of a variable 104 Topic 2 Table 6.1: Elements of a variable Element Description Name The word that is used to identify the variable in code. Address The physical address in the computer’s RAM where the value is stored for the variable. Every variable has a unique physical address. Data type The type and size of data that can be stored in the variable.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.