1

When I tried to compile the following C++ program:

//Source: C++ How To Program, Sixth Edition
#include <iostream>
int main()
{
int a;
int *aPtr;
a=7;
aPtr=&a;
std::cout<<"The address of a is: "<<&a<<std::endl;
std::cout<<"The value of aPtr is: "<<aPtr<<std::endl;
std::cout<<"The value of a is: "<<a<<std::endl;
std::cout<<"The value of *aPtr is: "<<*aPtr<<std::endl;
std::cout<<"Showing that * and & are inverses of each"
<<" other"<<std::endl;
std::cout<<"&*aPtr= "<<&*aPtr<<std::endl;
std::cout<<"*&aPtr= "<<*&aPtr<std::endl;
return 0;
}

I got the following error:

enter image description here

Any ideas on that?

Thanks.

7
  • I'd suggest you put some more spaces in, e.g. around your operators std::cout << "*&aPtr= " << *&aPtr < std::endl; This would make it all easier to read! Commented Jan 27, 2011 at 11:04
  • And always compile with g++ -Wall... Commented Jan 27, 2011 at 11:05
  • 1
    If you can cut and paste the error as text from the console, that is much easier to read than a picture. Commented Jan 27, 2011 at 11:15
  • @David Rodríguez - dribeas. I'm using Cygwin console, and cannot do that. Commented Jan 27, 2011 at 11:30
  • @Paul R. What is -wall? Thanks Commented Jan 27, 2011 at 11:30

6 Answers 6

6

Replace

std::cout<<"*&aPtr= "<<*&aPtr<std::endl;

by

std::cout<<"*&aPtr= "<<*&aPtr<<std::endl;

Just a syntax error in your code ( < instead of << ).

Sign up to request clarification or add additional context in comments.

Comments

3

It looks like a simple typo in line 15. You forgot one "<" between aPTR and the endl-constant ;)

std::cout<<"*&aPtr= "<<*&aPtr<std::endl;

Comments

3

You missed a < on the last line:

//----------------------------v here.
std::cout<<"*&aPtr= "<<*&aPtr<<std::endl;

Comments

3

Yes, the typo on line 15, where you've written < instead of <<. The error message makes that pretty clear!

Comments

3

Line 15 says *&aPtr < std::endl. should be << instead of <.

You would spot this kind of error more easily if you put spaces between operators and operants.

Comments

2

fix this line (syntax error) (<< instead of <)

std::cout<<"*&aPtr= "<<*&aPtr<std::endl;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.