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

Integrated test result, COGNITIONS Mr. X exhibits a generally high-quali...

COGNITIONS Mr. X exhibits a generally high-quality level of cognitive and intellectual functioning, as evidenced by his performance on the MMSE-2 and WAIS-IV. His one weakness w

What is segment directive, Q. What is SEGMENT Directive? Segment direct...

Q. What is SEGMENT Directive? Segment directive defines logical segment to which following instructions or data allocations statement belong.  It also provides a segment name t

What is backward compatible, A program is backward compatible if it can use...

A program is backward compatible if it can use files from an older version of itself. For a file saved in the program to be backward compatible, it must be possible to open the fil

Function of host to host transport layer in tcp/ip protocol, Illustrate the...

Illustrate the function of host to host transport layer in TCP/IP protocol stack? Function of Host - to-Host Transport Layer: This protocol layer just above inter network

Determine the minimal sum of products for boolean expression, Determine the...

Determine the Minimal sum of products for the Boolean expression? Obtain the minimal sum of products for the Boolean expression f=(1,2,3,7,8,9,10,11,14,15) using Quine-McCluske

Define digital computers system, Q. Define Digital computers system? Di...

Q. Define Digital computers system? Digital computers, in general, are automatic machines that accept data and instructions, perform predefined operations very quickly on the d

Defines a macro, Defines a macro Defines a macro with the given name, h...

Defines a macro Defines a macro with the given name, having as its value the given replacement text. After that (for the rest of the current source file), wherever the preproce

List the properties which a hashing function should possess, List the prope...

List the properties which a hashing function should possess to ensure a good search performance. What approaches are adopted to handle collision? A hashing function h must poss

Define http, Http Hyper Text Transfer Protocol: The WWW protocol that...

Http Hyper Text Transfer Protocol: The WWW protocol that performs the request and regain functions of a server. Generally seen as the first part of a website address. It is t

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