Pointers

Respected Fellow members, I am not that much expert in C++, however when practicing pointers I encountered following problem.

I am trying to implement the following code obtained form http://www.functionx.com/cpp/Lesson13.htm

#include <iostream>

using namespace std;



int main()

{

int students;

int *ptrStudents;



ptrStudents = &students;

cout << "Number of students: ";

cin >> *ptrStudents;



cout << "\nNumber of students: " << students

<< "\nThat is: " << *ptrStudents << " students.";




cout << "\n\n";

return 0;

}


However, at the underlined line, i am receiving the msg error C2100: illegal indirection

pls help
The code compiles and works correctly for me.
The code compiles and works correctly for me.
Same here.
The code compiles and works correctly for me.
Same here.

Same here.

-Albatross
This is what your compiler complains about:
http://msdn.microsoft.com/en-us/library/bzf3eha6%28VS.71%29.aspx
That is you try to dereference something that is not a pointer.

But the piece of code here works ok. Maybe when you were pasting/typing it in your compiler editor you missed an asterisk (*) in the declaration of ptrStudents...
Topic archived. No new replies allowed.