In the following sentences, what is the function of the words what and why? Are they subjects or objects?(a) "What did you say just now?" (b) "Why do dogs eat raw meat?"
Let's start by looking at your first question: "What did you say just now?"
When the word what is used to introduce a question, the word what is referred to as an interrogative pronoun. Two other interrogative pronouns are the words which and who. When used in sentences, interrogative pronouns introduce noun clauses and function as subjects in the clauses they are used in. An example of this is the sentence: "I already told the detective what I know about it"(grammar.ccc.comnet). In this sentence the interrogative pronoun clause is "what I know about it." In this clause what is filling in for a noun and acting as part of the subject.
However, whenever we construct a question, the normal order of the subjects and verbs of sentences get switched around. In normal circumstances a sentence follows the pattern of Subject+Verb+Object/Predicate. But in sentences that are constructed as questions, the pattern becomes Verb+Subject+Object/Predicate. This is true for the following question example: "Are you ready?"(grammar.ccc.comnet). In this example are is the verb; you is the subject; and ready is the predicate. To see this easily, we can rewrite the question so that it is in the form of a sentence statement instead. The sentence would look like this: "You are ready."
We can use this technique to analyze your first question: "What did you just say now?" Rewritten as a sentence statement it would read: "You just said what now." This shows us that in your question the word you is your subject; say or said is your verb; and the phrase what now is your predicate. What is replacing a noun and is functioning as your object.
Therefore, in your first example the word what is an interrogative pronoun and is functioning as an object.
Let's take a look at your next question:"Why do dogs eat raw meat?" In this question, the word why has a different function from the word what. Because this sentence is still in question format, the word why is still an interrogative. However, why is also functioning as an adverb. Therefore, why is an interrogative adverb. However, unlike your previous question, why will never be considered the object. The object of this sentence is raw meat and why will always be considered the adverb.
The Longman's Dictionary of Contemporary English has the following entries for,
1.WHAT: "Pronoun" "Determiner" or "Predeterminer"
"used to ask for information or for someone's opinion."
2. WHY: "Adverb" "Conjunction"
"used to ask or talk about the reason for something."
3. Auxiliary Verb: "a verb that is used with another verb to show its tense, person, mood etc. In English the auxiliary verbs are 'be,' 'do,' and 'have' and all the modals.
4. Modal: one of these verb forms: can, could, may, might, shall, should, will, would, must, ought to, used to, need, had better, and dare. They are all used with other verbs to express ideas such as possibility, permission, or intention.
"WHAT" and "WHY" are certainly not auxiliary verbs or modals.
Let's divide and convert the two sentences into new ones like these:
(a) What you said just now?
-> you + said + just now + what + ?
(b) Dogs eat raw meat. Why?
-> Dogs + eat + raw meat + why + ?
Now, In the first example (a), watch carefully and think on your own which can be the subject and the object. Look at it, and see that "you" is subject. Isn't it? And "what" is the object. And it is an interrogative pronoun too. Because, it has replaced a noun.
Now, look at the second example (b), here "dogs" is already working as the subject and "raw meat" is as object. So, what is WHY? It is an interrogative adverb, acts to interrogate about a fact and modify that.
Hopefully, my answer might help you.