Question

In: Computer Science

What are differences between structure and union by coding example in C language?

What are differences between structure and union by coding example in C language?

Solutions

Expert Solution

1)

The struct keyword is used to define a structure
The union keyword is used to define a union

2)

When a variable is associated with a structure, the compiler allocates
the memory for each member. The size of structure is greater than or equal to the sum of size of its members.

When a variable is associated with a union the compiler allocates the memoryby cinsidering the size of
the largest memory. So, size of the union is equal to the size of largest member.

3)
In structure each member within a strucure is assigned unique storeage area of location.
Where in union memory allocated is shared by individual memebers of union.

4)

In structure altering value of a member will not affect other members of the structure.
In union altering value of any of the member will alter other memebers value;

5)

In structure individual memeber van be accessed at a time
In union only on member can be accessed at time

6)

Several members of a structure can intialize at once.
Only the first member of a union can be initialized.

// declaring structure
struct person
{
int id;
float salary;
char name[20];
};

// declaraing union

union employee
{
int empId
float rate;
char name[20];
};

If you have any query regarding the answer please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

Giving an example of each, what are the differences between a Free Trade Area, Customs Union,...
Giving an example of each, what are the differences between a Free Trade Area, Customs Union, Common Market and Economic Union? Explain clearly. be as clear and specific as possible
1. What are the similarities and differences between how sign language and oral language are organised...
1. What are the similarities and differences between how sign language and oral language are organised in the brain? How has the study of aphasia assisted with understanding the relationship between these two types of language?
What are the similarities and differences between the acquisition of language in human infants and the...
What are the similarities and differences between the acquisition of language in human infants and the evolution of language in the human species? Answer this question in terms of Tomasello’s theory.
C- What are the differences between Merger, Consolidation, and Acquisitions? Support your answer with one example...
C- What are the differences between Merger, Consolidation, and Acquisitions? Support your answer with one example from the real world for each type.
execute coding examples that demonstrate the 4 scope rules file,function,class,block coding language c++
execute coding examples that demonstrate the 4 scope rules file,function,class,block coding language c++
LP7 Assignment: Union vs. Nonunion. Directions: identifying the differences between a union and a nonunion organization....
LP7 Assignment: Union vs. Nonunion. Directions: identifying the differences between a union and a nonunion organization. Include: 1. The relationship between management and employees. 2. Specific laws that impact each. 3. How compensation, benefits, and working conditions may vary. 4. Identify current legislation impacting unions and where you see them going in the future. 5. Your opinion/experience with either or both of these environments. Discuss positive employee relations strategies and non-monetary rewards.
Write a program that calculates the compound interest for an investment. (C++ coding language) If you...
Write a program that calculates the compound interest for an investment. (C++ coding language) If you deposit an amount of money P , the principal, at an interest rate r then the interest will compound over time. This means that the interest earned each period becomes part of the principal and the next time you get interest you earn interest on the interest. This is known as compounding. The equation for compound interest is ( r)n·t Pn=P0 1+n where P0...
Economics 1 What are the differences between a free trade area, customs union, common market, and...
Economics 1 What are the differences between a free trade area, customs union, common market, and economic union? Do any RTAs fit completely within one of these models of integration? 2 In what ways is the EU a unique RTA? What are some of the problems confronting the EU today?
Coding language: C++. • Each functionality component must be implemented as a separate function, though the...
Coding language: C++. • Each functionality component must be implemented as a separate function, though the function does not need to be declared and defined separately • No global variables are allowed • No separate.hor.hpp are allowed • You may not use any of the hash tables, or hashing functions provided by the STL or Boost library to implement your hash table • Appropriate, informative messages must be provided for prompts and outputs You must implement a hash table using...
Coding language: C++. • Each functionality component must be implemented as a separate function, though the...
Coding language: C++. • Each functionality component must be implemented as a separate function, though the function does not need to be declared and defined separately • No global variables are allowed • No separate.hor.hpp are allowed • You may not use any of the hash tables, or hashing functions provided by the STL or Boost library to implement your hash table • Appropriate, informative messages must be provided for prompts and outputs You must implement a hash table using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT