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

7 Key excerpts on "Data Types in Programming"

  • Learn C Programming
    This is very much like the byte sequences the compiler generates, which the CPU processes. Internally, commands, addresses, and data in the computer are nothing more than sequences of 1s and 0s of various sizes. So, how the computer interprets the patterns of 1s and 0s is entirely dependent upon the context given to them by the computer language and the programmer.
    We, as programmers, must provide the guidelines to the compiler, and consequently to the CPU, on how to interpret the sequence. We do this in C by explicitly assigning a data type to the data we want to manipulate. The data type of a value provides the context to correctly interpret a sequence of bits.
    C is a strongly typed language. That is, every value must have a type associated with it. It should be noted that some languages infer the type of a piece of data by how it is used. They will also make assumptions about how to convert one data type into another. These are called loosely typed languages . C also does automatic, or implicit, conversions from one type into another, but the rules are fairly specific compared to other programming languages. We can also perform manual, or explicit, conversions with type casting . Type casting is an operation that we might need to do to a value; it will be covered in greater detail in Chapter 5 , Exploring Operators and Expressions .
    In C, as in most programming languages, there are five basic, and intrinsic , data types. The five basic types are as follows:
    • Whole numbers : These numbers can represent a positive-only range of values or a range that includes both positive and negative values.
    • Numbers with fractions or decimal numbers : These are all of the numbers between whole numbers, such as ½, ž, 0.79, and 1.125, as well as other numbers that aren't easily represented using fractions. One such common number is 3.14159, which is a very approximate value for π, or even 3.1415926535897932384626433 – an even more precise but still approximate value for π. Decimal numbers can always include negative values.
    • Characters : These are the basis of C strings. Some languages have a separate string type. In C, strings are a special case of arrays of characters – they are not a data type but a special arrangement of contiguous character values. We will begin our encounter with arrays in Chapter 11 , Working with Arrays , and then look at strings specifically in Chapter 15 , Working with Strings
  • Software Design
    eBook - ePub

    Software Design

    A Comprehensive Guide to Software Development Projects

    6   Data, Storage, and Retrieval     What Is Data?
    Data, as defined in Chapter 1 , is facts about entities. An entity can be:
    1.A person. 2.A location. 3.An object. 4.A system. 5.An equipment. 6.An item of material. 7.A transaction. 8.A town. 9.It can be anything that has some attributes by which it is described!
    Facts can be in figures or be descriptive. For example, a person has a name, which is descriptive in nature; has a weight, which is expressed in numbers; has an educational qualification, which is descriptive; has an income, which is described in figures; has a date of birth, which is a special type of number; and has a title, which is again descriptive. In this manner, all entities have some facts and figures associated with them.
    While each entity has facts and figures about it, we are not interested in all entities. We are interested in those entities whose data needs to be stored in our computer system, processed, and reported as required.
      Basic Data Types Data is basically of two types 1.The data that human beings use 2.The data used solely by the computer and its I/O devices As programmers, we might need to handle both types of data. Then, the data used by human beings is of two types, namely
    1.Character data : The data that contains alphabets and perhaps numbers, too
    2.Numeric data : The data that is expressed only in numbers
      Character Data
    Character data includes any character that can be input to the computer. What are characters, in the context of computers? They can be anything accepted by the computers. IBM used extended binary coded decimal interchange code (EBCDIC) codification of characters for its mainframe computers. It is an 8-bit code that allows 256 characters to be codified. Later, the American Standards Association finalized the standard for codification of characters for use in computers and called it the American Standard Code for Information Interchange (ASCII). It was originally a 7-bit code, but has been extended to 8 bits and allows 256 characters to be codified. It codifies alphabets (uppercase and lowercase), digits (0–9), and other special characters that are both humanly readable (like space, (, ), [, ], and so on) and not humanly readable (like the enter button, CTRL+
  • Revival: The Handbook of Software for Engineers and Scientists (1995)
    • Paul W Ross(Author)
    • 2018(Publication Date)
    • CRC Press
      (Publisher)
    Early versions of C had an easily used interface to the Unix operating systems. C provides several features that aid systems programmers: bitfields, shift operators, etc. Current uses of C have expanded from systems programming to general applications programming of all types. One of the central characteristics of C is that it is a typed language. All identifiers have a type assigned to them, either by the language itself in the case of reserved identifiers, or by the user in the case of user-defined names, like variable names or function names. In general, a type is a description of the kinds of values that a particular identifier can hold, and the operations that can be performed on those data. The philosophy of types in C is somewhat less rigorous than this general definition. The fact that all data are stored as strings of bits is more obvious in C.C types give alternative ways of viewing those bit strings. For example, a string of bits can be viewed as an integer, or can be interpreted as the ASCII code corresponding to that integer. Types must be associated with an identifier prior to the first use of that identifier. In the case of variables, this association occurs during a declaration. We will discuss C’s types in the next section. As described in the previous section, C supports structured programming through its control constructs: sequencing as a default, decisions through the if and if-else structures, and repetitions through for loops, while loops, and do loops. C is considered to be a block structured programming language. A block of statements, i.e., a sequence of statements surrounded by braces { }, can appear anywhere that a single statement is legitimate. Variables can be declared at the beginning of such a block
  • API Design Patterns
    • JJ Geewax(Author)
    • 2021(Publication Date)
    • Manning
      (Publisher)

    5 Data types and defaults

    This chapter covers
    • What we mean by data types
    • How a null value differs from one that’s missing entirely
    • An exploration of the various primitive and collective data types
    • How to handle serialization for various data types
    When designing any API, we always have to think of the types of data we want to accept as input, understand, and potentially store. Sometimes this sounds pretty straightforward: a field called “name” might just be a string of characters. Hidden in this question though is a world of complexity. For example, how should the string of characters be represented as bytes (it turns out there are lots of options for this)? What happens if the name is omitted in an API call? Is that any different from providing an empty name (e.g., { "name": "" } )? In this chapter we’ll explore the various data types you will almost certainly experience when designing or using APIs, how best to understand their underlying data representation, and how best to handle the default values of the various types in a sane and straightforward way.

    5.1 Introduction to data types

    Data types are an important aspect of almost every programming language, telling the program how to handle a chunk of data and how it should interact with the variety of operators provided by the language or the type itself. And even in languages with dynamic typing (where a single variable can act as lots of different data types rather than being restricted to a single one), the type information at a single point in time is still quite important, dictating how the programming language should treat the variable.
    However, when designing APIs, we have to break out of the mode of thinking of a single programming language primarily because a major goal of our API is to let anyone, programming in any language, interact with the service. The standard way we do that is by relying on some serialization protocol, which takes a structured representation of data in our programming language of choice and converts it into a language-agnostic representation of serialized bytes before sending it to a client who asked for it. On the other end, the client deserializes these bytes and converts them back into an in-memory representation that they can interact with from the language they use (which may or may not be the same as ours). See figure 5.1 for an overview of this process.
  • C++ Programming
    eBook - ePub
    • Li Zheng, Yuan Dong, Fang Yang(Authors)
    • 2019(Publication Date)
    • De Gruyter
      (Publisher)
    Comments in a program are used to explain and interpret the program to improve its readability. When the compiling system compiles the source program, it first strips the comments. Thus comments have no effect on the realization of a program’s functions. In addition, since they are stripped by the compiler before code generation, they will not increase the size of the final executable program. Comments, if used properly, can make a program more readable.
    There are two ways to add comments in C++. One follows the C language, using “/*” and “*/” to enclose comments just as follows: Here all the symbols between “/*” and “*/” are to be recognized as comments. The other way uses “//” to delimit a single-line comment. Starting from “//” and ending until the finishing point of that line, all the characters in between are viewed as comments. For example,

    2.2Basic Data Types and Expressions

    Data are the objects programs process. They can be classified according to their characteristics. For example, in mathematics there are concepts like integers, real numbers, etc.; in daily life we need character strings to denote a person’s names and addresses; the answers of some questions can only be “yes” or “no” (i.e., “true” or “false” in logic). Different types of data have different processing methods. For example, both integers and real numbers can participate in arithmetical operations, while real numbers differ from integers in that they have to retain a certain part of decimal fractions; character strings can be concatenated; logical data can participate in logical operations such as “and”, “or”, “non-”, etc.
    We write programs to solve practical questions in the objective world. Therefore, high-level languages provide us with a wealth of data types and operations. C++ data types are divided into two categories: basic data types and user-defined data types. Basic data types are predefined within the C++ compiler system. Wewill first introduce the basic data type in this section.

    2.2.1Basic Data Types

    Basic C++ data types are shown in Table 2.1 .
    We can see from Table 2.1 that basic C++ data types include bool (Boolean type), char (character type), int (integer type), float (floating-point type, representing real numbers), and double (double-precision floating-point type, or double-precision type). Apart from bool these data types can be classified into two main categories: integer and floating-point. char is an integer type essentially. It is a one-length integer, so usually we use the ASCII code to store characters. Keywords signed , unsigned , short , and long
  • Beginning JavaScript
    • Jeremy McPeak(Author)
    • 2015(Publication Date)
    • Wrox
      (Publisher)
    2 Data Types and Variables
    WHAT YOU WILL LEARN IN THIS CHAPTER:                
    • Representing data in code
    • Storing data in memory
    • Making calculations
    • Converting data
    WROX.COM CODE DOWNLOADS FOR THIS CHAPTER
    You can find the wrox.com code downloads for this chapter at http://www.wiley.com/go/BeginningJavaScript5E on the Download Code tab. You can also view all of the examples and related files at http://beginningjs.com .
    One of the main uses of computers is to process and display information. By processing, we mean the information is modified, interpreted, or filtered in some way by the computer. For example, on an online banking website, a customer may request details of all money paid out from his account in the past month. Here the computer would retrieve the information, filter out any information not related to payments made in the past month, and then display what’s left in a web page. In some situations, information is processed without being displayed, and at other times, information is obtained directly without being processed. For example, in a banking environment, regular payments may be processed and transferred electronically without any human interaction or display.
    In computing, information is referred to as data. Data comes in all sorts of forms, such as numbers, text, dates, and times, to mention just a few. In this chapter, you look specifically at how JavaScript handles data such as numbers and text. An understanding of how data is handled is fundamental to any programming language.
    In this chapter you start by looking at the various types of data JavaScript can process. Then you look at how you can store this data in the computer’s memory so you can use it again and again in the code. Finally, you see how to use JavaScript to manipulate and process the data.

    TYPES OF DATA IN JAVASCRIPT

    Data can come in many different forms, or types
  • Ivor Horton's Beginning Visual C++ 2008
    • Ivor Horton(Author)
    • 2011(Publication Date)
    • Wrox
      (Publisher)
    CChutney , each defined specifically for the kind of problem that you want to solve, complete with the functions and operators that are necessary to manipulate instances of your new types.
    Program design now starts with deciding what new application-specific data types you need to solve the problem in hand and writing the program in terms of operations on the specifics that the problem is concerned with, be it CCoffins or CCowpokes .
    Terminology I'll first summarize some of the terminology that I will be using when discussing classes in C++:
    • A class is a user-defined data type.
    • Object-oriented programming (OOP) is the programming style based on the idea of defining your own data types as classes.
    • Declaring an object of a class type is sometimes referred to as instantiation because you are creating an instance of a class.
    • Instances of a class are referred to as objects.
    • The idea of an object containing the data implicit in its definition, together with the functions that operate on that data, is referred to as encapsulation.
    When I get into the detail of object-oriented programming, it may seem a little complicated in places, but getting back to the basics of what you're doing can often help to make things clearer, so always keep in mind what objects are really about. They are about writing programs in terms of the objects that are specific to the domain of your problem. All the facilities around classes in C++ are there to make this as comprehensive and flexible as possible. Let's get down to the business of understanding classes.
    Understanding Classes
    A class is specification of a data type that you define. It can contain data elements that can either be variables of the basic types in C++, or of other user-defined types. The data elements of a class may be single data elements, arrays, pointers, arrays of pointers of almost any kind, or objects of other classes, so you have a lot of flexibility in what you can include in your data type. A class also can contain functions that operate on objects of the class by accessing the data elements that they include. So, a class combines both the definition of the elementary data that makes up an object and the means of manipulating the data that belongs to individual objects of the class.
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.