Tuesday, 5 June 2018

STRUCTURE - 2

Now we discuss some key features of structure :- 

Structure Pointer :

                Pointer size is dependent upon OS ,same applies for structure pointer. we will assume a 32-bit system.

Exp :

struct st
         {
          int a;
          char b;
          };
main()
{
struct st a1 ={10, p} , *ST;
ST = &a1;

for access :-

printf("%d %c",ST->a , ST->b );

Ways to Pass a structure in function :

1) print1(a1.a, a1.b);
2) print2(ST);
3) print3(&a1);

Structure Bit Field :

  •  Bit field is a mechanism in C-Language where we can allocate a memory in the form of  Bits.
  • Bit field can only be used in Structure and Union.
struct A
         {
         int a:6;
         chat ch:3;
         };

Here int take b bit and char take only 3;

Limitation of bit Field :
  • We cannot allocate more bit size, then the actual size.
  • bit field are applicable only for char and int.
  • Getting address of bit field variable is possible.