answersLogoWhite

0

What is class union in c language?

User Avatar

Anonymous

14y ago
Updated: 8/19/2019

A union is often confused with the structure data-type that can contain multiple data items simultaneously. A union can contain only one piece of data and that data may be of any data type.

struct foo

{

int a;

long b;

float c;

char d[80];

}my_struct;

The structure foo will have space for all the variables.

union bar

{

int a;

long b;

float c;

char d[80];

}my_union;

The union bar will have 80 bytes assigned to it, 80 being the size of the largest variable (char d[80]). At any given time only one variable can be stored in bar.

my_union.a is used to read or write an int.

my_union.b is used to read or write a long.

my_union.c is used to read or write a float.

my_union.d is used to read or write a string.

C does not have classes, C++ has class unions (a union used to define a class). A class union is the same as a union in C but gets its name from how it is used.

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

What is the topNet class that everything is derived from in c?

C language: int (but C is NOT a .net language) C# language: object or System.Object


What is FileInfo Class in C?

There are no classes in C -- it is not an object oriented language. As such there is no FileInfo class.


What is structure and union?

Structure is a query that is used in language c++


What is a class in c?

That is where students are in a classroom with an instructor learning how to program computers in the C language. Other than that the C programming language does not have classes.


What is a class c?

That is where students are in a classroom with an instructor learning how to program computers in the C language. Other than that the C Programming language does not have classes.


Where is c class made?

The C language does not support classes, per se, like the C++ language does. The closest the C language comes to a class is in the typdef struct... typdef struct _myClass { ... ... }; myClass; But you won't have any methods, inheritance, polymorphism, operator overloading, access specifiers, etc. like you do in C++.


Can you create class in 'c'?

Class acts as an encapsulation of attributes and methods, that is used by an object oriented programming (OOP) language. Since C is not an OOP, its a structural programming language, one can not create classes in C. That is why OOP version of C was developed called C++, where one can work with classes.


When you make a c program in c language then how many types class are required?

It depends on what you mean by 'types class'. Here is the shortest C program, without any 'types class': int main (void) { return 0; }


What is the difference between a class and a union in c plus plus?

The data members of a class are each allocated separate memory addresses. A union's members are all mapped to the same address. If you change the value of one union member, you change them all.


How memory space is occupied by union variables in C programming language?

A union is an aggregate of members that share the same memory address. The size of a union is determined by the largest member.


What is similarity among structure union and enum in c language?

all the three are user defined datatypes


Can methods in c sharp declared outside the class?

C# is a completely object-oriented language, everything is an object. Every datatype, is a superset of the object class. I'm sorry to say, but every method must be declared inside of a class. :(