Question sur le code de jeudi 21.11.19

Re: Question sur le code de jeudi 21.11.19

by Sepand Kashani -
Number of replies: 0
La flèche est une notation qui peux s'utiliser avec des pointeurs sur structures pour simplifier l'accès à leurs attributs.

#include <iostream>

struct A {
    int a;
    int b;
};

int main() {
    A obj = {1, 2};
    A* ptr = &obj;

    std::cout <<    obj.a << ", " <<    obj.b << std::endl;  // 1, 2
    std::cout << (*ptr).a << ", " << (*ptr).b << std::endl;  // 1, 2
    std::cout <<  ptr->a << ", " <<  ptr->b << std::endl;  // 1, 2

    return 0;
}