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

PREVIOUS NEXT
Code Example
C :: c program strtok use 
C :: list c 
C :: how to pass an array of structs as an argument in c 
C :: char array to int c 
C :: mongodb update 
C :: how to represent unsigned char with % c 
C :: dynamic memory in c 
C :: array value from user c 
C :: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration] 
C :: 2 bytes integer c 
C :: ruby find object in array by attribute 
C :: how to print in c 
C :: addition of two numbers in c 
C :: C program to check whether character is lowercase or not using ASCII values 
C :: ft_putchar 
C :: keep last n bits 
C :: syntax 
C :: gcd and lcd in c 
C :: mongo script to find collection size in database 
C :: Program to Check Whether Character is Lowercase or Not without using islower function 
C :: how to merge 2 bytes into an integer 
C :: ex: C hello world 
C :: C Program to Check Whether Character is Lowercase or Not using islower function 
C :: scan c 
C :: C float and double Output 
C :: iterating through a linked list 
C :: C/AL Convertion of Decimal to String/Text 
C :: Highest integer among the four inputs in c 
C :: Tensorflow: What are the "output_node_names" for freeze_graph.py in the model_with_buckets model? 
C :: %s and string pointer 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =