Pointers to structure

Hi friends here is my code please have a look at end i'll tell you what is wrong
 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include #include using namespace std; struct employee{ int empID; char empName[20]; int empGrade; }; int main() { employee user[3]; employee* users; for(int i = 0;i<3;i++) { cout<<"Employee NO."<>user[i].empID; cout<<"Please enter the Name of the employee NO.: "; cin>>user[i].empName; cout<<"Please enter the grade of the employee NO.: "; cin>>user[i].empGrade; cout<

You noticed that i have created a pointer for nothing but my teacher ask me to use that pointer to assign the values to each data member of the array
how can i do that i don't under stand i mean how can i use one pointer to point to different locations or my thinking is wrong is it possible
 ``1234567891011121314151617`` `````` employee user[3]; employee* users = user; for(int i = 0;i<3;i++) { cout<<"Employee NO."<>users->empID; cout<<"Please enter the Name of the employee NO.: "; cin>>users->empName; cout<<"Please enter the grade of the employee NO.: "; cin>>users->empGrade; cout<
Last edited on
It can also be done without using pointer arithmetic:
 ``12345678910111213141516`` ``````employee user[3] employee* users; for(int i = 0;i<3;i++) { users = &user[i]; cout<<"Employee NO."<>users->empID; cout<<"Please enter the Name of the employee NO.: "; cin>>users->empName; cout<<"Please enter the grade of the employee NO.: "; cin>>users->empGrade; cout<
Topic archived. No new replies allowed.