Well, I am new to C. I would like to know as my title says.
Suppose I declare pointers as following,
char *chptr1;
char **chptr2;
int *i;
int **ii;
struct somestruct *structvar1;
struct somestruct **structvar2;
Then,
char
pointer,
strdup()
which allocate memory itself, we have not to care much about it.A pointer is a variable that contains an address in memory. In a 64 bit architectures, the size of a pointer is 8 bytes independent on the type of the pointer.
Yes, a declared pointer has its own location in memory. In the example above, you have a variable, 'b', which stores the value "17".
Dynamic memory allocation is to allocate memory at “run time”. Dynamically allocated memory must be referred to by pointers. the computer memory which can be accessed by the identifier (the name of the variable).
Using pointers to allocate spacemalloc(n) allocates n bytes of memory and returns the address of that memory, or NULL if the allocation failed. Allocated memory must have an address which can be reached from the value of a variable, otherwise we cannot access it and it gets "lost".
Pointers point at things. It's up to you what you make them point at.
You can leave them uninitialized and don't use them: int * q;
That's a little silly.
You can make them point to something that exists: int x; int * q = &x;
You can store the address of dynamically allocated memory in them: int * q = malloc(29);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With