C Programs

C Program on Understanding and performing union operations

In this program, you will learn union operations in a C Program.

Also See :C Program on structures using as complex variables


int main(void) {

	//----- EXAMPLE 1 -----
	union symbol{
		int number;
		char letter;

	union symbol value;
	value.number = 25;
	value.letter = 'm';

	union symbol *ptr; 	//pointer to union
	ptr = &value;
	char myLetter = ptr->letter;

	printf("Letter field: %c\n", myLetter);


Join The Discussion