Question on Pointer tutorial

Reference http://www.cplusplus.com/doc/tutorial/pointers/

I can't seems to compile "foo = &myvar;" but I can compile "*foo = &myvar;"
Did I miss out any std files?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
int myvar = 25;
int foo = &myvar;
int bar = myvar;
int beth = *foo;
return(0);

}
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    int myvar = 25; // type of myvar is 'int'
    
    // int foo = &myvar;
    int* foo = &myvar; // type of foo is 'pointer to int'
    
    int bar = myvar; // type of bar is 'int'
    
    int beth = *foo; // type of beth is 'int'
}
u cant assign address of a variable to a normal variable as suggested by @JLBorgers u need to use pointer of same type

int *foo = &myvar;
i.e the tutorial is wrong??
The tutorial simply omits the types. You inferred them all to be int, which was incorrect. The tutorial intended for you to assume the types were those given by JLBorges.
ah...ok. got it. thanks!
Topic archived. No new replies allowed.