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

Describe about the digital cameras, Describe about the Digital cameras ...

Describe about the Digital cameras The microprocessor would be used to control the below functions, for instance: - shutter speed - lens focus - Flash - Aperture (l

Computer Architecture, As an advocate of CISC architecture to RISC architec...

As an advocate of CISC architecture to RISC architecture, what are the merits and demerits of CISC to RISC architecture

Illustration of an instruction cycle, Q. Illustration of an instruction cyc...

Q. Illustration of an instruction cycle? Instruction cycle displayed in given figure comprises subsequent stages: First address of the subsequent instruction is calculat

What is an assembler, An assembler is? Ans. An assembler is Machine dep...

An assembler is? Ans. An assembler is Machine dependant.

When can we see layer groups in gimp, Sometimes it is nice to place layers ...

Sometimes it is nice to place layers in groups. It makes them simple to organize when you have lots of them. It also means you can simply apply the similar effect to lots of layers

Fuzzy logic - artificial intelligence, Fuzzy set theory provides a means fo...

Fuzzy set theory provides a means for modeling the kind of uncertainty associated with vagueness, with imprecision, and/or with a lack of information regarding a particular element

Estimate the size of the state space, 1. The missionaries and cannibals pro...

1. The missionaries and cannibals problem. Three missionaries and three cannibals are on the left river bank, with a boat that can hold one or two people. If on either side of the

Variables and quantifiers for first-order models , Variables and Quantifier...

Variables and Quantifiers for First-order models -artificial intelligence: So what do sentences containing variables mean? In other words, how does first order model select whe

Working of read-only memory, Q. Working of Read-Only Memory? A ROM is f...

Q. Working of Read-Only Memory? A ROM is fundamentally a memory or storage device in which a fixed set of binary information is stored. A block diagram of ROM is as displayed i

Why is cloud computing important, Why is Cloud Computing important? The...

Why is Cloud Computing important? There are many implication of cloud technology, for both developers and end users. For developers, cloud computing gives increased amounts of

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