You are on page 1of 9

User-Defined

Data Type

mira@polibatam.ac.id
Introduction

In addition to the basic data types in C


such as int or float, sometimes we
need data types that we create
ourselves but are still based on the
standard.
redefine the name of
an already existing
basic type
1
There are several ways to
structured type 2 create user-defined type:

union type 3

 Similar to struct in declaration


 Variables created are shared a common memory space
 Not discussed on this subject
Redefine The Name Of An Already
Existing Basic Type

Keyword

typedef

Definition

The typedef keyword is used to assign


a new name or "alias" to an existing
variable. In other words we can
redefine an existing variable name
using this keyword.
Example

pseudocode C language

type <alias_name> : <existing_name> typedef <existing_name> <alias_name>;

Type unit : integer redefine integer to unit typedef int unit;


M : unit variable declaration unit M;

Type huruf : char typedef char huruf;


N : huruf Huruf N;
Structured Type

Keyword

struct

Definition

struct keyword is used to define a


structure or a new data type which is a
collection of primary and derived
datatypes
Example

pseudocode C language

type number_set : record <dec : real, struct number_set {


unit : int> float dec; int unit; };
N1, N2, N3 : number_set number_set N1, N2, N3;
Individual Task

Create an algorithm to calculate


the distance between 2 points,
use a structured data type to
create a point data type
consisting of X and Y coordinates.

 Write your task in word named


T10_NIM.docx
Thank you

mira@polibatam.ac.id

You might also like