what does mean

'->' What doeas mean
Please give some examples.
t->g
Last edited on
It is a pointer dereference and a member selection operator combined in one. Here is an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct S {
    int a;
};
 
int main() {
    S s;
    s.a = 5; // member selection

    int *pn = &s.a; // make a pointer to that value
    std::cout << "PN: " << pn << "\n"; // memory address
    std::cout << "*PN: " << *pn << "\n"; // dereference pointer

    S *ps = &s;
    std::cout << "(*PS).A: " << (*ps).a << "\n"; // derefence ps and get 'a'
    std::cout << "PS->A: " << ps->a << "\n"; // shorthand of the above

    return 0;
}
Last edited on
Big thanks to you
Its is a dereferencing operator. You need to know pointers to understand it though.

Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>

using namespace std;

struct Employee
{
	unsigned int age;
	unsigned int salary;
};

int main()
{
	Employee emp1; //Here we create a new instance of the Employee structure
	emp1.age = 24; //We set the age
	emp1.salary = 10000; //And the salary

	Employee *ptr = &emp1; //We create a pointer of type Employee and point it to the memory address of emp1.

	cout << "Age of emp1: " << ptr->age << endl; //We can't use ptr.age, we need to use ptr->age
	cout << "Salary of emp1: " << ptr->salary << endl; //-> takes what is in the memory address of salary

	//Note: If not working with pointers like emp1 we do: emp1.age but if its a pointer to a struct we do ptr->age.

	return 0;
}
Last edited on
Topic archived. No new replies allowed.