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

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 

Recently uploaded (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 

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