
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Anonymous Union and Structure in C
Here we will see what is the anonymous union and structures in C. The anonymous unions and structures are unnamed unions and structures. As they have no names, so we cannot create direct objects of it. We use it as nested structures or unions.
These are the examples of anonymous union and structures.
struct { datatype variable; ... }; union { datatype variable; ... };
In this example we are making one structure, called point, it is holding an anonymous structure. This is holding two values x, y. We can access the anonymous structure or union members directly.
Example
#include<stdio.h> struct point { // Anonymous structure struct { int x; int y; }; }; main() { struct point pt; pt.x = 10; pt.y = 20; printf("Point (%d,%d)", pt.x, pt.y); //anonymus members can be accessed directly }
Output
Point (10,20)
- Related Articles
- Difference between Structure and Union in C
- Difference between Structure and Union in C Program
- Anonymous Structure and Field in Golang
- Difference Between Structure and Union
- What is union of structure in C language?
- State the difference between structure and union with suitable example in C language
- Union in C
- Anonymous Methods in C#
- Anonymous classes in C++
- Union Method in C#
- C# Anonymous Methods
- Difference between UNION and UNION ALL in DB2
- What are anonymous methods in C#?
- Union of two HashSet in C#
- C# Queryable Union Method

Advertisements