How do you know to what a pointer is pointing to ?
umm..you mean the value?
for value, dereference it. *variable gives the value.
i mean the variable name to which it is pointing ?? is it possible ?
I have a struct, it contains two data members and a pointer to char.
I created two objects of the struct and initialized all the members of the first one,
then I initialized the second one with the first
like b = a;
now whatever I change in the pointer of a, also gets changed in b. So they both are pointing to the same thing, is there anyway I can get the address of to what they are pointing ?
of course the pointers in the structs point to the same thing. That is because you do a shallow copy. If you want the two char pointers inside the structs point to diffrent strings you need to do a deep copy ( copy the content pointed by the pointer in a and make the pointer in b point to the new content ).
>>now whatever I change in the pointer of a, also gets changed in b. So they both are pointing to the same thing, is there anyway I can get the address of to what they are pointing ?
From what i have understood, i would like to say the following :
A pointer actually stores an address of the variable it points to. So you may just retrieve the address of the variable (a character variable in your case) from the pointer value.
Say the pointer is char* ptr. Then ptr gives the address of to what it points to.
If i have misunderstood your question, however, you may poke me. :)
>i mean the variable name to which it is pointing ?? is it possible ?
It's possible, but not without some extra manual framework. But my question to you is, what if the pointer isn't pointing to the address of a variable? For example:
char *p = new char;
There's no variable involved here, the address refers to anonymous dynamically allocated memory.
>is there anyway I can get the address of to what they are pointing ?
The value of a pointer is the address that it points to.
You can compare the pointer with the location in the memory of the structures (using &)
if pointer == &struct ==> the pointer points to that struct.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...