C++ for C Developers
Transfer C experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.
C and C++ side by side
The same program in C and in C++, from the lessons of this course.
Strings and Output
C character arrays require explicit capacity and terminators. C++ std::string owns its storage and tracks length; stream insertion formats values without a printf format string. String length counts bytes, not Unicode characters.
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5 6int main(void){7char name[]="oak";printf("%zu\n",strlen(name));8return 0;9}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}Text Equality
C string pointers compare addresses with ==; strcmp compares their contents. C++ std::string overloads equality to compare contents. Raw C++ pointers still compare addresses, so choosing the owning string type changes the available operations.
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5 6int main(void){7char a[]="red",b[]="red";puts(strcmp(a,b)==0?"true":"false");8return 0;9}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}Fixed-size Arrays
A C array decays to a pointer in many expressions and does not carry its length into a function parameter. C++ std::array is a fixed-size value type whose size is part of its type. It can be copied and exposes size and iterators.
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5 6int main(void){7int a[]={4,5,6};printf("%zu %d\n",sizeof a/sizeof a[0],a[1]);8return 0;9}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}Value Copies
C struct assignment copies member values, but copying a pointer does not duplicate its allocation. C++ vector and string copies own independent storage. A class containing raw pointers still needs a deliberate ownership policy; prefer owning standard members.
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5 6int main(void){7struct Pair{int x,y;};struct Pair a={4,2},b=a;b.x=9;printf("%d %d\n",a.x,b.x);8return 0;9}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}Functions and Returns
C++ declarations and definitions serve the same separate-compilation roles as in C. Parameter types, references, and const qualifications are part of the contract. Returning a value differs from printing it; library functions should leave presentation to…
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5int triple(int n){return 3*n;}6int main(void){7printf("%d\n",triple(4));8return 0;9}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}Streams and Exact Parsing
C parsers inspect conversion counts, end pointers, and error flags. C++ string streams expose extraction success and permit checking for extra tokens. Failed extraction does not guarantee a useful parsed value; branch on stream state before using it.
C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5 6int main(void){7char word[16];int n;if(sscanf("oak 7","%15s %d",word,&n)==2)printf("%s/%d\n",word,n);8return 0;9}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 7");std::string word;int n;if(in>>word>>n)std::cout<<word<<"/"<<n<<"\n";15}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsC++ Files and Values
6 lessonsConditions and Iteration
5 lessonsStandard Containers
5 lessonsCopies and Algorithms
5 lessonsFunctions and Templates
5 lessonsParsing and Lifetime
5 lessonsObjects and Invariants
6 lessonsComposition and Ownership
5 lessonsProject: Library Desk
4 lessonsFinal Challenges
2 lessonsFrequently asked questions
Who is C++ for C Developers for?
For people who already write C and want to learn C++. Each lesson starts from C 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 C basics: variables, conditions, loops, functions and collections.
How many lessons does C++ for C Developers have?
C++ for C Developers contains 48 interactive lessons you can complete at your own pace.
What does C++ for C 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 C Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.