Menu
CoddyTech
Course

Kotlin for C++ Developers

Transfer C++ experience to Kotlin through null safety, collections, functions, properties and object contracts. Compare value copying, captures and dispatch, then build an order processor and port a stock ledger.

C++ and Kotlin side by side

The same program in C++ and in Kotlin, from the lessons of this course.

  1. Strings and Templates

    C++ streams combine output through insertion operators, while Kotlin string templates embed values or expressions in a string. Kotlin println adds a newline. std::string stores bytes; Kotlin/JVM String uses UTF-16 code units, so length conventions differ for…

    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <map>5#include <set>6#include <algorithm>7#include <numeric>8#include <optional>9#include <functional>10#include <sstream>11#include <variant>12#include <memory>13#include <cctype>14#include <stdexcept>15
    16
    17int main() {18std::cout << std::boolalpha;19std::string name="Ada";std::cout << "Hello, " << name << "!\n";20}
    Kotlin
    1
    2fun main(){3val ready=34println("Ready: $ready")5}
  2. Equality and Identity

    C++ classes can define operator== and std::string compares text, while pointer equality compares addresses. Kotlin == uses null-safe equals and === tests reference identity. Strings have content equality, but an ordinary class does not automatically compare…

    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <map>5#include <set>6#include <algorithm>7#include <numeric>8#include <optional>9#include <functional>10#include <sstream>11#include <variant>12#include <memory>13#include <cctype>14#include <stdexcept>15
    16
    17int main() {18std::cout << std::boolalpha;19std::string a="ab",b=std::string("a")+"b";std::cout << (a==b) << "\n";20}
    Kotlin
    1
    2fun main(){3val a=String(charArrayOf('t','e','a'))4val b=String(charArrayOf('t','e','a'))5println(a==b)6}
  3. Arrays and IntArray

    C++ std::array owns fixed-size storage and std::vector grows; Kotlin arrays instead have a fixed runtime size and checked indexing. IntArray gives primitive integer storage, while Array<Int> uses a generic representation on the JVM. size and lastIndex expose…

    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <map>5int main(){6int a[]={4,8,12};std::cout << a[2] << "\n";7}
    Kotlin
    1
    2fun main(){3val a=intArrayOf(4,8,12)4println(a.last())5}
  4. While, Break, and Continue

    C++ and Kotlin support while, break and continue, but Kotlin requires Boolean conditions. Ensure a manual index advances along every continuing path. Kotlin string == compares content, so sentinel tests can use it directly. Keep ignoring empty values separate…

    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <map>5#include <set>6#include <algorithm>7#include <numeric>8#include <optional>9#include <functional>10#include <sstream>11#include <variant>12#include <memory>13#include <cctype>14#include <stdexcept>15
    16
    17int main() {18std::cout << std::boolalpha;19int n=3;while(n>1)--n;std::cout << n << "\n";20}
    Kotlin
    1
    2fun main(){3val kept=mutableListOf<String>()4for(word in listOf("tea","","STOP","coffee")){if(word=="STOP")break;if(word.isEmpty())continue;kept.add(word)}5println(kept.joinToString(","))6}
  5. Top-level Functions

    C++ free functions can take values, references or pointers, including output references that rebind caller state. Kotlin top-level functions also need no utility class, but their ordinary parameter bindings are read-only and do not provide C++…

    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <map>5#include <set>6#include <algorithm>7#include <numeric>8#include <optional>9#include <functional>10#include <sstream>11#include <variant>12#include <memory>13#include <cctype>14#include <stdexcept>15
    16int twice(int n){return n*2;}17int main() {18std::cout << std::boolalpha;19std::cout << twice(4) << "\n";20}
    Kotlin
    1fun isLong(text:String):Boolean = text.length>42fun main(){3println(isLong("coffee"))4}
  6. Input and String Formatting

    C++ streams and string conversions have their own whitespace and failure conventions. Kotlin readlnOrNull represents end-of-input as null, and toInt requires a complete valid integer string. Trim only when the contract allows it, and format machine output…

    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <map>5int main(){6int cents=305;std::cout << "tea: " << cents/100 << "." << (cents%100<10 ? "0":"") << cents%100 << "\n";7}
    Kotlin
    1
    2fun main(){3println("  tea  ".trim().uppercase(java.util.Locale.ROOT))4}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

Final Challenges

2 lessons

More courses for C++ developers

Learn Kotlin from another language

Frequently asked questions

Who is Kotlin for C++ Developers for?

For people who already write C++ and want to learn Kotlin. Each lesson starts from C++ you know and shows how Kotlin does the same thing, so you skip the beginner basics.

Do I need to know Kotlin already?

No. The course starts with your first Kotlin program. You need C++ basics: variables, conditions, loops, functions and collections.

How many lessons does Kotlin for C++ Developers have?

Kotlin for C++ Developers contains 48 interactive lessons you can complete at your own pace.

What does Kotlin for C++ Developers cover?

The course is organized into chapters covering: Starting Kotlin, Values and Decisions, Collections and Ownership, Iteration and Transformations, and more.

Is Kotlin for C++ Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start Kotlin for C++ Developers for free

Get started