To complete your example, it would be,
Quid est hoc? What is this?
Because "what" is neuter, whereas "who" could be masculine or feminine.
The demonstratives (hic, ille, iste, and is) can be used as either pronouns or adjectives. You can read about their paradigms on section 146 of Allen and Greenough, and their uses on section 296.
When demonstratives are used as substantives, which is the scenario you speak of, the gender and number are determined by context. Allen and Greenough give some examples from Caesar.
sī obsidēs ab eīs dentur (Bellum Gallicum 1.14)
if hostages should be given by them
In the above example, Caesar is at war, so it's only natural that "them" refers to male soldiers. Thus it makes sense that the plural masculine is used. However, this sadly does not make a difference, since the plural is equivalent in masc./fem./neut. for the ablative.
Hī sunt extrā prōvinciam trāns Rhodanum prīmī. (Bellum Gallicum 1.10)
These (men/people) are the first (inhabitants) beyond the province across the Rhone.
Above, the masculine plural is used. The demonstrative pronoun Hi refers to men, or men and women. When you are referring to men and women it is common to use the masculine plural.
ille minimum propter adulescentiam posset (Bellum Gallicum 1.20)
He could do little on account of his youth.
Above, the demonstrative ille is used more like a personal pronoun. It means "he". This use of the demonstrative as personal is quite common. You can think of it as, that (man) = he.
Lastly, let's look at a famous Latin phrase.
Ad hoc ("for this")
The phrase ad hoc uses the neuter pronoun because it refers to a thing, task, or purpose, as opposed to a person. This idea of a thing or task is often expressed by the neuter.
Hope that's clear. Gender and number are determined by context, in the case where demonstratives are used substantively. Sometimes there is an implied noun, such as one expressed in the previous sentence or clause, and then the demonstrative will get its gender and number from the implied noun.