SlideShare a Scribd company logo
1 of 19
Download to read offline
C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My mother and Father
t
                                                               y
         Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.


                                                               C
                                       Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS UNIONS, BITWISE,
BIT-FIELDS AND ENUM
                                   2
Unions
• A variable that may hold variables of different
  types and sizes.
• Only contains one data member at a time.
• Member of union share same space.
• Last data member defined can be accessed.




                        3
Unions
• Unions declaration
       union u_tag {
               int ival;
               float fval;
               char cval;
       }u;
  – Use union keyword to declare a union.
  – u_tag is the name of union.
  – ival, fval & cval are the member of the u_tag
    union.

                             4
Union…
• All operation applied on structures can be
  applied on unions.
• Access:
  – Union_name.member;
  – Union_pointer -> member;
• Unions may occur within structures and arrays,
  and vice versa.

                         5
Bitwise-operators
• All data represent as sequence of bits.
• A bit can be zero or one.
• C provides some operators to work on bits.




                        6
Bitwise-operators
• & (Bitwise AND)
  – Set 1 if both operands are 1.
    A       B     A &B                  011 3
    0       0       0               &   101 5
    0       1       0                   001 1
    1       0       0
    1       1       1




                            7
Bitwise-operators
• I (Bitwise OR)
  – Set 1 if any one operand is 1.
    A       B      A|B                   011 3
     0      0       0                |   101 5
     0      1       1                    111 7
     1      0       1
     1      1       1




                            8
Bitwise-operators
• ^ (Bitwise Exclusive-OR)
  – Set 1 if exactly one operand is 1.
    A       B      A^B                       011 3
    0       0       0                    ^   101 5
    0       1       1                        110 6
    1       0       1
    1       1       0




                             9
Bitwise-operators
• << (left-Shift)
  – Shifts the bits of the first operand left by the
    number of bits specified by the second operand; fill
    from the right with 0 bits.
        5    0   0   1   0   1
  – 5 << 1
             0   1   0   1   0        10


                                 10
Bitwise-operators
• >> (Right-Shift)
  – Shifts the bits of the first operand right by the
    number of bits specified by the second operand.
        5     0   0   1   0   1
  – 5 >> 1
              0   0   0   1   0    2



                              11
Bitwise-operators
• ~ (One’s Complement)
  – All 0 bits are set to 1 and all 1 bits are set to 0.
    A       ~A
    0        1
    1        0




                              12
Bitwise-Assignment operator
•   &= (Bitwise AND assignment operator)
•   |= (Bitwise OR assignment operator)
•   ^= (Bitwise Exclusive OR assignment operator)
•   <<= (Left-shift assignment operator)
•   >>= (Right-shift assignment operator)




                            13
Operator                                 Associativity Type
() [] . ->                               left to right   Highest
+ - ++ -- ! & * ~ sizeof (type)          right to left   Unary
* / %                                    left to right   multiplicative
+ -                                      left to right   additive
<< >>                                    left to right   shifting
< <= > >=                                left to right   relational
== !=                                    left to right   equality
&                                        left to right   bitwise AND
^                                        left to right   bitwise OR
|                                        left to right   bitwise OR
&&                                       left to right   logical AND
||                                       left to right   logical OR
?:                                       right to left   conditional
= += -= *= /= &= |= ^= <<= >>= %=        right to left   assignment
,                                        left to right   comma

                                    14
Bit-fields
• Member variable of a structure with the
  specified bits size.
        struct dob{
                 unsigned int dd : 5;
                 unsigned int mm : 4;
        };

• Better memory utilization.
• int / unsigned;

                            15
Unnamed bit-field
• Used as the padding.
        struct rent{
                 unsigned int x : 5;
                 unsigned int : 4;
                 unsigned int y : 4;
        };




                              16
Enumeration
• Integer constants represented by identifiers.
       enum days { sun, mon, tue, wed, thu, fri, sat }

• It creates a new data type (days).
• Values start at 0 and increment by 1.
• If you want to set the start value write as:-
      enum days { sun = 1, mon, tue, wed, thu, fri, sat }




                               17
Enumeration…
• To use inside program declare variable like:-
       enum days day;

• OR, use typedef
       enum days Day;
       Day day;




                         18
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

              For any problem in this tutorial mail me at
                    yogendra@learnbywatch.com
                        with the subject “C”

                     For Other information mail at
                       info@learnbywatch.com


Keep Watching Keep Learning
NEXT IS FILE I/O


                                    19

More Related Content

Similar to Unions

4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.pptRithwikRanjan
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
L3 operators
L3 operatorsL3 operators
L3 operatorsteach4uin
 
Programming techniques
Programming techniquesProgramming techniques
Programming techniquesPrabhjit Singh
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAhmad Bashar Eter
 
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2Yo Halb
 
Cse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expressionCse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expressionFarshidKhan
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++Online
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systemsMitul Tank
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++ANANT VYAS
 
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxchapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxJahnavi113937
 

Similar to Unions (20)

Programing techniques
Programing techniquesPrograming techniques
Programing techniques
 
4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt4_A1208223655_21789_2_2018_04. Operators.ppt
4_A1208223655_21789_2_2018_04. Operators.ppt
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
L3 operators
L3 operatorsL3 operators
L3 operators
 
Programming techniques
Programming techniquesProgramming techniques
Programming techniques
 
Acm aleppo cpc training sixth session
Acm aleppo cpc training sixth sessionAcm aleppo cpc training sixth session
Acm aleppo cpc training sixth session
 
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2
[YIDLUG] Programming Languages Differences, The Underlying Implementation 1 of 2
 
Cse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expressionCse lecture-4.2-c bit wise operators and expression
Cse lecture-4.2-c bit wise operators and expression
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Bitwise operators
Bitwise operatorsBitwise operators
Bitwise operators
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
Java ppt2
Java ppt2Java ppt2
Java ppt2
 
Java ppt2
Java ppt2Java ppt2
Java ppt2
 
Java ppt2
Java ppt2Java ppt2
Java ppt2
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
 
SPL 6 | Operators in C
SPL 6 | Operators in CSPL 6 | Operators in C
SPL 6 | Operators in C
 
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptxchapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
chapter-3-engdata-handling1_1585929972520 by EasePDF.pptx
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 

More from Learn By Watch

Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detectorLearn By Watch
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorLearn By Watch
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong methodLearn By Watch
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodLearn By Watch
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfmLearn By Watch
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfmLearn By Watch
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signalLearn By Watch
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexingLearn By Watch
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorLearn By Watch
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodLearn By Watch
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodLearn By Watch
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverLearn By Watch
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qamLearn By Watch
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detectorLearn By Watch
 

More from Learn By Watch (20)

Tutorial 9 fm
Tutorial 9 fmTutorial 9 fm
Tutorial 9 fm
 
Phase modulation
Phase modulationPhase modulation
Phase modulation
 
Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detector
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detector
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong method
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator method
 
Carson's rule
Carson's ruleCarson's rule
Carson's rule
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfm
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfm
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signal
 
Angle modulation
Angle modulationAngle modulation
Angle modulation
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexing
 
Vsb modulation
Vsb modulationVsb modulation
Vsb modulation
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detector
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination method
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination method
 
Ssb modulation
Ssb modulationSsb modulation
Ssb modulation
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiver
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qam
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detector
 

Recently uploaded

Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Unions

  • 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  • 2. t y Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. C Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS UNIONS, BITWISE, BIT-FIELDS AND ENUM 2
  • 3. Unions • A variable that may hold variables of different types and sizes. • Only contains one data member at a time. • Member of union share same space. • Last data member defined can be accessed. 3
  • 4. Unions • Unions declaration union u_tag { int ival; float fval; char cval; }u; – Use union keyword to declare a union. – u_tag is the name of union. – ival, fval & cval are the member of the u_tag union. 4
  • 5. Union… • All operation applied on structures can be applied on unions. • Access: – Union_name.member; – Union_pointer -> member; • Unions may occur within structures and arrays, and vice versa. 5
  • 6. Bitwise-operators • All data represent as sequence of bits. • A bit can be zero or one. • C provides some operators to work on bits. 6
  • 7. Bitwise-operators • & (Bitwise AND) – Set 1 if both operands are 1. A B A &B 011 3 0 0 0 & 101 5 0 1 0 001 1 1 0 0 1 1 1 7
  • 8. Bitwise-operators • I (Bitwise OR) – Set 1 if any one operand is 1. A B A|B 011 3 0 0 0 | 101 5 0 1 1 111 7 1 0 1 1 1 1 8
  • 9. Bitwise-operators • ^ (Bitwise Exclusive-OR) – Set 1 if exactly one operand is 1. A B A^B 011 3 0 0 0 ^ 101 5 0 1 1 110 6 1 0 1 1 1 0 9
  • 10. Bitwise-operators • << (left-Shift) – Shifts the bits of the first operand left by the number of bits specified by the second operand; fill from the right with 0 bits. 5 0 0 1 0 1 – 5 << 1 0 1 0 1 0 10 10
  • 11. Bitwise-operators • >> (Right-Shift) – Shifts the bits of the first operand right by the number of bits specified by the second operand. 5 0 0 1 0 1 – 5 >> 1 0 0 0 1 0 2 11
  • 12. Bitwise-operators • ~ (One’s Complement) – All 0 bits are set to 1 and all 1 bits are set to 0. A ~A 0 1 1 0 12
  • 13. Bitwise-Assignment operator • &= (Bitwise AND assignment operator) • |= (Bitwise OR assignment operator) • ^= (Bitwise Exclusive OR assignment operator) • <<= (Left-shift assignment operator) • >>= (Right-shift assignment operator) 13
  • 14. Operator Associativity Type () [] . -> left to right Highest + - ++ -- ! & * ~ sizeof (type) right to left Unary * / % left to right multiplicative + - left to right additive << >> left to right shifting < <= > >= left to right relational == != left to right equality & left to right bitwise AND ^ left to right bitwise OR | left to right bitwise OR && left to right logical AND || left to right logical OR ?: right to left conditional = += -= *= /= &= |= ^= <<= >>= %= right to left assignment , left to right comma 14
  • 15. Bit-fields • Member variable of a structure with the specified bits size. struct dob{ unsigned int dd : 5; unsigned int mm : 4; }; • Better memory utilization. • int / unsigned; 15
  • 16. Unnamed bit-field • Used as the padding. struct rent{ unsigned int x : 5; unsigned int : 4; unsigned int y : 4; }; 16
  • 17. Enumeration • Integer constants represented by identifiers. enum days { sun, mon, tue, wed, thu, fri, sat } • It creates a new data type (days). • Values start at 0 and increment by 1. • If you want to set the start value write as:- enum days { sun = 1, mon, tue, wed, thu, fri, sat } 17
  • 18. Enumeration… • To use inside program declare variable like:- enum days day; • OR, use typedef enum days Day; Day day; 18
  • 19. To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com Keep Watching Keep Learning NEXT IS FILE I/O 19