1. He painted food for hungry people.

2. He painted food for the hungry.

(Are both the same?)

3. In China, there lived a poor boy who loved to paint(,) and whose name was Ma Liang.
(Is this sentence grammatical? Do we have to use 'comma' before 'and' or not?)

You have used the wrong verb -- "painted." Please check to see which word you really want.

3 is correct. You don't need any commas in that sentence.

With a magic paintbrush, he painted food. (folktale)

Ohh. OK.

Both of those sentences are correct, then.

1. Yes, both sentences convey the same meaning. The only difference is in the inclusion of the article "the" before "hungry" in the second sentence. In sentence 1, it is implied that the food was painted specifically for hungry people, whereas sentence 2 suggests that the food was painted for any general hungry individuals. Both sentences are grammatically correct and can be used interchangeably, depending on the intended meaning.

2. The sentence "In China, there lived a poor boy who loved to paint and whose name was Ma Liang" is grammatically correct. In this case, a comma before "and" is optional because the phrase "and whose name was Ma Liang" is nonrestrictive, meaning it provides additional information about the boy but is not essential for the sentence's overall meaning. If the information between the commas were taken out, the sentence would still be grammatically complete and make sense. However, adding the comma helps to separate the nonrestrictive phrase from the rest of the sentence, making it easier to read and emphasizing the additional information about the boy. Therefore, both versions of the sentence (with or without the comma) are acceptable, but using the comma is generally considered more stylistically preferred.