Linked Questions
29 questions linked to/from What is the size of a pointer?
58 votes
10 answers
11k views
Do all pointers have the same size in C++?
Recently, I came across the following statement: It's quite common for all pointers to have the same size, but it's technically possible for pointer types to have different sizes. But then I came ...
0 votes
0 answers
1k views
How to use register value as an array-element offset in x86 Assembly? [duplicate]
So I have this array: fib BYTE 9, 123, 92, 0, 0, 0, 0 And I'm wanting to be able to access the different elements of the array and move them, individually, into a register. I've noticed so far ...
0 votes
1 answer
478 views
Why is the size of (void *) 8 bytes? [duplicate]
#include <stdio.h> int main() { printf("%ld", sizeof(void *)); return 0; } The output for the program was 8, but I am unable to figure out how.
-3 votes
1 answer
326 views
What is the size of pointers in c++? [duplicate]
What is the size of pointers in c++? char a; char *b=a; cout<<sizeof(b); Output is 2 I don't know why. cout<<sizeof(const); //o/p is 2 cout<<sizeof(NULL); //o/p is 2
0 votes
1 answer
105 views
Why dynamically allocated memory return different size that i actually tried to allocate? [duplicate]
I want to add a string after the struct in memory. How to check that i dynamically allocated right amount of bytes? Example: const wchar_t* add_str = L"test string"; struct test_{ ...
16 votes
3 answers
722 views
A compile time way to determine the least expensive argument type
I have a template that looks like this template <typename T> class Foo { public: Foo(const T& t) : _t(t) {} private: const T _t; }; Is there a savvy template metaprogramming way to ...
7 votes
4 answers
3k views
How do pointers reference multi-byte variables?
I am confused as to how C pointers actually reference the memory address of a variable. I am probably missing something here, but if, for example an int is 32 bits (like in C), then this would be ...
0 votes
7 answers
390 views
Confusion regarding pointer size
This may be a noob question ..but this is really confusing me.. Below is some sample code void main() { int a = 300; char *ptr = &a; int *intptr = &a; printf("%d\n %d\n", *...
5 votes
2 answers
1k views
Double pointer conversions, passing into function with `const void **ptr` parameter
GCC gives me folowing warning: note: expected 'const void **' but argument is of type 'const struct auth ** Is there any case, where it could cause problems? Bigger snippet is struct auth *current; ...
1 vote
2 answers
2k views
Why doesn't my program work with float variables, but it does with int variables?
I am trying to program a method that determines if a given number is an armstrong number. An armstrong number can be found by the steps below: Take base digits ie 456 => 4, 5, 6 Power to the number of ...
1 vote
4 answers
394 views
C++ heap / stack clarification
I need some clarification on C++ memory allocation, I'll just get right to an example Let's say I have made a class A, which contains two containers: a hash_map and a std::vector like this: class ...
5 votes
1 answer
954 views
What is *(int*)&data[18] actually doing in this code?
I came across this syntax for reading a BMP file in C++ #include <fstream> int main() { std::ifstream in('filename.bmp', std::ifstream::binary); in.seekg(0, in.end); size = in....
0 votes
4 answers
3k views
What is the size of a char*?
What is the size of a char*, or how would I be able to get the size of it? Would it simply be sizeof(char) or sizeof(char[]) I am asking this because I am trying to make a data structure (a queue) ...
5 votes
2 answers
756 views
Code reuse (or not) in C++ templates
In all books I've read until now, they said that C++ templates generate one instance of code for each type we use. On the other and, the books said that in C# the code is reused. So I made a ...
2 votes
2 answers
315 views
Can int and long be the same type?
Of course int and long are not guaranteed to be the same type, but on a platform such as Windows when compiling in 32-bit mode where they happen to be the same size, is the compiler allowed to regard ...