Unions: বিসদৃশ Data সংগ্রহের অন্য উপায়

Submitted by administrator on Mon, 01/02/2012 - 16:26

In the previous hour's lesson you learned how to store data of different types into structures. In this hour you'll learn another way to collect differently typed data items by using unions. You'll learn about the following topics in this lesson:

    How to declare and define unions
    How to initialize unions
    The differences between unions and structures
    Nested unions with structures
    Manipulating the bit field with struct



Summary

  •     A union is a block of memory that is used to hold data items of different types.
  •     A union is similar to a structure, except that data items saved in the union are overlaid in order to share the same memory location.
  •     The size of a union is the same as the size of the largest member in the union.
  •     The union keyword has to be used to specify the union data type in a union declaration or a union variable definition.
  •     To reference a union member, you can use either a dot operator (.) to separate the union name and the union member name or an arrow operator (->) to separate the name of a pointer that points to the union and the union member name.
  •     The ANSI C standard allows you to initialize a union by assigning the first union member a value.
  •     You can access the same memory location with different union members.
  •     To make a structure flexible, you can nest a union inside a structure so that the structure can hold different types of values.
  •     You can define the bit fields, which can be a single bit or any number of bits up to the number of bits in an integer, by using the struct data type.

 

Related Items

Another Function for Writing: putchar()

Another Function for Writing: putchar()

C প্রোগ্রামিং এর putc() Function এর ব্যবহার

Using the putc() Function
The putc() function writes a character to the specified file stream, which, in our case, is the standard output pointing to your screen.

 

C প্রোগ্রামিংয়ের getchar() Function এর ব্যবহার

Using the getchar() Function
The C language provides another function, getchar(), to perform a similar operation to getc(). More precisely, the getchar() function is equivalent to getc(stdin).

 

The syntax for the getchar() function is

 

C প্রোগ্রামিংয়ে getc() Function এর ব্যবহার

Using the getc() Function
The getc() function reads the next character from a file stream, and returns the character as an integer.

 

The syntax for the getc() function is

 

C প্রোগ্রামিং এর double Data Type সম্পর্কে আলোচনা

The double Data Type
In the C language, a floating-point number can also be represented by another data type, called the double data type. In other words, you can specify a variable by the double keyword, and assign the variable a floating-point number.