|
I'm relatively new to C/C++ and had small question on pointers. Its like this:
int* p;<br />
int q;<br />
q = 15;<br />
p = &q;<br />
*p = 22;
With the above, i would have the value of 22 in the memory location inside p. Right? i guess so. I had to put an asterix before the p to set the value to 22.
Now see this,
struct node<br />
{<br />
int data;<br />
struct node* next;<br />
};<br />
<br />
struct node* newNode = malloc(sizeof(struct node));<br />
newNode->data = 15;
Now why is it that i dont have to put an asterix before newNode when i set the value of data to 15 (in the last line).
|
|
|
|
|
Mridang Agarwal wrote: Now why is it that i dont have to put an asterix before newNode when i set the value of data to 15 (in the last line).
Because you access a member variable of newNode with the arrow ( -> ). This member variable is not a pointer but an integer, so you have to treat it like a normal integer.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Because the -> operator works on pointer variables.
Writing
newNode->data = 15;
is equivalent to (and a shorthand of)
(*newNode).data = 15;
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Mridang Agarwal wrote: struct node* newNode = malloc(sizeof(struct node));
First of all the malloc requires typecasting to get correct pointer,
because malloc return void pointer.
The correct way is
struct node* newNode = (struct node*)malloc(sizeof(struct node));
Mridang Agarwal wrote: why is it that i dont have to put an asterix before newNode
As it is pointer.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
got it! thanks everyone. You guys really helped clear my head out.
|
|
|
|
|
Hi !!!
struct node
{
int data;
struct node* next;
};
struct node* newNode = malloc(sizeof(struct node));
newNode->data = 15;
Here you don't have to put the asterisk, because you have created an instance of the struct node and the integer variable data is not a pointer, so you don't have to and you are not allowed to put the asterisk before.
By.
-:KNOX:-
|
|
|
|
|
Hi,
I want to access some global variables from a DLL from another application in VC6. Is it possible ? I have tried but not successful.
Cyber Friend
|
|
|
|
|
Cyber Friend wrote: I want to access some global variables from a DLL from another application in VC6. Is it possible ? I have tried but not successful.
declare the variable in .h of DLL as
extern _cdecl __declspec(dllexport) int humm;
define the variable in .cpp file of DLL as
extern _cdecl __declspec(dllexport) int humm=0;
_cdecl ensures that the variable/function declared as C Style avoids mangling by C++ compiler.
Knock out 't' from can't,
You can if you think you can
-- modified at 10:03 Friday 19th May, 2006
|
|
|
|
|
|
Hi Steen,
I dont want to share data between two processes using dll. All I want to do is that, in dll I want to put some global variables and in other application I want to access these global variables. Is it possible as replied by the other guy.
Regards
CyberFriend
|
|
|
|
|
|
What do you mean by "other application"? If it's another program, then you want to share data between processes. If it's another module within your program you can do as A_Laxman wrote.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
A_Laxman wrote: define the variable in .cpp file of DLL as
extern _cdecl __declspec(dllexport) int humm=0;
Why extern in definition...?
Nibu thomas
Software Developer
Faqs by Michael dunn
|
|
|
|
|
maybe it is some helpful to you
Here[^]
whitesky
|
|
|
|
|
Have you tried exporting functions to Set and Get the variable ?
|
|
|
|
|
Hi,
I want to display information stored in my database, that is only available for a user. I can use GetCurrentUser() to get the name of the currently logged in user, but I want to read other users to read their data without completey logging off and on again.
I have a dialogbox to ask the user for a username and the corresponding password.
Now I want to check, if this is the correct password for the user, asking my domain controller in my ADS.
Any hints?
Juergen
|
|
|
|
|
e-DJ wrote:
I have a dialogbox to ask the user for a username and the corresponding password.
Now I want to check, if this is the correct password for the user, asking my domain controller in my ADS.
see the LogonUser security API
The LogonUser function attempts to log a user on to the local computer, that is, to the computer from which LogonUser was called.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
e-DJ wrote: Now I want to check, if this is the correct password for the user, asking my domain controller in my ADS.
Can you use LogonUser() for this?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Nice to see you here:
Check for LogonUser()
Regards.
|
|
|
|
|
Great
exactly, what I was looking for.
Thanks everybody for this great support
Juergen
|
|
|
|
|
maybe it is some helpful to you Here [^]
whitesky
|
|
|
|
|
I use DirectX Sample Browser with WebCam device, but I can't link "strmbasd.lib", help me!
aloha
|
|
|
|
|
aloha1812 wrote: but I can't link "strmbasd.lib"
What is the problem ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Hi,
To link 'Strmiids.lib' Library File ...... Build the base-class of 'DirectShow' & then add path-name of library files of DirectX in your program.
Best Regards,
Aniket
|
|
|
|
|
Hi
how can I make a copy of file on another location while it is open
would there be a problem to copy it using my app to another location , when it is open too.
thanks
Regards.
|
|
|
|