sizeof Questions

2

Solved

In particular I'd like to know what ->val does in the sizeof(((stoken_t*)(0))->val) and what stoken_t*(0) pointer do, in particular what the (0) means? I hope I have formulated my question c...
Dantedanton asked 7/9, 2020 at 8:39

4

Solved

I am trying to use the following code to append a right parenthesis to the end of a string took from the user int main( void ) { char charArray[ 20 ]; fgets( charArray, 20, stdin ); charArray[...
Buckling asked 31/8, 2020 at 10:12

8

Solved

Is the size of a pointer the same as the size as the type it's pointing to, or do pointers always have a fixed size? For example... int x = 10; int * xPtr = &x; char y = 'a'; char * yPtr ...
Grandioso asked 19/7, 2011 at 17:57

2

Solved

In a recent post, I realised that when allocating a structure variable, passing the dereferenced pointer deemed a better practice in contrast to passing the structure type to sizeof(). This is basi...
Liberia asked 21/7, 2020 at 12:54

4

Solved

I don't know why the sizeof operator is not evaluated in a for loop condition at run time. I am trying this simple code with different C compilers but it always print nothing. But if I replace size...
Omnipotence asked 13/6, 2020 at 6:16

5

Solved

This is an online C++ test question, which has been done. #include<iostream> using namespace std; class A { }; class B { int i; }; class C { void foo(); }; class D { virtual void foo()...
Swineherd asked 24/2, 2012 at 22:59

5

Solved

If I use malloc in my code: int *x = malloc(sizeof(int)); I get this warning from gcc: new.c:7: warning: implicit declaration of function ‘malloc’ new.c:7: warning: incompatible implicit decla...
Popp asked 4/8, 2009 at 23:15

1

Solved

This program: struct alignas(4) foo {}; int main() { return sizeof(foo); } returns 4, with GCC 10.1 and clang 10.1, and icc 19.0.1 . That makes me wonder - is it mandatory for alignas() to affe...
Zink asked 17/5, 2020 at 18:29

2

Solved

Look at the following code: #include <stdio.h> int main(void) { int i = 1; printf("%lu\n", sizeof(int[++i])); printf("%d", i); } I was testing the sizeof operator because variable-len...
Ananthous asked 5/5, 2020 at 17:32

4

Solved

What is the main function of sizeof (I am new to C++). For instance int k=7; char t='Z'; What do sizeof (k) or sizeof (int) and sizeof (char) mean?
Ful asked 8/7, 2010 at 11:46

5

Solved

Context We are porting C code that was originally compiled using an 8-bit C compiler for the PIC microcontroller. A common idiom that was used in order to prevent unsigned global variables (for ex...
Ancylostomiasis asked 15/4, 2020 at 15:5

6

#include <iostream> using namespace std; int main() { int a; long b; cout<<sizeof(a+b); return 0; } The output is 8 (size of a long variable). Why doesn't it return their sum?...
Appurtenance asked 1/4, 2020 at 10:14

9

Solved

Once again, I'm questioning a longstanding belief. Until today, I believed that the alignment of the following struct would normally be 4 and the size would normally be 5... struct example { int...
Dovecote asked 9/1, 2011 at 5:2

1

Solved

There is std::array<T, N>::size(), but it's non-static, so it requires an instance of std::array. Is there a way to get the value it returns (which is the N of std::array<T, N>) without...
Gonta asked 13/3, 2020 at 18:31

6

Solved

Assuming you're using a compiler that supports C99 (or even just stdint.h), is there any reason not to use fixed-width integer types such as uint8_t? One reason that I'm aware of is that it makes ...
Duisburg asked 16/11, 2012 at 9:13

6

Solved

I have a piece of C code and I don't understand how the sizeof(...) function works: #include <stdio.h> int main(){ const char firstname[] = "bobby"; const char* lastname = "eraserhead"; ...
Shotgun asked 23/6, 2013 at 11:21

2

Solved

Can sizeof(size_t) be less than sizeof(int)? Do the C and/or C++ standards guarantee that using unsigned int for array indexing is always safe?
Bananas asked 21/1, 2020 at 1:42

7

Solved

I want store a list of doubles and ints to a ByteBuffer, which asks for a size to allocate. I'd like to write something like C's syntax int size=numDouble*sizeof(double)+numInt*sizeof(int); But ...
Hyalite asked 20/7, 2011 at 18:3

4

Solved

I have a quick question about class structuring, padding, and the resulting sizeof the class. In the below example, on every compiler I've tested, the result is always 40 bytes for sizeof A, which ...
Belly asked 13/12, 2019 at 15:40

3

Solved

#include <stdio.h> int main() { char a = 'A'; int b = 90000; float c = 6.5; printf("%d ",sizeof(6.5)); printf("%d ",sizeof(90000)); printf("%d ",sizeof('A')); printf("%d ",sizeof(c)); ...
Lakes asked 10/12, 2019 at 18:49

2

Solved

I know in C++ you can get a arrays amount of rows and columns with: int rows = sizeof array / sizeof array[0]; int cols = sizeof array[0] / sizeof array[0][0]; However is there any better way ...
Selenaselenate asked 10/2, 2013 at 8:3

10

Solved

Why is sizeof considered an operator and not a function? What property is necessary to qualify as an operator?
Blench asked 8/9, 2009 at 11:56

1

Solved

Is this undefined behavior? The relevant parts of the standard don't say much. size_t n = SIZE_MAX / sizeof(double) + 1; size_t m = sizeof(double[n]);
Intoxicated asked 3/9, 2019 at 3:23

3

Solved

I searched thoroughly but could not find the solution to this: Assuming sizeof(int) = 4, we define: int a[10] = {0}; What is the output of the following: 1. sizeof(&a) 2. sizeof(*a) 3. sizeo...
Dulciedulcify asked 8/8, 2019 at 7:17

8

Why is int typically 32 bit on 64 bit compilers? When I was starting programming, I've been taught int is typically the same width as the underlying architecture. And I agree that this also makes s...
Deane asked 5/7, 2013 at 13:17

© 2022 - 2024 — McMap. All rights reserved.