I would like to count how many bytes a char pointer takes in memory.
The pointer points to a string with 100 chars.
According to the following program a char needs 4 bytes
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char b;
b = 'b';
printf("%p\n",&b);
system("pause");
return 0;
}
Is it the same for pointers?
So it’s 400 bytes saved in memory for a string of 100 chars?
charneeds one byte. Pointer to anything usually needs 4 or 8 bytes depending on the architecture. Of course an object and a pointer to it are separate things and they use separate memory, so if a 100-char string uses 100 or 101 byte (depends on how do you count and how do you store the string), a pointer to it will still use 4 bytes.