简体   繁体   中英

Confusion with C syntax (relating to pointer and ampersand)

Through this website, http://c.learncodethehardway.org/book/ex17.html , I am now learning C programming and now I am trying to understand the codes written there. So, I know about the basic pointer, and all of the stuffs that associated to it, at least I think so.

I came up with this code from above's URL (below's code is simplified):

void Database_get(struct Connection *conn, int id)
{
    struct Address *addr = &conn->db->rows[id];
}

Does the Right Hand Side of the above's code means &(conn->db->rows[id]) or (&conn)->db->rows[id] ? From the way I look at it, it means &(conn->db->rows[id]) . Sorry if this is a basic stuff. Still in the midst of learning. Already tried to Google this stuff, can't seems to find it.

Thanks in advance.

The concept you're looking for is operator precedence . In C and C++, -> and [] have higher precedence than & . Moreover, -> and [] have left-to-right associativity, so they are resolved in this order:

&(((conn->db)->rows)[id])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM