Isnt this how I would dereferrence a pointer
and to assign the value in num to iCode:int *num;
...
...
int i;
i = #
Code:i = **num;
Printable View
Isnt this how I would dereferrence a pointer
and to assign the value in num to iCode:int *num;
...
...
int i;
i = #
Code:i = **num;
An example:
Code:int* p = new int;
*p = 3; // Assign 3 to the space pointed to by p
int num = *p; // num == 3 now
or...
int num = 3;
int* p = # // p now points to num
no, it would be
Code:int *num;
...
...
int i = 5;
num = &i;
...
...
int x = *num; //to assign value POINTED TO by num to x
No, it's like this
andCode:int *num;
int i;
//The memory adress of i is stored in num.
num = &i;
;)Code://The memory contents pointed by num are dereferenced ONCE and placed in i
i = *num;
//EDIT: UH!! fast posters :cool:
What about :
where val is a variable within a classCode:int *num;
int i;
num.val=10;
i=num.val;
a) num is a pointer to an int
b) the syntax is wrong
Code:struct foo
{
int val;
};
int main()
{
foo* bar = new foo;
bar->val = 2;
(*bar).val = 3;
delete bar;
}
No!
num is a pointer to an INT.
Could be
//edit: post beated again! :pCode:class Int{
int val;
Int(int n=0) : val(n){}
};
Int num;
int i;
num.val=10;
i=num.val;
Quote:
Originally Posted by xErath
What are we debating about? ;)Quote:
Originally Posted by Zach L.
- Stack Overflow
Check the times. They posted simultaneously.
Ah, thanks; just noticed.
I'll keep my eye on post times in the future. It may be the key to the answer ;)
- Stack Overflow