Review of Arrya Structure Pointer Union and Class

-- Leave a Comment
We will be discussing about data structure. You should have knowledge in basic programming. We will be using C and Java for some example programming. Here we would discuss about Array, Structure, Pointer and Class. These are the topics we will be using throughout this article series in Data Structures.

Array

Array is primitive data member provided by C programming. Array is the collection of similar data types. Memory allocation of the array is sequential. ie. Array are stored in contiguous block of memory. Array only supports similar data type. Strings are the array of character with \0 at the end. \0 = NULL

Structure

Structure is the collection of different type of data type. In C programming Structure is the only way to create complex data type. Structure is the heterogeneous collection of data. Theoretically it will not occupy any memory unless we create the variable of that Structure. Memory allocation  of structure is sequential. We can access members of array with dot operation(.) and Arrow operation(->). Dot operation is used to access memory of structure variables. and Arrow operation is used to access members from Pointer of the structure.

1
2
3
4
5
6
struct Person
{
    char name[30];
    int age;
    char address[40];
}

Self Referencial Structure

The structure that is pointing to self is called self referential structure. Ie a member of structure is pointer to that structure
struct list

1
2
3
4
5
struct List
{
    int age;
    struct List *next;
}

Union

It is similar as of the structure. The only difference is that union only occupy the memory of the largest member data. So we car use only one data of the union at a time. Can there be pointer to union? yes they can be :)

Courses to Complete During Software Engineering

Pointer

What is pointer in a word? A pointer is a variable. A pointer is a reference variable which store memory location. All the pointer occupy same memory bits. The pointer of the floating point data and the integer data. will occupy only 2 bits of memory. What is Void Pointer and null pointer? Void pointer is the pointer that can point to any kind of data type. This make use of type casting to to this job. Null pointer os the pointer which points to non or invalid address. Remember Structure pointer can only point to structure.

float data type is of 4 bit of memory, so when pointer points to the floating point it will point the base address of the variable. Points to the starting block of the memory for that variable.

Class

A class is data type. class is user defined variable that can be used to create objects. The difference between the structure and the class is that class have methods (Behaviour) which structure does not have. When ever the object are created the members are copied to the variables but not the methods. All the objects share the same methods. What is Abstract class? The class which have pure virtual function and cannot make any object.

Abstract means hiding the implementation details. We Drive the car but it is no concern to use how all the functions in the car works.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment