0% found this document useful (0 votes)
63 views13 pages

PPL Unit 2

This document discusses different data types in programming languages including primitive, non-primitive, array, class, interface, enumeration, subrange, record, union, and pointer types. It provides details on each type such as how primitive types are predefined while non-primitive types are created by the programmer. It also explains that arrays store multiple values of the same type using indexes, classes define data and behaviors of objects, and interfaces contain abstract method signatures.

Uploaded by

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

PPL Unit 2

This document discusses different data types in programming languages including primitive, non-primitive, array, class, interface, enumeration, subrange, record, union, and pointer types. It provides details on each type such as how primitive types are predefined while non-primitive types are created by the programmer. It also explains that arrays store multiple values of the same type using indexes, classes define data and behaviors of objects, and interfaces contain abstract method signatures.

Uploaded by

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

Unit 2

Structuring the Data,


Computations & Programs
Primitive Data Type

Character String Type

Elementary Data Types


User Defined Ordinal types

Array Types

Union type

Record types

Pointer Reference Type


Primitive Data Types:
A primitive data type is pre-defined by the programming language.
The size and type of variable values are specified, and it has no
additional methods.

Non-Primitive Data Types:


These data types are not actually defined by the programming
language but are created by the programmer. They are also called
“reference variables” or “object references” since they reference a
memory location which stores the data.
Strings: String is a sequence of characters. But in Java, a string is an object that represents a
sequence of characters. The java.lang.String class is used to create a string object.

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

It is an user defined data type in C and mainly used to assign


names to integral constant

# 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

Defines the subset of values of a particular type.

Int digit = 0…9;


Char = ‘A’…’Z'
Array data type
an array type is a data type that represents a collection
of elements

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.

• It is a collection of variables of different datatypes in the same memory location.

• 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

The main difference between records and a union is that, records


allocate enough space to store all of the fields in the struct. The first
one is stored at the beginning of the record, the second is stored after
that, and so on.

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.

The syntax of a pointer is −


type *var-name;

You might also like