114k views
5 votes
If chr is a character variable, which of the following if statements is written correctly? A. if (chr = "a") B. if (chr == "a") C. if (chr = 'a') D. if (chr == 'a')

1 Answer

3 votes

Answer:

D.if(chr=='a')

Step-by-step explanation:

Since chr is a character variable means it can only store a single character it could be any character.Characters are written in c++ language using single quotes out of the other three statements two of them uses double quotes and the third uses assignment operator instead equal to operator.Double quotes are used for null terminated strings.

User Kakiang
by
5.1k points