Data types and Escape sequence

Data types and Escape sequence

Published by: Nuru

Published date: 21 Jun 2021

Data types and Escape sequence Photo

Data types and Escape sequence

The data type is an attribute that describes the nature of data to be stored in memory. C language is rich in its data types. There are other varieties of data types available in C, each of which may be represented differently within the computer’s memory. These varieties of data types allow the programmer to select the type needed in his/her application. There are various types of data. For e.g., data 10 and 10.5 are of different types. The data 10 is an integer while 10.5 is a fractional number.

ANSI C supports 3 classes of data types:

  1. Primary (or fundamental) data types
  2. Derived data types
  3. User-defined data types

Primary Data Type

The primary data types are categorized into five types:

I. Integer type (int)- a whole number
II. Floating point type (float)- a number with a fraction part
III. Double precision floating type (double)-a number with double precise value than float
IV. Character type (char)-a single character
V. Void type (void)-holds no value used to specify the type of function or what it returns

 

Derived data types

C supports three derived data types:

    1. Arrays: Arrays are sequences of data items having homogeneous values. They have adjacent memory locations to store values.
    2. Pointers: These are powerful features that are used to access the memory and deal with their address.
    3. References: Function pointers allow referencing functions with a particular signature.

 

User-Defined Data Types

C allows the feature called type definition which allows programmers to define their identifier that would represent an existing data type. There are three such types:

Structure It is a package of variables of different types under a single name. This is done to handle data efficiently.
"struct" keyword is used to define a structure.
Union These allow storing various data types in the same memory location. Programmers can define a union with different members, but only a single member can contain a value at a given time. A keyword union is used.
Enum Enumeration is a special data type that consists of integral constants, and each of them is assigned with a specific name. "enum" keyword is used to define the enumerated data type.

Datatypes and their sizes

some of the most used data types and their sizes are given below:

 

Data types and Escape sequence

Escape sequence of C

An escape sequence is a non-printing character in C. it is a character combination consisting of a backslash(\)followed by a letter or digit. The escape sequence is useful for formatting input and output.

some of the common escape sequence characters  along with their function are:

Data types and Escape sequence