Welcome to part 6 of my C video tutorial. Today I’m going to cover Unions, Enumerated Types, the Designated Initializer, Using unions in Structs, Recursive Structures, Linked Lists and much more.
I’m also going to experiment with a new style that is more interactive and I hope it feels more like a classroom setting. Throughout the tutorial I will constantly insert brain teasers. Hopefully they aren’t distracting. I do this every once in a while to try and improve.
If you like tutorials like this it helps to tell Google+ with a click here [googleplusone]
Code From the Video
CTutorial6_1.c
CTutorial6_2.c
I got the linked List from the first time watching, the tutorial was good.
The quizz for the union -> my answer for that is: the actual bytes of information that store the entire struct are interpreted differently depending on the data type that is asumed, so if you put 16.00 for pund and you request the info interpreting it as an int (%d) then the processor will interpret it in a different way, cuzz int is expected to be 4 bytes normally and a a float is 4 and a short is 2(I think), but the struct will be stored in the highest possible data type size – 8 bytes and the float has floating points, so they all read the bits in a different way, although they are always the same 64 bits. Is that it?
Cheers,
The reason why they seem to both be stored is because data is stored as bits. The bit representation for 4 is 100 and the bit representation for 16 is 10000. So when you ask for the number of oranges, just the first 3 bits are checked and you get 100 or 4 returned. When you ask for Orange juice amount you get 10000 returned or 16.
Does that make sense?
Thanks, it does make sense, that was the point I was trying to make. I wasn’t aware of how exactly the bits are accesesd – I was guessing that it was from right to left, but apparently its a different way.
Anyway I got it now, thans!!!
I’m very happy I could help 🙂