Linked Questions
356 questions linked to/from Why isn't sizeof for a struct equal to the sum of sizeof of each member?
67
votes
4
answers
289k
views
size of struct in C [duplicate]
Possible Duplicate:
Why isn’t sizeof for a struct equal to the sum of sizeof of each member?
Consider the following C code:
#include <stdio.h>
struct employee
{
int id;
char ...
16
votes
9
answers
13k
views
Size of structure with a char, a double, an int and a t [duplicate]
When I run only the code fragment
int *t;
std::cout << sizeof(char) << std::endl;
std::cout << sizeof(double) << std::endl;
std::cout << sizeof(int) << std::...
4
votes
9
answers
1k
views
C++ struct size: 2+4+2+2+4 = 16 [duplicate]
Possible Duplicate:
Why isn’t sizeof for a struct equal to the sum of sizeof of each member?
Why is the sizeof(); of this structure 16 bytes? I'm compiling in g++.
struct bitmapfileheader {...
6
votes
6
answers
13k
views
size of a structure containing bit fields [duplicate]
Possible Duplicate:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
I was trying to understand the concept of bit fields.
But I am not able to find why the size of the ...
2
votes
5
answers
22k
views
Sizeof operator returns incorrect size? [duplicate]
Possible Duplicate:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
Extra bytes when declaring a member of a struct as uint32_t
For some reason, the sizeof operator ...
4
votes
2
answers
3k
views
Size of struct is more than expected [duplicate]
I already read this question: struct padding in c++ and this one Why isn't sizeof for a struct equal to the sum of sizeof of each member?
and I know this isn't standardized but still I believe it'...
3
votes
2
answers
2k
views
Question regarding memory allocation of variables in a structure (In C) [duplicate]
Possible Duplicate:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
#include <stdio.h>
int main(){
struct word1{
char a;
int b;
char c;
};
struct word2{
...
4
votes
2
answers
1k
views
Is sizeof class guaranteed to contain size of elements only [duplicate]
Given example class
class test
{
public:
test();
~test();
void someMethod();
void someOtherMethod();
private:
int var;
};
is sizeof(test) == sizeof(int), or we cannot make such assumption? Is it ...
0
votes
1
answer
7k
views
Sizeof Structure in C [duplicate]
To find the size of a structure in C
struct student
{
char name;
int age;
float weight;
};
main ()
{
int i,j,k,l;
struct student s1;
i=sizeof(s1.name);
j=sizeof(...
1
vote
6
answers
3k
views
How is this possible? String always size 40 and structure sizeof odd reading [duplicate]
Okay really confused about something here. Two questions.
First question is according to my compiler, string is always a size of 40 bytes. How is this possible when we can have more than 40 ...
4
votes
1
answer
5k
views
Why is the sizeof a std::pair different to the sum of the sizeof its elements? [duplicate]
I was trying to create a pair type using dynamic memory and then return it's address to the calling function, but on checking the size of the pair object I got confused:
pair<int,vector<int> ...
-2
votes
1
answer
3k
views
Why does sizeof show 4 bytes for a char? [duplicate]
So I am currently a student and am having a programming couse.
Today we had about the use of sizeof in different classes(if it had 1 int or 2 int´s and so on)
One part of the example I found weird ...
-3
votes
3
answers
12k
views
What is the sizeof(struct)? [duplicate]
int main()
{
struct node
{
char i;
int a;
};
printf("sizeof(struct node) =%d\n",sizeof(struct node));
return 0;
}
The output for this program is 8 byte. Here sizeof(int)+size(char) ...
2
votes
5
answers
6k
views
How is memory allocated for typedef's in structs (C) [duplicate]
Possible Duplicate:
Why isn’t sizeof for a struct equal to the sum of sizeof of each member?
When you create a struct in C, for example:
typedef struct student
{
int roll_no;
char* name;
int* ...
3
votes
5
answers
383
views
Output of following code with integer, float, char variable [duplicate]
When I run following, it gives me output as 20.
but int is of 4 byte,float is of 4 byte and character array is of 10 byte, then the total is 18 byte. Why I am getting output as 20 byte?
#include<...