# Simple pointer question

• 11-16-2004
sweets
Simple pointer question
Isnt this how I would dereferrence a pointer

Code:

```int *num; ... ... int i; i = &num;```
and to assign the value in num to i

Code:

`i = **num;`
• 11-16-2004
Zach L.
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 = &num; // p now points to num```
• 11-16-2004
Hunter2
no, it would be
Code:

```int *num; ... ... int i = 5; num = &i; ... ... int x = *num;  //to assign value POINTED TO by num to x```
• 11-16-2004
xErath
No, it's like this
Code:

```int *num; int i; //The memory adress of i is stored in num. num = &i;```
and
Code:

```//The memory contents pointed by num are dereferenced ONCE and placed in i i = *num;```
;)
//EDIT: UH!! fast posters :cool:
• 11-16-2004
sweets

Code:

```int *num; int i; num.val=10; i=num.val;```
where val is a variable within a class
• 11-16-2004
Zach L.
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;  }```
• 11-16-2004
xErath
No!
num is a pointer to an INT.

Could be
Code:

```class Int{     int val;     Int(int n=0) : val(n){} }; Int num; int i; num.val=10; i=num.val;```
//edit: post beated again! :p
• 11-16-2004
Stack Overflow
Quote:

Originally Posted by xErath
No!
num is a pointer to an INT.

Quote:

Originally Posted by Zach L.
a) num is a pointer to an int

What are we debating about? ;)

- Stack Overflow
• 11-16-2004
XSquared
Check the times. They posted simultaneously.
• 11-16-2004
Stack Overflow
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