• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mock test question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
I too feel choice #1 is correct.What was the Xam BTW?
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if it would have been like this then it would be right
char a = (char)65;
otherwise it's 4
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both 1 AND 4 are correct !!
uma
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic