Search
 
SCRIPT & CODE EXAMPLE
 

C

union in c

//A union is a special data type available in C that allows 
//to store different data types in the same memory location. 
//You can define a union with many members, 
//but only one member can contain a value at any given time.
//Unions provide an efficient way of using the same memory 
//location for multiple-purpose.

union Data {
   int i;
   float f;
   char str[20];
};
 
int main( ) {

   union Data data;        

   data.i = 10;
   data.f = 220.5;
   strcpy( data.str, "C Programming");

   printf( "data.i : %d
", data.i);
   printf( "data.f : %f
", data.f);
   printf( "data.str : %s
", data.str);
   
   // Output
data.i : 1917853763
data.f : 4122360580327794860452759994368.000000
data.str : C Programming

// i and f are corupted and the latest assigned is correct
Comment

union in c

union car
{
  char name[50];
  int price;
};
Comment

C Create union variables

union car
{
  char name[50];
  int price;
};

int main()
{
  union car car1, car2, *car3;
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: use frama c online 
C :: what is O(N^2) in bubble sort method 
C :: short print variable in c 
C :: yt derived field 
C :: c sjf 
C :: string to number in c 
C :: arduino internal pull up resistor 
C :: how to check file pointers in c 
C :: program in c to print 1 to 100 without using loop 
C :: c hello word 
C :: change base int in c 
C :: block quote in lua 
C :: How to declare a string? 
C :: C static libraries (creating object files) 
C :: e sharm card jobkhozo.com 
C :: int main() { int sum =0; FILE * ptr; ptr = fopen("d:students. "," "); if (ptr ==NULL){ ("file does not exist!!"); exit(0); } 
C :: c program to take array input from user 
C :: turn on and turn off different device at the same time in rainmaker 
C :: Implement N-Queen Problem 
C :: arcpy buffer 
C :: under 
C :: using tables as arguments in c++/c 
C :: float and double Output 
C :: how to write 2d array from bin file in c 
C :: scanf autotrash c 
C :: helloworld c 
C :: Recommended compiler and linker flags for GCC 
Dart :: flutter flotingactionbutton position 
Dart :: flutter width infinity 
Dart :: flutter card border radius overflow hidden 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =