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

What are different edi components and edi services, What are different EDI ...

What are different EDI components and EDI services? Different EDI components and EDI services are illustrated as: Three main components including services in EDI System are

Explain common sub expression elimination, Explain briefly Common sub ex...

Explain briefly Common sub expression elimination of the commonly used code optimization techniques. Common sub expression elimination: In given expression as "(a+b)-(

Define the term web service with example, Define the term web service with ...

Define the term web service with example. A web service is an application that operate over a network-typically, over the Internet. Most typically, a web service is an API that

Describe the horizontal frequency or cycle, Q. Describe the Horizontal Freq...

Q. Describe the Horizontal Frequency or cycle? Horizontal Frequency: The time to scan one line connecting the right edge to left edge of the screen horizontally is known as t

Planning too much up front a mistake in an oosad, You can't plan only for t...

You can't plan only for the present phase of the project as your future activities are still coarse granular. To have good planning you require to have fine granularity w.r.t the t

Classical approach - canonical genetic algorithm, Classical approach - Cano...

Classical approach - Canonical genetic algorithm: However returning to the classical approach, as there example, whether solving a particular problem involved finding a set of

Validate the xml document , As an XML expert you are needed to model a syst...

As an XML expert you are needed to model a system for an online furniture shop. After an interview with the shop manager you have the certain information: The detail of th

Describe the types of flip-flops and latches, Describe the types of flip-fl...

Describe the types of flip-flops and latches. Flip-flops are of two types as illustrated below: a. Positive edge triggered b.  negative edge triggered Latches are

Explain creating files for writing only in c, Creating Files for Writing On...

Creating Files for Writing Only Creating Files for Writing Only : To create a text file for writing only, pass "w" into fopen as the second argument. This example follows along

At least two optional data fields, As an XML expert you are needed to model...

As an XML expert you are needed to model a system for an online furniture shop. After an interview with the shop manager you have the certain information: The detail of th

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