Arrays
• Syntax: type arr.name[size];
• Eg: int marks[5];
• Let ‘A’ be a array in the memory
• Loc(A[K]) = address of the element A[K] of the array A.
• Elements of A are stored in successive memory cells, the address
of the first element of A is denoted by
• base(A)
called base address of A.
We can calculate the address of any element oa A by
the formula
Loc(A[K]) = Base(A)+W(K-lowerbound)
• Dynamically allocated arrays:
• Allocated the array during the run time, we
can call the function to allocate memory
– int * List n, I;
– malloc (list, n*sizeof(int));
Structures and Unions
• Structures:
– Structures are user- defined data types, and sung
Structures we can define a data-type which holds
more than one element of different types.
– Like primitive data types such as int, float, char etc.,
using Structures we can develop user- data types.
– The “General syntax”
struct <Identify>
{
data_type element1;
data_type element2; members of structure
.
.
};
• Eg: employee structure
struct employee
{
Int eno;
Char ename[20];
Float esal;
};
Struct Employee
26
bytes
Eno Ename esal
Type – defined structure
• The structure associated with keyword typedef is
called type-defined structure. This is the most
powerful way of defining the structure.
• Syntax:
Typedef struct {
{
Char name[10];
Int roll_no;
Float avq_marks;
} STUDENT;
– Where STUDENT is the datatype
Union
• A union is similar to a structure which is also
collection of data items of similar/ dissimilar
data types which are identified by unique
names using identifiers.
• All members of union share same memory
• All any point during execution only one
member is active.
• The general s
– The “General syntax”
union <tag_name>
{
type1 member1;
type1 member2; members of Union
.
.
};
Eg: typedef union
{
Inrt I;
Double d;
Char c;
} item;
introduction-to-data-structure-dsa1.pptx
introduction-to-data-structure-dsa1.pptx
introduction-to-data-structure-dsa1.pptx

introduction-to-data-structure-dsa1.pptx

  • 2.
  • 3.
    • Syntax: typearr.name[size]; • Eg: int marks[5]; • Let ‘A’ be a array in the memory • Loc(A[K]) = address of the element A[K] of the array A. • Elements of A are stored in successive memory cells, the address of the first element of A is denoted by • base(A) called base address of A. We can calculate the address of any element oa A by the formula Loc(A[K]) = Base(A)+W(K-lowerbound)
  • 4.
    • Dynamically allocatedarrays: • Allocated the array during the run time, we can call the function to allocate memory – int * List n, I; – malloc (list, n*sizeof(int));
  • 5.
    Structures and Unions •Structures: – Structures are user- defined data types, and sung Structures we can define a data-type which holds more than one element of different types. – Like primitive data types such as int, float, char etc., using Structures we can develop user- data types. – The “General syntax” struct <Identify> { data_type element1; data_type element2; members of structure . . };
  • 6.
    • Eg: employeestructure struct employee { Int eno; Char ename[20]; Float esal; }; Struct Employee 26 bytes Eno Ename esal
  • 7.
    Type – definedstructure • The structure associated with keyword typedef is called type-defined structure. This is the most powerful way of defining the structure. • Syntax: Typedef struct { { Char name[10]; Int roll_no; Float avq_marks; } STUDENT; – Where STUDENT is the datatype
  • 8.
    Union • A unionis similar to a structure which is also collection of data items of similar/ dissimilar data types which are identified by unique names using identifiers. • All members of union share same memory • All any point during execution only one member is active.
  • 9.
  • 10.
    – The “Generalsyntax” union <tag_name> { type1 member1; type1 member2; members of Union . . }; Eg: typedef union { Inrt I; Double d; Char c; } item;