473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why the size of empty class is 1 byte?

Why is the size of this empty class 1 byte?
Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.  
  4. };
  5.  
  6. sizeof(A);
  7. ans:- 1 byte
Sep 16 '14 #1
1 1629
weaknessforcats
9,208 Expert Mod 8TB
Think about it.

Expand|Select|Wrap|Line Numbers
  1. class A
  2. {
  3.  
  4. };
  5.  
  6. A obj;
  7.  
  8. A* ptr = &obj;
You can always create an object from a class. That means you can take the address of the object. For that to work you need an actual object in memory. A 1 byte memory allocation is the minimum required to acquire an address.
Sep 16 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Sweety | last post by:
hello, why sizeof an empty class why 1 byte ? plz illustrate this ? bye
6
by: free2cric | last post by:
Hi, What will the syntax sound like for checking size of an empty class? what will be the size. Thanks, Cric
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
4
by: avranju | last post by:
Hi, We have a few exception marker classes in a project that are used only to throw exceptions. I mean stuff like this (this may not be such a hot idea for doing exception handling - a simple...
8
by: meendar | last post by:
what will a object of an Empty class( contain nothing), do on default.What are all the default methods it calls. what is the use of creating the object for an empty class?
7
by: dost | last post by:
can any budy tell me why the size of the empty class object is 1 thank you kapil kaushik
2
by: Harish | last post by:
This was an interview question: The size of an empty class is 1 byte. Why? Should it not be 4 bytes? Because an invisible pointer "this" is part of every class?
1
by: Ajay | last post by:
Hello All, I have one question in mind...when you derive an empty class and see its size it comes 1 byte,can somebody tell me why.....Thanks in advance. Ajay
7
by: Ajay | last post by:
Hi all, Please tell me why empty class has one Byte Size. thanks in Advance.. Ajay
9
by: Morgan Cheng | last post by:
Hi, I once worked for java in embedded system. Since the memory is limited in embedded system, there are some guidelines for programming. One of them is "Don't create too many classes, because...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.