Kotlin - Data TypesIdentify the error in this Kotlin code snippet:val num = 0b1021_0010AUnderscores are not allowed in binary literalsBBinary literals cannot contain digits other than 0 or 1CBinary literals must start with 0xDThe number is too large for binary formatCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand valid digits in binary literalsBinary literals can only contain digits 0 and 1, optionally separated by underscores.Step 2: Check the given literal for invalid digitsThe literal contains '2', which is invalid in binary. Underscores are allowed, and binary literals start with 0b, not 0x.Final Answer:Binary literals cannot contain digits other than 0 or 1 -> Option BQuick Check:Binary digits must be 0 or 1 only [OK]Quick Trick: Binary digits only 0 or 1, no other digits allowed [OK]Common Mistakes:MISTAKESUsing digits other than 0 or 1 in binaryConfusing hex prefix 0x with binary 0bThinking underscores are disallowed in binary
Master "Data Types" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Mutable vs immutable interfaces - Quiz 2easy Control Flow as Expressions - If as an expression returning value - Quiz 8hard Control Flow as Expressions - When expression as powerful switch - Quiz 5medium Data Types - Nothing type for functions that never return - Quiz 14medium Kotlin Basics and JVM Runtime - What is Kotlin - Quiz 15hard Operators and Expressions - Arithmetic operators - Quiz 9hard Operators and Expressions - Arithmetic operators - Quiz 10hard Operators and Expressions - Why operators are functions in Kotlin - Quiz 9hard Variables and Type System - Val for immutable references - Quiz 10hard Variables and Type System - Var for mutable references - Quiz 14medium