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

Importance of barrier free design and web accessibility, Problem: (a) ...

Problem: (a) Accessibility can be classified as below: (i) Barrier-free design (ii) Web accessibility. Describe the importance of barrier free design and web accessibi

Explain congestion, Explain CONGESTION. CONGESTION: This is uneconomi...

Explain CONGESTION. CONGESTION: This is uneconomic to provide sufficient equipment to carry entire traffic that could possibly be given to a telecommunication system. Inside

Processor technology , Processor Technology: Computers consist of elec...

Processor Technology: Computers consist of electronic components assembled in a design or "architecture" that will perform necessary functions of input, output, computation an

two arguments are passed, The velocity of sound in air is 49.02 feet p...

The velocity of sound in air is 49.02 feet per second where is the air temperature in degrees Rankine.  Write a function to execute this.  If just 1 argument is passed to the f

Determine about the verilog task, Determine about the Verilog Task - Ta...

Determine about the Verilog Task - Tasks are capable of enabling a function as well as enabling other versions of a Task. - Tasks also run with a zero simulation however the

Which datatype cannot be used to define parameters, Which datatype cannot b...

Which datatype cannot be used to define parameters. Type F datatype is not used to explain parameters.

Explain ones complement operator, One's Complement Operator: ~ The one'...

One's Complement Operator: ~ The one's complement operator, sometimes called the "bitwise complement" or "bitwise NOT" operator, produces the bitwise one's complement of its op

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

Initial considerations in problem solving, Initial considerations in proble...

Initial considerations in problem solving: Three initial considerations in problem solving for easiest(as described in Russell and Norvig):  Initial State  First

Testmanager can be used for performance testing, Rational Testmanager is a ...

Rational Testmanager is a complicated tool that can be used for automating performance tests on client/server systems. A client/server system have client applications accessing a d

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