GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Tech FAQs  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 246 of 255    Print  
How to find the size of a class
Size of a class
which is
class C
{
int i;
char c;
}
int size is 4 and char is 1 but the size of class is coming 8, give the explanation for that?



  
Total Answers and Comments: 1 Last Update: November 29, 2007     Asked by: sundarkms 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 29, 2007 05:55:37   #1  
kamal7725 Member Since: November 2007   Contribution: 15    

RE: How to find the size of a class
This is because, your machine is 32 bit( 4 byte). your structure has two variable, a int and a char. int is 4byte long, so no problem. but char is 1 byte long, and will occupy the other 3 byte for alignment. So the sizeof operator gives the total size 8 byte.
 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : #include #include /* Prototype Declaration */int validateDate(int dd, int mm, int yyyy);void printError();int calcDay_Dec31(int yyyy);int dayInYear(int dd, int mm);void nameInStr (char daysInWord[], int days);void main(void){    ...

Latest Answer : In linux there is a memory debugging tool valgrind.With the help of valgrind, you can easily check the memory allocation or memory deallocation. ...

Latest Answer : To reduce the final size of executable, remove any dead code, if there in the program (remove extra white spaces, extra commnets, extra tabs) and also use functions where ever possible, because it reduces the code and executable file size alot. ...

Latest Answer : Class is not a Object simillarly Object cannot be a class. the relationship between this two is that the Object is an instance of the Class.If Car is a class then running car is the Object [it might comprise of other Objects also]. Simillarly if Heart ...

Tags : Abstract

Latest Answer : #includeusing namespace std;/* factorial function  --recursive*/int fact(int n){ if (n == 0)  return 1; n=n*fact(n-1); return n;}int main() { int n=5; cout

Latest Answer : ptr=realloc(ptr,newsize);This function allocates a new memory space of size  newsize to the pointer variable ptr  and returns a pointer to the first byte of the new memory block.The new size may be smaller or larger than the size.If the function ...

Latest Answer : Create a new array and copy the old one in it. ...

Latest Answer : class is the collection of same type of objects .whereas object is an instance of a class.ex :humanbeing is a class whose objects can be man ,woman etc. ...

Latest Answer : 1)class is the advanced and the secured form of structure.2)Both are the abstract and user defined data types.3)By default the the behavior of the class contents is private and the structure is public.4)In C++ the structure is the class with public behavior.5)In ...


 Sponsored Links

 
Related Articles

OOPS Tutorials

Object oriented programming OOP is a computer science term used to characterize a programming language that began development in the 1960’ s The term object oriented programming’ was originally coined by Xerox PARC to designate a computer application that describes the methodol
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

How to Access C++ Class Members

How to Access C Class Members In this C tutorial you will learn how to access Class members dot operator or class member access operator difference between struct and class and  scope resolution operator mosgoogle center It is possible to access the class members after a class is defined an
 

UML Elements : Class Diagram

UML Elements UML 2 0 is comprised of a total of 13 diagrams If you wish to understand these diagrams they should be organized based on a hierarchy For UML a diagram is an element which must define which things should be modeled in a system mosgoogle center Introduction to Class Diagram In this arti
 

Class-based Object Oriented Programming

Class based Object Oriented Programming Class based object oriented programming is a style that gains inheritance by processing classes as objects The most prominent style of OOP is class based instead of object based With the class based OOP system objects are units that merge states identities and
 

The Inheritance Concept In OOPs

The Inheritance Concept In OOPs In object oriented programming objects will be characterised by classes It is possible to learn a lot about an object based on the class it belongs to Even if you are not familiar with the name Maybach If I told you it is a car you would immediately know that it has f
 

Understanding The Message Concept In OOPs

Understanding The Message Concept In OOPs To understand object oriented programming you will need to become familiar with messages As the name implies a message is a process in which software objects will communicate with one another Because of this having one object is not enough mosgoogle An objec
 

Class Constructors and destructors in C++

Class Constructors and destructors in C In this C tutorial you will learn about Class Constructors and destructors in C viz Constructors What is the use of Constructor General Syntax of Constructor Destructors What is the use of Destructors and General Syntax of Destructors mosgoogle Constructors Wh
 

Basic concepts of OOPS and Structure of C++ program

Basic concepts of OOPS and Structure of C program In this tutorial you will learn about Objects Classes Inheritance Data Abstraction Data Encapsulation Polymorphism Overloading Reusability Before starting to learn C it is essential that one must have a basic knowledge of the concepts of Object orie
 

A Java TOC2 Class Which Can Contact Aim

How To Produce a Java TOC2 Class Which Can Contact Aim AOL Instant Messenger is one of the most popular instant messenging tools available today It allows you to send instant messages to other people who use AIM At the same time it is possible to heavily customize AIM programs by using a protocol wh
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape