What are the advantages of using structure in c program, Computer Engineering

Assignment Help:

What are the advantages of using structure in C Program

Declaring a struct is a two-stage process. The first stage defines a new data type that has the required structure which can then be used to declare as many variables with the same structure as required. For example, suppose we need to store a name, age and salary as a single structure. You would first define the new data type using:

struct emprec

{

char name[25];

int age;

int pay;

};

and then you would declare a new variable:

struct emprec employee

Notice that the new variable is called employee and it is of type emprec which has been defined earlier.

To get the individual components of a structure you have to use qualified names. i.e. You first give the name of the structure variable and then the name of the component separated by a dot. For example, given:

struct emprec employee

then: employee.age is an int and:

employee.name

is  a  char  array.  Once  you  have  used  a  qualified  name  to  get  down  to  the  level  of  a component then it behaves like a normal variable of the type. For example: employee.age=32;

is a valid assignment to an int

As we have seen, a structure is a good way of storing related data together. It is also a good way of representing certain types of information. Complex numbers in mathematics inhabit a two dimensional plane (stretching in real and imaginary directions). These couldeasily be represented here by

struct {

double real;

double imag;

} complex;

In a similar way, structures could be used to hold the locations of points in multi- dimensional space. Mathematicians and engineers might see a storage efficient implementation for sparse arrays here.

Apart from holding data, structures can be used as members of other structures. Arrays of structures are possible, and are a good way of storing lists of data with regular fields, such as databases.

Another possibility is a structure whose fields include pointers to its own type. These can be used to build chains (programmers call these linked lists), trees or other connected structures.

 


Related Discussions:- What are the advantages of using structure in c program

Callable modules of program code within one abap/4 program, How can we crea...

How can we create callable modules of program code within one ABAP/4 program? We can create callable modules by two techniques:- By defining Macros. By creating incl

Target_parent, TARGET = "_parent" "_parent" is used in a situation whe...

TARGET = "_parent" "_parent" is used in a situation where a frameset file is nested inside another frameset file. A link in one of the inner frameset documents that uses "_par

Why is segmented paging important, Why is segmented paging important (as co...

Why is segmented paging important (as compared to a paging system)? Paging can be super-imposed upon a segment oriented addressing mechanism to acquire efficient use of the mem

Describe data structures used during passes of assembler, Describe Data str...

Describe Data structures used during passes of assembler and their use. During passes of assembler, the Data structures define as: Pass 1 data base Input source pro

What are interrupts, What are interrupts?  Interrupt: An interrupt i...

What are interrupts?  Interrupt: An interrupt is a hardware mechanism which enables an external device, classically input/output devices, to send a signal to the CPU. An int

State the number of definitions of firewall, State the number of definition...

State the number of definitions of firewall Though there exist a number of definitions of firewall, in simplest terms it can be defined as "a mechanism used to protect a truste

Collective communications - broadcast, Q. Collective Communications - Broad...

Q. Collective Communications - Broadcast? Broadcast: Broadcasting can be done in two ways one of them is one to all and another one is all to all. In the matter of one to all b

What is random access memory, Q. What is Random Access Memory? We will ...

Q. What is Random Access Memory? We will discuss RAM as an example of sequential circuit. A memory unit is a collection of storage cells or flip flops along with associated cir

What is literal, Meaning of Literal is:- Literal is string constant.

Meaning of Literal is:- Literal is string constant.

Career after BSc CS, Sir,wish to receive guidance from you how to join in A...

Sir,wish to receive guidance from you how to join in Aeronautical Engineering after Bsc Computer Science. I am a Girl.Interested to work in AE field, it will be better to use in co

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd