In a mock test: The 8859-1 character code for the uppercase letter A is 65. Which of these code fragments declare and initialize a variable of type char with this value? 1)char ch = 65; 2)char ch = '\65'; 3)char ch = '\0041'; 4)char ch = 'A'; 5)char ch = "A"; the answer is (4) why 1 is not right?
don't know what i am saying but you are right no explicit casting is needed because it's ijn the rangoe of char. So therefore the answer should also be right.
both 1 and 4 r right!! char c = 65; the character with an ascii value of 65 is assigned to c, in this case the ascii value of A is 65. So c='A' (implicitly).
This looks like Q59 of the Mughal Sample Exam in Appendix E. The printing I have (printing 4) lists answers a and d as correct: (a) char ch = 65; (d) char ch = 'A'; URL for Mughal errata. Printing 1 had the above error. http://www.ii.uib.no/~khalid/pgjc/jcbook/errata.html
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
a bit of art, as a gift, the permaculture playing cards