sizeof Questions

22

I want to know the size occupied by a JavaScript object. Take the following function: function Marks(){ this.maxMarks = 100; } function Student(){ this.firstName = "firstName"; this.lastName ...
Jemison asked 8/8, 2009 at 7:58

3

Solved

I am trying to allocate AVFrame->data[0] of a video frame to uint8_t* buffer using the following lines of code : size_t sizeOfFrameData = mpAVFrameInput->linesize[0] * mpAVFrameInput->heig...
Iorgo asked 27/3, 2015 at 9:55

4

Solved

Sizeof() doesn't work when applied to bitfields: # cat p.c #include<stdio.h> int main( int argc, char **argv ) { struct { unsigned int bitfield : 3; } s; fprintf( stdout, "size=%d\n", s...
Endurant asked 23/7, 2010 at 15:32

1

Consider int array[5]{}; std::cout << std::size(array) << std::endl; This will give me the result of 5. int array[5]{}; std::cout << sizeof(array) << std::endl; This will ...
Fielder asked 28/6, 2021 at 6:56

3

Solved

Is there a way to get the length of a fixed size buffer? Something like: public struct MyStruct { public unsafe fixed byte buffer[100]; public int foo() { return sizeof(buffer); // Compile e...
Aubree asked 9/5, 2016 at 17:7

14

Solved

Let's say I have an array arr. When would the following not give the number of elements of the array: sizeof(arr) / sizeof(arr[0])? I can thing of only one case: the array contains elements that a...
Weatherboarding asked 29/1, 2011 at 21:42

5

I wrote a bash script to determine the size of gcc's datatypes (e.g. ./sizeof int double outputs the respective sizes of int and double) by wrapping each of its arguments in the following P() macro...
Sears asked 4/2, 2015 at 22:31

10

Solved

I have tried implementing the sizeof operator. I have done in this way: #define my_sizeof(x) ((&x + 1) - &x) But it always ended up in giving the result as '1' for either of the data type....
Modie asked 5/1, 2013 at 11:1

4

Solved

The program #include <stdio.h> int main(void) { printf("sizeof( char ) = %zu, sizeof 'a' = %zu.\n", sizeof( char ), sizeof 'a' ); return 0; } outputs the following: sizeof(...
Valine asked 2/11, 2021 at 13:0

5

Solved

For example result of this code snippet depends on which machine: the compiler machine or the machine executable file works? sizeof(short int)
Pollypollyanna asked 10/4, 2010 at 22:15

1

Solved

If sizeof(int) == sizeof(long), then is INT_MIN == LONG_MIN && INT_MAX == LONG_MAX always true? Is there any real existing cases demonstrating "not true"? UPD. The similar questio...
Dissertate asked 19/10, 2021 at 13:12

8

Solved

When looking for a size of an array in a for loop I've seen people write int arr[10]; for(int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++){} How is sizeof(arr) / sizeof(arr[0]) the length of...
Hoarsen asked 4/11, 2015 at 13:50

10

Solved

Here is the code compiled in Dev-C++ on Windows: #include <stdio.h> int main() { int x = 5; printf("%d and ", sizeof(x++)); // note 1 printf("%d\n", x); // note 2 ret...
Bevel asked 22/11, 2011 at 11:7

16

I have an int array and I need to find the number of elements in it. I know it has something to do with sizeof but I'm not sure how to use it exactly.
Wilt asked 24/4, 2012 at 1:30

8

What's the difference between sizeof and alignof? #include <iostream> #define SIZEOF_ALIGNOF(T) std::cout<< sizeof(T) << '/' << alignof(T) << std::endl int main(int...
Andrea asked 8/7, 2012 at 21:40

4

Solved

In C, I have an array of structs defined like: struct D { char *a; char *b; char *c; }; static struct D a[] = { { "1a", "1b", "1c" }, { "2a", "2b", "2c" } }; I would like to determ...
Tobe asked 14/12, 2009 at 2:30

4

Solved

Following the question: How come an array's address is equal to its value in C? #include <stdio.h> #define N 10 char str2[N]={"Hello"}; int main(){ printf("sizeof(str2): %d bytes\n", s...
Salmonoid asked 2/3, 2013 at 17:36

0

The following program template<int> struct R{}; struct S { template<typename T> auto f(T t) -> R<sizeof(t)>; }; template<typename T> auto S::f(T t) -> R<sizeof...
Alteration asked 10/4, 2021 at 21:38

7

Solved

I have two tasks for an assignment, one return the number of bits in type int on any machine. I thought I would write my function like so: int CountIntBitsF() { int x = sizeof(int) / 8; return x...
Caitiff asked 19/1, 2010 at 2:56

2

Solved

I have the next two code examples: const char *val = strchr(ch, ' '); const int diff = (int)(val - ch); char arr[diff]; and const char *val = strchr(ch, ' '); const int diff = (int)(val - ch); c...
Sylvanus asked 10/3, 2021 at 14:8

5

Solved

Using the sizeof operator, I can determine the size of any type – but how can I dynamically determine the size of a polymorphic class at runtime? For example, I have a pointer to an Animal, and I...
Engender asked 11/9, 2009 at 15:59

7

Why do we say sizeof(variable) is an operator, not a function? It looks like a function call and when I am thinking about the meaning of operator, it appears to me something like + or - or * and so...
Cruz asked 22/1, 2021 at 15:41

4

Solved

Suppose I have two classes that I would expect to have exact same memory layout: struct A { int x; int y; }; /* possibly more code */ struct B { int a; int b; }; Is there anything in the s...
Kaolin asked 8/3, 2019 at 18:0

6

Solved

i have a doubt regarding sizeof operator Code 1: int main() { int p[10]; printf("%d",sizeof(p)); //output -- 40 return 0; } Code 2: int main() { int *p[10]; printf("%d",sizeof(*p)); //out...
Izaguirre asked 20/12, 2011 at 7:39

4

Solved

On my machine, the relevant sizes are: sizeof(char) == 1, sizeof(int) == 4 and sizeof(char*) == 8. #include <stdio.h> #include <stdlib.h> typedef struct person{ char *name; int age;...
Johanna asked 1/12, 2020 at 13:52

© 2022 - 2024 — McMap. All rights reserved.