The first line of the play, "Who's there?"—spoken in a commanding voice by an armed guard on a raised platform—instantly grabs the audience's attention and piques their interest. As the scene unfolds, the characters on stage ask leading questions that, when answered, give the audience insight into the events that have happened before the play takes place:
BERNARDO: Have you had quiet guard
FRANCISCO: Not a mouse stirring. . . .
FRANCISCO: Stand, ho! Who is there?
[Enter Horatio and Marcellus]
HORATIO: Friends to this ground. . . .
What, is Horatio there?
HORATIO: A piece of him. . . .
MARCELLUS: What, has this thing appear'd again to-night? (1.1.10–28)
The audience is left to wonder: what "thing" has reappeared tonight? Marcellus calls it "this dreaded sight" and "this apparition." Just as Bernardo starts to explain what the "thing" is to Horatio (and to the audience), the "thing" actually appears:
MARCELLUS: Peace! break thee off! Look where it comes
BERNARDO: In the same figure, like the King that's dead. (1.1.50–51)
This thing, the ghost, looks like King Hamlet, and Horatio confirms for Bernardo (and for the audience) that the ghost looks like the dead king. Horatio then tries to talk to the ghost, but "It stalks away." The master of understatement, Horatio then remarks, "Tis strange."
More exposition follows, with Horatio providing the audience with the dead King's background information and bringing the audience up to date on current events regarding the sword-rattling by "young Fortinbras" at Denmark's borders. Horatio then discusses the kind of ill omen that the dead King's appearance might portend for Denmark. Just in case the audience has forgotten who or what Horatio is talking about, the ghost appears again!
Again Horatio tries to talk with the ghost, and again the ghost stalks away without responding to him. Horatio, Bernardo, and Marcellus then try to stop it:
HORATIO: Stop it,
MARCELLUS: Shall I strike at it with my partisan?
HORATIO: Do, if it will not stand.
BERNARDO: 'tis here!
HORATIO: 'tis here!
MARCELLUS: 'tis gone! (1.1.153–159)
Horatio, Marcellus, and Bernardo (and the audience) then relax a bit after all the excitement, and Horatio decides that they must tell "young Hamlet" about what they've seen. Earlier, when Horatio was referencing "Hamlet," he was referring to the dead King whose name was Hamlet (rather than "young Hamlet," his son, who isn't mentioned until six lines from the end of the scene).
Thus this opening scene functions to lay the foundation for the rest of the play—which is the purpose of the scene—through a question-and-answer technique that allows the characters onstage to impart information to the audience. All of the talk about "this apparition" and the appearance of the ghost itself makes sure that the audience pays attention to what they need to in order to understand the rest of the play.
In the next scene, the audience is then introduced to "young Hamlet" as well as the other principle characters, who have only been alluded to in this first scene.