Data Types in C: An Overview, Lecture notes of C programming

An introduction to data types in the c programming language. It covers the different types of data, including basic types (integer and floating-point), derived types (pointers, arrays, structures, unions, and functions), and the void type. The document also includes tables detailing the storage sizes, value ranges, and precisions for various data types.

Typology: Lecture notes

2018/2019

Uploaded on 02/26/2019

Bulgaria1999
Bulgaria1999 🇺🇸

5 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Central Florida
COP 3223C
Introduction to Programming in C
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Data Types in C: An Overview and more Lecture notes C programming in PDF only on Docsity!

University of Central Florida

COP 3223C

Introduction to Programming in C

  • (^) Data types in C refer to an extensive system

used for declaring variables or functions of

different types.

  • (^) The type of a variable determines how much

space it occupies in storage and how the bit

pattern stored is interpreted

  • (^) The types in C can be classified as follows
    • (^) void
      • (^) The type specifier void indicates that no value is

available

  • (^) Derived types
    • (^) They include
      • (^) Pointer types
      • (^) Array types
      • (^) Structure types
      • (^) Union types
      • (^) Function types
  • (^) The types in C can be classified as follows
    • (^) Derived types
      • (^) The array types and structure types are referred

collectively as the aggregate types.

  • (^) The type of a function specifies the type of the

function's return value.

  • (^) We will see the basic types in the following section,

where as other types will be covered in the upcoming

chapters.

Type Storage size Value range

  • char 1 byte -128 to 127 or 0 to
  • unsigned char 1 byte 0 to
  • signed char 1 byte -128 to
    • -32,768 to 32,767 or -2,147,483,648 to 2,147,483, int 2 or 4 bytes
  • unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,
  • short 2 bytes -32,768 to 32,
  • unsigned short 2 bytes 0 to 65,
  • long 4 bytes -2,147,483,648 to 2,147,483,
  • unsigned long 4 bytes 0 to 4,294,967,
  • (^) To get the exact size of a type or a variable on

a particular platform, you can use

the sizeof operator.

  • (^) The expressions sizeof(type) yields the storage

size of the object or type in bytes.

  • (^) Given next is an example to get the size of int

type on any machine

  • (^) Floating-Point Types
    • (^) The next table provide the details of standard floating-point types with storage sizes and value ranges and their precision
    • (^) The header file float.h defines macros that allow you to use these values and other details about the binary representation of real numbers in your programs.

Type Storage size Value range Precision float 4 byte 1.2E-38 to 3.4E+38 6 decimal places double 8 byte 2.3E-308 to 1.7E+ 15 decimal places long double 10 byte 3.4E-4932 to 1.1E+ 19 decimal places

  • (^) The void Type
    • (^) The void type specifies that no value is available.
    • (^) It is used in three kinds of situations
      • (^) Function returns as void
        • (^) There are various functions in C which do not return any value or you can say they return void.
        • (^) A function with no return value has the return type as void.
        • (^) For example, void exit (int status);
      • (^) Function arguments as void
        • (^) There are various functions in C which do not accept any parameter.
        • (^) A function with no parameter can accept a void.
        • (^) For example, int rand(void);
  • (^) The void Type
    • (^) It is used in three kinds of situations
      • (^) Pointers to void
        • (^) A pointer of type void * represents the address of an object, but not its type.
        • (^) For example, a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any data type
        • (^) More about this later!!!!