Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a union to store either an integer or a float and display the value based on the type chosen.

Hard

Problem Statement

Implement a union to store either an integer or a float and display the value based on the type chosen.

Sample Input

choice = 'i', value = 10

Sample Output

Integer Value: 10

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
#include <stdio.h> union Data { int intValue; float floatValue; }; int main() { union Data data; char choice; // Add logic to read choice and assign value // Logic to display based on choice return 0; }
Log in or sign up to run or submit your code.Log inSign up
Input
choice = 'i', value = 10
Expected Output
Integer Value: 10