Char क्या है
एक Char बिल्कुल एक letter, digit, या symbol रखता है, जैसे किसी word game की एक tile। इसे single quotes में लिखा जाता है।
In this page:
Syntax
val ch: Char = 'a'
Char
एक Char एक single UTF-16 character को represent करता है, जिसे single quotes से लिखा जाता है, जैसे A। Characters को compare किया जा सकता है और .toInt से उनके underlying numeric code point में cast किया जा सकता है।
Double quotes String के लिए reserved हैं, Char के लिए नहीं, और इन्हें मिला देना एक आम beginner mistake है।
Note:
.toInt से किसी Char को Int में cast करने पर आपको उसका Unicode code point मिलता है।उदाहरण: Char
object Main extends App {
val letter: Char = 'A'
val digit: Char = '7'
println(letter)
println(letter.toInt)
println(digit.isDigit)
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
Charके लिए double quotes का उपयोग करना, जैसेval c: Char = "A", जो एकStringहै और compile नहीं होता।7के लिएletter.toIntसे digit की value की उम्मीद करना, जबकि यह character code55देता है।ABजैसे एक Char में दो characters store करने की कोशिश करना, जो एक compile error है।
🔒
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: