← Back to Scala Course | Chapter 2: Variables & Types | Lesson 4 of 8

Char क्या है

एक Char बिल्कुल एक letter, digit, या symbol रखता है, जैसे किसी word game की एक tile। इसे single quotes में लिखा जाता है।

In this page:

  1. Char
Syntax
scala
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

markup
object Main extends App {
  val letter: Char = 'A'
  val digit: Char = '7'

  println(letter)
  println(letter.toInt)
  println(digit.isDigit)
}
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. #}
आम गलतियां
  1. Char के लिए double quotes का उपयोग करना, जैसे val c: Char = "A", जो एक String है और compile नहीं होता।
  2. 7 के लिए letter.toInt से digit की value की उम्मीद करना, जबकि यह character code 55 देता है।
  3. AB जैसे एक Char में दो characters store करने की कोशिश करना, जो एक compile error है।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.