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

Applied physics, #what is nicol prism.its construction and working

#what is nicol prism.its construction and working

State about the object oriented analysis design, State about the Object ori...

State about the Object oriented analysis design Object oriented analysis design (OOAD) is a bottom up approach which supports viewing system as a set of components (objects) w

Mating - canonical genetic algorithm, Mating: Therefore once our GA ag...

Mating: Therefore once our GA agent has chosen the individuals lucky sufficient as actually there  fit enough to produce offspring then we next determine how they are going to

How do active web pages work, How do active web pages work? Describe with a...

How do active web pages work? Describe with a small example. Active Web Pages: An active document is not completely specified through the server. Instead an active documen

Define about the objects, Define about the Objects The object notation...

Define about the Objects The object notation is the same in basic form as that for a class. There are three differences among the notations, these are given below: With

Engineering applications, Engineering Applications A few of the enginee...

Engineering Applications A few of the engineering applications are: Airflow circulation over aircraft machinery, Simulations of simulated ecosystems. Airflow c

Define pipeline speedup, Define pipeline speedup. S(m)=T(l)/T(m) Whe...

Define pipeline speedup. S(m)=T(l)/T(m) Where T(m) is the execution time for some target workload on an m-stage pipeline. T(l) is the execution time for some workload an

Example on public divisor, Q. Example on PUBLIC DIVISOR? Linker appends...

Q. Example on PUBLIC DIVISOR? Linker appends all segments having the same name and PUBLIC directive with segment name into one segment. Their contents are pulled together in co

Which scheduling in cpu is allocate for least cpu-burst time, The schedulin...

The scheduling in which CPU is allocated to the process with least CPU-burst time is called? Ans. Shortest job first Scheduling wherein CPU is allocated to the process with lea

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