Menu
CoddyTech
Course

C++ for Kotlin Developers

Transfer Kotlin experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.

Kotlin and C++ side by side

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

  1. Strings and Output

    Kotlin String is immutable and its length counts UTF-16 code units; building text means a StringBuilder or a string template. C++ std::string owns a mutable byte sequence; stream insertion formats values. Length counts bytes, not Unicode characters.

    Kotlin
    1fun main() {2    println("oak".length)3}
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::string name="oak";std::cout<<name.size()<<"\n";15}
  2. Text Equality

    Kotlin == calls equals and compares string contents, while === checks reference identity. C++ has no separate identity operator for strings. C++ std::string equality compares contents. Raw pointer equality compares addresses; user classes need a deliberate…

    Kotlin
    1fun main() {2    val a = "red"3    val b = StringBuilder("re").append('d').toString()4    println("${a == b} ${a === b}")5}
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::string a="red",b="red";std::cout<<std::boolalpha<<(a==b)<<"\n";15}
  3. Fixed-size Arrays

    Kotlin arrays such as IntArray have a fixed length, but they are reference objects: the length is a runtime value and assignment shares the same array. C++ std::array<T,N> is a fixed-size value type. Its size is part of its type, and normal copy duplicates…

    Kotlin
    1fun main() {2    val a = intArrayOf(4, 5, 6)3    val b = a4    b[1] = 95    println("${a.size} ${a[1]}")6}
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::array<int,3> a{4,5,6};std::cout<<a.size()<<" "<<a.at(1)<<"\n";15}
  4. Value Copies

    In Kotlin, val b = a copies a reference: both names see the same MutableList, and only toMutableList() makes a separate (shallow) copy. C++ container assignment copies values. C++ vector and string copies own independent storage. Copying a raw pointer still…

    Kotlin
    1fun main() {2    val a = mutableListOf(4)3    val b = a4    b.add(9)5    val c = a.toMutableList()6    c.add(1)7    println("${a.size} ${b.size} ${c.size}")8}
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::vector<int> a{4};auto b=a;b.push_back(9);std::cout<<a.size()<<" "<<b.size()<<"\n";15}
  5. Functions and Returns

    Kotlin, like C++, allows top-level functions outside any class. An expression body (= n * 2) infers its return type, and a block body without a declared type returns Unit, a real object you can store and print. C++ function declarations establish parameter…

    Kotlin
    1fun twice(n: Int) = n * 22
    3fun log(n: Int) {4    println("got $n")5}6
    7fun main() {8    val r = log(twice(4))9    println(r)10}
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12int triple(int n){return 3*n;}13int main(){14std::cout<<triple(4)<<"\n";15}
  6. Streams and Exact Parsing

    Kotlin parses text with toInt(), which throws NumberFormatException on bad input, or toIntOrNull(), which returns null; both require the whole string to be a number. C++ stream extraction reports success through stream state. Validate conversion and reject…

    Kotlin
    1fun main() {2    val parts = "oak 7 7x".split(" ")3    val word = parts[0]4    val n = parts[1].toInt()5    val bad = parts[2].toIntOrNull()6    println("$word/$n/$bad")7}
    C++
    1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12
    13int main(){14std::istringstream in("oak 7x");std::string word;int n;char rest;if(in>>word>>n)std::cout<<word<<"/"<<n<<"\n";if(in>>rest)std::cout<<"left: "<<rest<<"\n";15}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for Kotlin developers

Learn C++ from another language

Frequently asked questions

Who is C++ for Kotlin Developers for?

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

Do I need to know C++ already?

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

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

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

What does C++ for Kotlin Developers cover?

The course is organized into chapters covering: C++ Files and Values, Conditions and Iteration, Standard Containers, Copies and Algorithms, and more.

Is C++ for Kotlin 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 C++ for Kotlin Developers for free

Get started