UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How can I learn which element in a union is currently active?

Asked by Last Modified  

Follow 0
Answer

Please enter your answer

Home Tutor

Actually, that question is really contrary to why I used unions in the first place — the idea was to be able to access one type of data AS IF it was another type. So, for instance, to dissect a floating point value into bytes, or to take a bunch of bytes and interpret as a long or a string, or … So,...
read more
Actually, that question is really contrary to why I used unions in the first place — the idea was to be able to access one type of data AS IF it was another type. So, for instance, to dissect a floating point value into bytes, or to take a bunch of bytes and interpret as a long or a string, or … So, in this use case, there is no *active* element — each element is just another way of interpreting the same chunk of memory. But, if you are using the union as a “catch all” type of structure, to be able to store any kind of value, but you need to know what type is stored there, then by all means add a “type” element to an enclosing struct, as suggested by others. read less
Comments

Related Questions

Which is older - Java or C?
C is older than JAVA
Baby
Which are the best books to learn C?
Yashavant Kanetkar
Kratika
What are the applications of C programming?
Hi Poulami Hope you are doing good. C programming language is a versatile and widely used language that has found applications in various domains. Some of the key applications of C programming include: 1....
Poulomi
0 0
6
Why are there so many programming languages if most programmers use C, C++, Java, and PHP?
This question has the same answer as the question"Why there are so many languages?" has... As they were ask meant for different purpose to serve for different platforms... For short: Link it to the languages used
Veerendra
0 0
7
what is syntex error
A syntax error is an error which found in the source code of a program or sometimes it can be small grammatical mistakes in spelling or limited to a single character. Programming languages follow their...
Tanha

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons


4 Things Every Tech Startup Needs to Know About The Coaching Industry
Knowledge on any subject is widely available to those who wish to learn. However, just gathering knowledge from other people doesn’t guarantee results in business. Results come from applying what...

Recursion in C Programming
The process of calling a function by itself is called recursion and the function which calls itself is called recursive function. Syntax of Recursive Function returntype recursive_func () { statements; ...
R

Ravindra Yadav

2 0
0

Set 0 To Kth Bit In A Variable
The following code snippet Set 0 to Kth Bit in an variable #include int UnsetBitValue(int n, int k);int main(){ printf("%d\n\n",UnsetBitValue(255,6)); return 0;}// Set kth bit to zeroint UnsetBitValue(int...

C Program Sample Application
//Standard Library Functions(Header Files used) #include<stdio.h> #include <conio.h> //Main method int main() { // function for clearing screen clrscr(); // function to print the output...

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more