×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

Size of structure with no members in C++ programming language

Learn: can we declare a structure with no members, if yes what will be the size of that structure? In this article we are going to learn about size of structure with no members (or Empty Structure) in C++ language with an example.

Size of structure with no members in C++

Yes, it is allowed in C++ programming language that we can declare a structure without any member and in that case the size of the structure with no members will be 1. It will be a One Bye structure.

Example of size of structure with no members

Consider the program:

In this C program, we are declaring a structure named "temp" without declare any variable in it, so "temp" is a structure with no members.

Then, we are declaring its variable "T" (Structure variable) and printing occupied size by "T" using sizeof() operator, and the result is "1".

#include <iostream>

using namespace std;

//structure with no members
struct temp
{
    
};

int main()
{
    //declaring stcurure variable
    struct temp T;
    cout<<"size of T: "<<sizeof(T)<<endl;
    return 0;
}

Output

Size of T: 1

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.