Explain union. What are its advantages?



Explain union. What are its advantages?..

Answer / Suhail Ahmad

A 'union' is a data structure that allows multiple variables to occupy the same memory location. Each variable can be of different data types. When one member is accessed, the other members lose their values. Union has several advantages: (1) It conserves memory by using the same storage space for multiple variables. (2) It allows efficient use of resources when dealing with data structures that require different representations at different times.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is the use of #define preprocessor in c?

1 Answers  


What is pragma c?

1 Answers  


write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);

1 Answers   TCS,


how to estimate the disk access time? e.g. the time between read one byte and another byte in the disk.

3 Answers   Google,


write a program to display all prime numbers

1 Answers  


Determine the code below, tell me exactly how many times is the operation sum++ performed ? for ( i = 0; i < 100; i++ ) for ( j = 100; j > 100 - i; j--) sum++;

5 Answers   ITCO, Wipro,


What are different types of pointers?

1 Answers  


Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test. Make necessary assumptions.

1 Answers  


Write a program to generate the Fibinocci Series

1 Answers   TISL,


IS it possible to define a zero sized array in c.if it is possible how can the elements of that array can be accessed.array index starts from zero,if it is possible to define zero sized array how can be its first element can be accesseed.

5 Answers   TCS,


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

1 Answers   HCL,


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1 Answers   Infosys,


Categories