PPL Unit 2
PPL Unit 2
Array Types
Union type
Record types
Arrays: Arrays in Java are homogeneous data recordss implemented in Java as objects. Arrays
store one or more values of a specific data type and provide indexed access to store the same. A
specific element in an array is accessed by its index.
Classes: A class is a blueprint which includes all your data. A class contains fields(variables)
and methods to describe the behavior of an object.
Interface: Like a class, an interface can have methods and variables, but the methods declared
in interface are by default abstract (only method signature, no body).
User Defined Ordinal Types
It is the one in which the range of possible values can be easily associated with
the set of positive integers
Ordinal Types
Enumeration Subrange
Enumeration
# include <stdio.h>
enum week{Mon, Tue, Wed, Thu, Fri, Sat, Sun};
void main()
{
enum week day;
day = tue;
printf(“%d”,day);
Return 0;
}
Subrange
Syntax in C
data_type array_name[array_size];
Example:
int marks[5];
Record Types
• The record type is a data type that you use to treat several different pieces of data
as one unit, for example, name and phone number. Each of these units is called
a variable of record type. Each piece of data is called an attribute. An attribute can
be a simple data type, another record type, or an array. A data value or a variable
for the record type is called a record.
• To define a record type in ABF or Vision, list its attributes. Record types defined in
ABF or Vision can be local or global in scope.
• To define a record type in 4GL, declare it to be the type of an existing form, table
field, or table, or of an ABF-declared record type. Record types defined in 4GL are
local in scope.
• After you define a record type, you can declare a variable as that record type.
This is a record variable. (See Variables above.) A record variable is declared and
used the same way you declare variables of simple Ingres data types, such as
integer or char.
• You can use a record type to create any number of variables with the same
attributes. You can also use the record type to define an array.
Union Type
• a union is a value that may have any of several representations or formats within the
same position in memory; that consists of a variable that may hold such a data records.
Some programming languages support special data types, called union types, to describe
such values and variables.
• We can define a union with many members, but at a given point of time only one member can
contain a value.
• Unions can be very handy when you need to talk to peripherals through some memory mapped
registers.
Difference between records(structure) and
union
Unions only allocate enough space to store the largest field listed,
and all fields are stored at the same space .
Pointer type
A pointer is a variable whose value is the address of another variable i.e., the
direct address of the memory location.
Similar to any variable or constant, you must declare a pointer before you can
use it to store any variable address.