{"id":2601,"date":"2022-08-03T21:28:21","date_gmt":"2022-08-03T16:28:21","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2601"},"modified":"2022-08-03T21:28:25","modified_gmt":"2022-08-03T16:28:25","slug":"carbon-language-tutorial-with-syntax-and-code-examples","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/","title":{"rendered":"Carbon Language Tutorial with Syntax and Code Examples"},"content":{"rendered":"\n<p>Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an experimental project. There is no working compiler or toolchain. You can see the demo interpreter for Carbon on\u00a0<a href=\"http:\/\/carbon.compiler-explorer.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">compiler-explorer.com<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Carbon Declarations<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Functions\/Methods are declared using\u00a0<code>fn<\/code>\u00a0keyword.<\/li><li>Variables are declared using\u00a0<code>var<\/code>\u00a0keyword.<\/li><li>Variable names should end with\u00a0<code>:<\/code>\u00a0eg:\u00a0<code>var x:<\/code><\/li><li>Constants are declared using\u00a0<code>let<\/code>\u00a0keyword.<\/li><li>Packages are declared using\u00a0<code>package<\/code>\u00a0keyword.<\/li><li>Comments are declared using two slashes\u00a0<code>\/\/<\/code><\/li><li><code>auto<\/code>\u00a0can be used to automatically assign the variable type. It can be used in combination with\u00a0<code>let<\/code>\u00a0or\u00a0<code>var<\/code>\u00a0or as function return types.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example code snippet:<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\n\/\/fn is function declaration\n\/\/return type is i32 i.e. int.\nfn Main() -> i32 {\n  \/\/This is a comment.\n\n  var name: auto = \"Muhammad Furqan Ul Haq\"; \/\/ Auto Variable\n  let id: i32 = 57; \/\/ Integer Constant\n  var total_articles_published: i32 = 4500; \/\/ Integer Variable\n  \n  Print(name); \/\/ Print \"name\" Auto Variable\n  Print(id); \/\/ Print \"id\" Constant\n  Print(total_articles_published); \/\/ Print \"total_articles_published\" Integer Variable\n  \n  return 0; \/\/Return value\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Numeric Variables in Carbon<\/h2>\n\n\n\n<p>Variables in carbon language can be<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>bool<\/code>\u00a0for boolean\u00a0<code>true<\/code>\u00a0or\u00a0<code>false<\/code><\/li><li><code>i8<\/code>,\u00a0<code>i16<\/code>,\u00a0<code>i32<\/code>,\u00a0<code>i64<\/code>,\u00a0<code>i128<\/code>,\u00a0<code>i256<\/code>\u00a0for integer types.<\/li><li><code>u8<\/code>,\u00a0<code>u16<\/code>,\u00a0<code>u32<\/code>,\u00a0<code>u128<\/code>,\u00a0<code>u256<\/code>\u00a0for unsigned integer types.<\/li><li><code>f16<\/code>,\u00a0<code>f32<\/code>,\u00a0<code>f64<\/code>, and\u00a0<code>f128<\/code>\u00a0for float types.<\/li><li><code>_<\/code>\u00a0can be used for digit separators. Eg: 1_000_000 is still an integer if declared without quotes.<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var a: i32 = 1;\n  var b: i32 = 2;\n  Print(a + b);\n  return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Strings in Carbon<\/h2>\n\n\n\n<p>Strings can be declared using<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>String<\/code>\u00a0for byte sequence<\/li><li><code>StringView<\/code>\u00a0as a read-only reference for the utf-8 byte sequence.<\/li><\/ul>\n\n\n\n<p>Strings literals can be declared in two ways.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Single Line: Use double quotation marks (&#8220;) for a single line.<\/li><li>Multi-line string: For multi-line string declaration use (<code>\"\"\"<\/code>)<\/li><\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var singleLine: String = \"Hello world!\";\n  var multiLine: String = \"\"\"hello line 1\n            TipSeason demo line 2\n            TipSeason demo line 3    \n        \"\"\"; \/\/End of multi block\n  return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Arrays in Carbon<\/h2>\n\n\n\n<p>Arrays are declared using array type and size. Syntax is\u00a0<code>[type; size]<\/code>\u00a0Eg:\u00a0<code>var xarray: [i32; 4] = (1,2,3,4);<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var xarray: [i32; 4] = (0, 1, 5, 6); \/\/ Integer array \n  var index: i32 = 1;\n  xarray[index] = 0;\n  Print(\"{0}\", xarray[0]);\n  Print(\"{1}\", xarray[0]);\n  return xarray[0] + xarray[1];\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conditional Statements (if&#8230;else) in Carbon<\/h2>\n\n\n\n<p>Combination of\u00a0<code>if<\/code>\u00a0,\u00a0<code>else<\/code>\u00a0can be used to control the conditional flow in Carbon.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">if&#8230;else<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if(condition) {\n \/\/doSomething\n} else {\n \/\/doSomething\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">if&#8230;else-if&#8230;else<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if(condition) {\n \/\/doSomething\n} else if (condition) {\n \/\/doSomething\n} else {\n  \/\/doSomething\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example:-<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var x: i32 = 5;\n  if(x == 5) {\n    Print(\"{0} to word is FIVE\", x);\n  } else {\n    Print(\"{0} is not known \", x);\n  }\n  return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Loops in Carbon<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">For Loop<\/h3>\n\n\n\n<p>For loop can be declared using\u00a0<code>for (loop conditions) { }<\/code>\u00a0. At the time of writing this article, didn\u2019t get a full working example. But here is the proposed\u00a0<a href=\"https:\/\/github.com\/carbon-language\/carbon-lang\/tree\/trunk\/docs\/design#for\">syntax<\/a>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n\n  var names: [String; 4] = (\"a\", \"b\");\n  for (var name: String in names) {\n   Console.Print(name);\n  }\n\n  return x;\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">While loop<\/h3>\n\n\n\n<p>While loop can be declared using\u00a0<code>while(condition){ }<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var x: auto = 5;\n  while (not (x == 0)) {\n    x = x - 1;\n    Print(\"{0}  \", x);\n  }\n  return x;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Match multiple conditions similar to Switch<\/h2>\n\n\n\n<p>Carbon has\u00a0<code>match<\/code>\u00a0keyword which is similar to\u00a0<code>switch<\/code>\u00a0in C\/C++. The syntax for match is<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">match(condition) {\n  case (condition) => {\n    \/\/doSomething;\n  }\n  default => {\n    \/\/doSomething;\n  }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Matcher(var num: i32) -> i32 {\n  var number: auto = 10;\n  match (number) {\n    case 5 => {\n      Print(\"Got 5\");\n      return number;\n    }\n    case 10 => {\n      Print(\"Got 10\");\n      return number;\n    }\n    default => {\n      Print(\"Default\");\n      return number;\n    }\n  }\n}\n\nfn Main() -> i32 {\n    Matcher(5);\n    Matcher(10);\n    Matcher(2);\n    return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Functions\/Methods in Carbon<\/h2>\n\n\n\n<p>Functions can be declared using\u00a0<code>fn<\/code>\u00a0keyword. The syntax is\u00a0<code>fn MethodName(var param: type ... ) -> return type<\/code>\u00a0. For void or empty return types, you can ignore the part after\u00a0<code>-><\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\n\/\/Integer return type \nfn Sum(var a: i32, var b: i32) -> i32 {\n    return a + b;\n}\n\n\/\/Empty or void return type. \nfn PrintCount(var count: i32) {\n    Print(\"The count is {0}\", count);\n}\n\nfn Main() -> i32 {\n    Print(\"Sum is {0}\", Sum(4, 6));\n    PrintCount(10);\n    return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Tuples in Carbon<\/h2>\n\n\n\n<p>Tuples represent values with multiple coordinates. They can be declared using parenthesis\u00a0<code>( )<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var x: auto = (0, 1);\n  Print(\"{0}\", x[1]);\n  return x[0];\n}<\/pre>\n\n\n\n<p>Here\u00a0<code>(x,y,z)<\/code>\u00a0is a tuple with multiple coordinates. They can be accessed using the index.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Pointers in Carbon<\/h2>\n\n\n\n<p>There are no null pointers in Carbon. To represent a pointer that may not refer to a valid object, use the type Optional(T*) where&nbsp;<code>T<\/code>&nbsp;is the type.<\/p>\n\n\n\n<p><code>*<\/code>\u00a0represents value.\u00a0<code>&amp;<\/code>\u00a0represents address.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var x: i32 = 5;\n  \/\/ changes x to 10\n  x = 10;\n  Print(\"---\");\n  Print(\"x = {0}\", x);\n  var y: i32* = &amp;x;\n  \/\/ changes x to 7\n  *y = 7;\n  Print(\"---\");\n  Print(\"x = {0}\", x);\n  Print(\"y = {0}\", *y);\n  var z: i32* = &amp;*y;\n  \/\/ changes x to 0\n  *z = 0;\n  Print(\"---\");\n  Print(\"x = {0}\", x);\n  Print(\"y = {0}\", *y);\n  Print(\"z = {0}\", *z);\n  var w: i32 = *y;\n\n  return w;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Classes in Carbon<\/h2>\n\n\n\n<p>Class in carbon language can be declared using\u00a0<code>class<\/code>\u00a0keyword. Class can have members and methods. Here is an example of class implementation.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nclass Sum {\n  var a: i32;\n\n  fn Add[me: Self](var num: i32) -> i32 {\n      var total: i32 = me.a + num;\n      return total;\n  }\n}\n\nfn Main() -> i32 {\n  var p1: Sum = {.a = 5};\n  var total: i32 = p1.Add(5);\n  Print(\"Total sum {0}\" , total);\n  return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Structs in Carbon<\/h2>\n\n\n\n<p>Structural types help you identify members using the name instead of their index\/position. They are declared within curly braces\u00a0<code>var name: auto = {.name1 = value1, .name2 = value2, ... }<\/code>\u00a0and can be accessed using\u00a0<code>name.name1<\/code>\u00a0etc.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn Main() -> i32 {\n  var point: auto = {.x_axis = 0, .y_axis = 1};\n  point = {.x_axis = 5, .y_axis = -5};\n  var result: i32 = point.x_axis * point.x_axis + point.y_axis * point.y_axis;\n  Print(\"Result : {0}\", result);\n  return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Generics in Carbon<\/h2>\n\n\n\n<p>Generics can be seen in many modern languages. They define a way to induce compile time type checks and help define cleaner type variables. They can be declared using\u00a0the T\u00a0parameter type as shown below.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package ExplorerTest api;\n\nfn GenericExample[T:! Type](x: T) -> T {\n  return x;\n}\n\nfn Main() -> i32 {\n  Print(\"Integer generic type {0}\", GenericExample(0));\n  Print(GenericExample(\"This is a string generic\"));\n  return 0;\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Memory safety in Carbon<\/h2>\n\n\n\n<p>Carbon language has a heavy focus on memory management especially when it comes to memory safety. At a very high-level, carbon language plans to achieve memory safety using<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Spatial Memory Safety<\/li><li>Temporal memory safety<\/li><\/ul>\n\n\n\n<p>Here is a detailed tutorial on how memory safety is achieved in carbon along with goals and basics. Check\u00a0<a href=\"https:\/\/tipseason.com\/carbon-language-memory-safety\">Carbon language memory safety for secure memory management<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an experimental project. There is no working compiler or toolchain. You can see the demo interpreter for Carbon on\u00a0compiler-explorer.com. Carbon Declarations Functions\/Methods are declared using\u00a0fn\u00a0keyword. Variables are declared using\u00a0var\u00a0keyword. Variable names &#8230; <a title=\"Carbon Language Tutorial with Syntax and Code Examples\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/\" aria-label=\"Read more about Carbon Language Tutorial with Syntax and Code Examples\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2607,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Carbon Language Tutorial with Syntax and Code Examples<\/title>\n<meta name=\"description\" content=\"Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Carbon Language Tutorial with Syntax and Code Examples\" \/>\n<meta property=\"og:description\" content=\"Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-03T16:28:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-03T16:28:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/carbon_language_tutorial.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"880\" \/>\n\t<meta property=\"og:image:height\" content=\"495\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Carbon Language Tutorial with Syntax and Code Examples","description":"Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/","og_locale":"en_US","og_type":"article","og_title":"Carbon Language Tutorial with Syntax and Code Examples","og_description":"Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an","og_url":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-08-03T16:28:21+00:00","article_modified_time":"2022-08-03T16:28:25+00:00","og_image":[{"width":880,"height":495,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/carbon_language_tutorial.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Carbon Language Tutorial with Syntax and Code Examples","datePublished":"2022-08-03T16:28:21+00:00","dateModified":"2022-08-03T16:28:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/"},"wordCount":546,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/carbon_language_tutorial.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/","url":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/","name":"Carbon Language Tutorial with Syntax and Code Examples","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/carbon_language_tutorial.jpg","datePublished":"2022-08-03T16:28:21+00:00","dateModified":"2022-08-03T16:28:25+00:00","description":"Carbon is an open-source programming language developed by Google as a successor to C++. At the time of writing this tutorial, Carbon language is an","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/carbon_language_tutorial.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/08\/carbon_language_tutorial.jpg","width":880,"height":495,"caption":"Carbon Language Tutorial with Syntax and Code Examples"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/carbon-language-tutorial-with-syntax-and-code-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Carbon Language Tutorial with Syntax and Code Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2601"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2601\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/2607"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}