dictionary/map/key-value pairs data structure in C
Posted
by
morgancodes
on Stack Overflow
See other posts from Stack Overflow
or by morgancodes
Published on 2010-12-29T05:23:48Z
Indexed on
2011/01/01
20:53 UTC
Read the original article
Hit count: 106
c
|data-structures
How does one construct and access a set of key-value pairs in C? To use a silly simple example, let's say I want to create a table which translates between an integer and its square root.
If I were writing javascript, I could just do this:
var squareRoots = {
4: 2,
9: 3,
16: 4,
25: 5
}
and then access them like:
var squareRootOf25 = squareRoots[5]
What's the prettiest way to do this in C? What if I want to use one type of enum as the key and another type of enum as the value?
© Stack Overflow or respective owner