0% found this document useful (0 votes)
40 views9 pages

User-Defined Data Type: Mira@polibatam - Ac.id

The document discusses different ways to create user-defined data types in C including: 1. Using typedef to redefine the name of an existing basic type like int or char. This allows creating an alias for a type. 2. Using struct to define a structured type which collects different data types into a single type. Struct is used to create custom types for storing related data. 3. Using union which allows storing different data types in the same memory space. Unions are not discussed further in the document.

Uploaded by

Jay Nipanjati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views9 pages

User-Defined Data Type: Mira@polibatam - Ac.id

The document discusses different ways to create user-defined data types in C including: 1. Using typedef to redefine the name of an existing basic type like int or char. This allows creating an alias for a type. 2. Using struct to define a structured type which collects different data types into a single type. Struct is used to create custom types for storing related data. 3. Using union which allows storing different data types in the same memory space. Unions are not discussed further in the document.

Uploaded by

Jay Nipanjati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

User-Defined

Data Type

[email protected]
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

[email protected]

You might also like