{"id":80737,"date":"2021-05-14T09:00:08","date_gmt":"2021-05-14T03:30:08","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=80737"},"modified":"2021-05-14T09:00:08","modified_gmt":"2021-05-14T03:30:08","slug":"syntax-of-cpp","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/","title":{"rendered":"C++ Syntax | Learn C++ Programming Language"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In programming, the term \u201csyntax\u201d signifies the set of predefined rules, processes, and protocols that everyone should follow, if they want an error-free code. Just like every other programming language, even C++ has its own distinctive syntax.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">In this article from TechVidvan, you\u2019ll get a clear idea of the syntax of a C++ program. Let&#8217;s start!!!<\/span><\/p>\n<h3><span style=\"font-weight: 400\">C++ Program\u00a0<\/span><\/h3>\n<p><span style=\"font-weight: 400\">When we look at the C++ program, we can define it as a collection of interactive objects by invoking each other&#8217;s methods. Now let&#8217;s take a brief look at what class, object, methods, and instance variables mean:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Class<\/strong>: It is basically a template or a blueprint that describes the function\/state of an object.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Object<\/strong>: Object depicts states and behaviors of the data. A plant has its type, color, and characteristics. One should note that an object is just an instance of a class.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Methods<\/strong>: Behaviors are termed as methods in C++. Methods are the most important part of C++ as it helps to perform all tasks such as writing concepts, data processing, and all other actions. There can be many methods in a single class.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>Instance Variables:<\/strong> The state of an object is usually determined by the values \u200b\u200bgiven by the variables of the model as each item has its own unique set of instance variables.<\/span><\/li>\n<\/ul>\n<h3>C ++ Identifiers<\/h3>\n<p>In C++ every user-defined data including variable, function, class, and objects are named unique. The identifier is nothing but a term for such names. Identifiers can start with any letter of the English lexicon, irrespective of its case.<\/p>\n<p>It can even begin with an underscore (_). It can also contain digits, but special symbols like @, $, and % are not allowed within C++ identifiers.<\/p>\n<p>Since C++ is a case-sensitive language, TechVidvan and techvidvan are two different identifiers in C ++.<\/p>\n<h3>First C++ Program<\/h3>\n<p><span style=\"font-weight: 400\">Displaying \u201cHello World\u201d is usually the first step to learn about the syntax of a programming language.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;iostream&gt;\nusing namespace std;\n\nint main()\n{\n\/* This is the hello world program *\/\n    cout &lt;&lt;\"Hello World, welcome to TechVidvan! \" &lt;&lt; endl; \/\/print statement\n    return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">Hello World, welcome to TechVidvan!<\/span><\/div>\n<h3>Components of C++ Program<\/h3>\n<p><span style=\"font-weight: 400\">From the above program, it is quite evident that there are many components in a C++ program. Here, at TechVidvan we will discuss every component to clear our understanding.\u00a0<\/span><\/p>\n<h4>1. Header files<\/h4>\n<p>Normally, the header file instructs the C ++ compiler to include all the functions associated with that title file. We have used just one header file, #include &lt;iostream&gt;, &#8216;iostream&#8217; represents the input-output stream.<\/p>\n<p>The &lt;iostream&gt; header file allows you to use input and output functionality. Hence, helped us to display the message \u201cHello World!\u201d on the screen.<\/p>\n<h4>2. Namespace<\/h4>\n<p>A namespace is a descriptive region that provides scope to the identifiers (names of types, functions, variables, etc.) within them. We use namespaces to organize code into sensible groups and prevent possible word conflicts, especially when your codebase includes more than one library.<\/p>\n<p>In the above program, we used using namespace std; which asks the compiler to use the std namespace. There\u2019s another way of using namespace, by the use of the scope resolution operator \u201c::\u201d (we will learn about it in the future articles)<\/p>\n<p>This is how we will use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">std::cout&lt;&lt;\"Hello world, welcome to TechVidvan!\";\n\n<\/pre>\n<p>We write this line in every C++ program. Hence, whenever we write cout, the compiler knows that we mean std::cout.<\/p>\n<h4>3. Comments<\/h4>\n<p><span style=\"font-weight: 400\">To give details and explanations about the code or blocks of code, we need to use comments. Sometimes the code becomes a little tedious for the user to understand and we may need to explain our code, for that C++ supports comments.\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400\">a. Single-line comments (<\/span><span style=\"font-weight: 400\">\/\/<\/span><span style=\"font-weight: 400\">)<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Single-line comment is prefixed with two front slashes \u201c\/\/\u201d and it ends when the user jumps to another line.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">\/\/print statement<\/span><\/p>\n<p><span style=\"font-weight: 400\">This single-line comment makes the user\/reader understand that this line is a print statement. Similarly, we can use them to explain what we as a writer mean by that particular line.\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400\">b.\u00a0 <\/span><span style=\"font-weight: 400\">Multi-line comments (<\/span><span style=\"font-weight: 400\">\/* This is the hello world program *\/<\/span><span style=\"font-weight: 400\">)<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Multi-line comments begin with \u201c\/*\u201d and end where \u201c*\/\u201d is detected.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Sometimes, we need to add comments of more than one line, for that C++ supports another type of comment. As writing it on one continued line makes it unreadable, we use multi-line comments or block comments when the explanation isn\u2019t short.<\/span><\/p>\n<p><span style=\"font-weight: 400\">It must be noted that comments are not code snippets, they are not a part of the code. Hence, if there is an error in the comments the compiler won\u2019t detect them as it completely ignores them. It is always a good practice to use comments, it helps the user to understand the code better.<\/span><\/p>\n<h4>4. The main method<\/h4>\n<p><span style=\"font-weight: 400\">The program must contain a main() method and the program execution will fail if there\u2019s no main() function. <\/span><span style=\"font-weight: 400\">int<\/span> <span style=\"font-weight: 400\">main<\/span><span style=\"font-weight: 400\">()<\/span><span style=\"font-weight: 400\"> is the main function where program execution begins and the return type is int. But, we are not done yet, without <\/span><span style=\"font-weight: 400\">return<\/span> <span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\">;<\/span><span style=\"font-weight: 400\"> the main() function won\u2019t terminate and the execution will fail.<\/span><\/p>\n<h4>5. Print statement<\/h4>\n<p><span style=\"font-weight: 400\">In C, we use printf() function along with format specifiers. Whereas in C++ we need not use format specifiers. We just need to use the cout function along with \u2018&lt;&lt;\u2019, the output operator.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">cout<\/span><span style=\"font-weight: 400\"> &lt;&lt;<\/span><span style=\"font-weight: 400\">&#8220;Hello World, welcome to TechVidvan&#8221;&lt;&lt;endl<\/span><span style=\"font-weight: 400\">;<\/span><\/p>\n<p><span style=\"font-weight: 400\">As discussed earlier, we don\u2019t have to mention the namespace during print statements if we have added <\/span><span style=\"font-weight: 400\">using<\/span> <span style=\"font-weight: 400\">namespace<\/span> <span style=\"font-weight: 400\">std<\/span><span style=\"font-weight: 400\">; <\/span><span style=\"font-weight: 400\">at the start.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">In order to ask the compiler to move to the new line, we can use <\/span><span style=\"font-weight: 400\">endl.<\/span><\/p>\n<p><span style=\"font-weight: 400\">We can even use the escape sequence \u201c\\n\u201d for the same purpose.<\/span><\/p>\n<h4>6. Tokens<\/h4>\n<p><span style=\"font-weight: 400\">A token is the smallest part of the program, which holds some meaning for the compiler. There are 5 types of token, they are:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Keywords<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Identifiers<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Constants<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Strings<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Special Symbols<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Operators<\/span><\/li>\n<\/ul>\n<h3>Blocks and Semicolons in C++<\/h3>\n<p>In C++, a block is a group of logical statements wrapped in a pair of curly braces. Blocks are mainly used to connect logical statements with the same purpose.<\/p>\n<p>For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{\na=1;\nb=4;\nsum=a+b;\ncout&lt;&lt;sum; \/\/to print the sum of a &amp; b\n}\n<\/pre>\n<p><span style=\"font-weight: 400\">In C++, a semicolon terminates the sentence. This means every C++ sentence must be ended with a semicolon. The compiler knows that it is the end of a sentence when there\u2019s a semicolon, the end of the line is not recognized as a terminator.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">For example,\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int a,b; \na=4,b=5;\ncout&lt;&lt;a&lt;&lt;b;\n<\/pre>\n<p><span style=\"font-weight: 400\">Is the same as :<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int a,b; a=4,b=5; cout&lt;&lt;a&lt;&lt;b;\n<\/pre>\n<h3>Whitespaces in C++<\/h3>\n<p><span style=\"font-weight: 400\">Whitespaces are nothing but blank spaces which separate one part of the line of code from the other. They are required to denote tab spaces, blank spaces, end of line characters, and comments.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">For example:\u00a0<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">String TechVidvan;<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">If there was no whitespace after String, the compiler would have failed to distinguish between datatype and variable name.<\/span><\/p>\n<h3>Rules while writing a C++ program<\/h3>\n<p><span style=\"font-weight: 400\">1. C++ is a case-sensitive language i.e. it treats upper-case and lower-case alphabets differently.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">2. Most of the keywords are in lower-case and they must be kept in mind before naming the tokens.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">3. Every line of code must be terminated by a semicolon, or else it will throw an error.<\/span><\/p>\n<p><span style=\"font-weight: 400\">4. Whitespace must be properly allocated between keywords and variables in C++.<\/span><\/p>\n<h3>Keywords in C++<\/h3>\n<p>As we discussed earlier about the identifiers, we should now know about Keywords and their importance. In C++, there are certain words whose meaning is already explained to the compiler.<\/p>\n<p>Such \u201creserved words\u201d are termed as Keywords. Since they have a predefined meaning, we must not use them as identifiers.<\/p>\n<p>C++ language has 75 keywords that are not to be used as identifiers in a C++ program:<\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">asm<\/span><\/td>\n<td><span style=\"font-weight: 400\">else<\/span><\/td>\n<td><span style=\"font-weight: 400\">new<\/span><\/td>\n<td><span style=\"font-weight: 400\">this<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">auto<\/span><\/td>\n<td><span style=\"font-weight: 400\">enum<\/span><\/td>\n<td><span style=\"font-weight: 400\">operator<\/span><\/td>\n<td><span style=\"font-weight: 400\">throw<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">bool<\/span><\/td>\n<td><span style=\"font-weight: 400\">explicit<\/span><\/td>\n<td><span style=\"font-weight: 400\">private<\/span><\/td>\n<td><span style=\"font-weight: 400\">true<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">break<\/span><\/td>\n<td><span style=\"font-weight: 400\">export<\/span><\/td>\n<td><span style=\"font-weight: 400\">protected<\/span><\/td>\n<td><span style=\"font-weight: 400\">try<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">case<\/span><\/td>\n<td><span style=\"font-weight: 400\">extern<\/span><\/td>\n<td><span style=\"font-weight: 400\">public<\/span><\/td>\n<td><span style=\"font-weight: 400\">typedef<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">catch<\/span><\/td>\n<td><span style=\"font-weight: 400\">false<\/span><\/td>\n<td><span style=\"font-weight: 400\">register<\/span><\/td>\n<td><span style=\"font-weight: 400\">typeid<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">char<\/span><\/td>\n<td><span style=\"font-weight: 400\">float<\/span><\/td>\n<td><span style=\"font-weight: 400\">reinterpret_cast<\/span><\/td>\n<td><span style=\"font-weight: 400\">typename<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">class<\/span><\/td>\n<td><span style=\"font-weight: 400\">for<\/span><\/td>\n<td><span style=\"font-weight: 400\">return<\/span><\/td>\n<td><span style=\"font-weight: 400\">union<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">const<\/span><\/td>\n<td><span style=\"font-weight: 400\">friend<\/span><\/td>\n<td><span style=\"font-weight: 400\">short<\/span><\/td>\n<td><span style=\"font-weight: 400\">unsigned<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">const_cast<\/span><\/td>\n<td><span style=\"font-weight: 400\">goto<\/span><\/td>\n<td><span style=\"font-weight: 400\">signed<\/span><\/td>\n<td><span style=\"font-weight: 400\">using<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">continue<\/span><\/td>\n<td><span style=\"font-weight: 400\">if<\/span><\/td>\n<td><span style=\"font-weight: 400\">sizeof<\/span><\/td>\n<td><span style=\"font-weight: 400\">virtual<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">default<\/span><\/td>\n<td><span style=\"font-weight: 400\">inline<\/span><\/td>\n<td><span style=\"font-weight: 400\">static<\/span><\/td>\n<td><span style=\"font-weight: 400\">void<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">delete<\/span><\/td>\n<td><span style=\"font-weight: 400\">int<\/span><\/td>\n<td><span style=\"font-weight: 400\">static_cast<\/span><\/td>\n<td><span style=\"font-weight: 400\">volatile<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">do<\/span><\/td>\n<td><span style=\"font-weight: 400\">long<\/span><\/td>\n<td><span style=\"font-weight: 400\">struct<\/span><\/td>\n<td><span style=\"font-weight: 400\">wchar_t<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">double<\/span><\/td>\n<td><span style=\"font-weight: 400\">mutable<\/span><\/td>\n<td><span style=\"font-weight: 400\">switch<\/span><\/td>\n<td><span style=\"font-weight: 400\">while<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">dynamic_cast<\/span><\/td>\n<td><span style=\"font-weight: 400\">namespace<\/span><\/td>\n<td><span style=\"font-weight: 400\">template<\/span><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Escape Sequences in C++<\/h3>\n<p><span style=\"font-weight: 400\">Control characters are non-printing characters used to control the printing behavior of the display stream objects. They are also known as escape sequences and are not displayed on the output screen. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Escape sequences can be inserted anywhere in the string and they begin with a backslash followed by the character which controls the display.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Some of the control characters along with their meanings are :<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\a<\/span><span style=\"font-weight: 400\"> &#8211; Bell<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\n<\/span><span style=\"font-weight: 400\"> &#8211; New line<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\r<\/span><span style=\"font-weight: 400\"> &#8211; Carriage return<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\b<\/span><span style=\"font-weight: 400\"> &#8211; Backspace<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\f<\/span><span style=\"font-weight: 400\"> &#8211; Formfeed<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\t<\/span><span style=\"font-weight: 400\"> &#8211; Horizontal tab<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\<\/span><span style=\"font-weight: 400\">&#8220;<\/span><span style=\"font-weight: 400\"> &#8211; Quotation mark<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\v<\/span><span style=\"font-weight: 400\"> &#8211; Vertical tab<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\&#8217;<\/span><span style=\"font-weight: 400\"> &#8211; Apostrophe<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\\\<\/span><span style=\"font-weight: 400\"> &#8211; Backslash<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\?<\/span><span style=\"font-weight: 400\"> &#8211; Question mark<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">\\<\/span><span style=\"font-weight: 400\">0<\/span><span style=\"font-weight: 400\"> &#8211; Null<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Let\u2019s learn the concept of escape sequence by implementing them:<\/span><\/p>\n<p><span style=\"font-weight: 400\">For example,\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;iostream&gt;\nusing namespace std;\n\nint main()\n{\n    cout &lt;&lt;\"Welcome to TechVidvan!Hope you are enjoying learning \";\n    return 0;\n}\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">Welcome to TechVidvan!Hope you are enjoying learning<\/span><\/div>\n<p><span style=\"font-weight: 400\">For some reason, if you want to break the print statement and display it in separate lines, you just need to insert the escape sequence for the new line \u201c\\n\u201d in the middle of the string.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;iostream&gt;\nusing namespace std;\n\nint main()\n{\n    cout &lt;&lt;\"Welcome to TechVidvan! \\nHope you are enjoying learning \";\n    return 0;\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">Welcome to TechVidvan!<\/span><span style=\"font-weight: 400\">Hope you are enjoying learning<\/span><\/p>\n<\/div>\n<h3>Trigraphs in C++<\/h3>\n<p><span style=\"font-weight: 400\">A few letters have another representation, called trigraph sequence. Trigraph represents a single letter even though it is a three-letter sequence. It is usually prefixed with two question marks \u2018??\u2019.\u00a0\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Trigraphs are extended wherever they appear, including alphabetical and character texts, in comments, and in the preprocessor.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The following are the most commonly used trigraph sequences along with their replacements:-<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??=<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 #<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??\/<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 \\<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??&#8217;<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 ^<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??(<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 [<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??)<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 ]<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??!<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 |<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??&lt;<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 {<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??&gt;<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 }<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">??-<\/span> <span style=\"font-weight: 400\">\u2192\u00a0 ~<\/span><\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>In this tutorial, we got to know about the components of the \u201cHello World\u201d C++ program. It helped us to learn about the main() method, comments, tokens, etc.<\/p>\n<p>We then went through the concepts of blocks, white spaces, keywords, and the escape sequence. Along with all this, we even got to know the basic rules of writing a C++ program which will help us in the future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In programming, the term \u201csyntax\u201d signifies the set of predefined rules, processes, and protocols that everyone should follow, if they want an error-free code. Just like every other programming language, even C++ has its&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":80741,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3405],"tags":[3440,3441,3442,3443],"class_list":["post-80737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpp","tag-c-syntax","tag-identifiers-in-c","tag-learn-c-programming","tag-whitespaces-in-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C++ Syntax | Learn C++ Programming Language - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn C++ Syntax to learn C++ programming Language. Learn various components of C++ Program, Identifiers, Blocks, Semicolons, Whitespaces etc\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ Syntax | Learn C++ Programming Language - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn C++ Syntax to learn C++ programming Language. Learn various components of C++ Program, Identifiers, Blocks, Semicolons, Whitespaces etc\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-14T03:30:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/05\/Syntax-of-C.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ Syntax | Learn C++ Programming Language - TechVidvan","description":"Learn C++ Syntax to learn C++ programming Language. Learn various components of C++ Program, Identifiers, Blocks, Semicolons, Whitespaces etc","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:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/","og_locale":"en_US","og_type":"article","og_title":"C++ Syntax | Learn C++ Programming Language - TechVidvan","og_description":"Learn C++ Syntax to learn C++ programming Language. Learn various components of C++ Program, Identifiers, Blocks, Semicolons, Whitespaces etc","og_url":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-05-14T03:30:08+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/05\/Syntax-of-C.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"C++ Syntax | Learn C++ Programming Language","datePublished":"2021-05-14T03:30:08+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/"},"wordCount":1594,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/05\/Syntax-of-C.jpg","keywords":["C syntax","Identifiers in C","Learn C++ programming","Whitespaces in C++"],"articleSection":["C++ Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/","url":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/","name":"C++ Syntax | Learn C++ Programming Language - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/05\/Syntax-of-C.jpg","datePublished":"2021-05-14T03:30:08+00:00","description":"Learn C++ Syntax to learn C++ programming Language. Learn various components of C++ Program, Identifiers, Blocks, Semicolons, Whitespaces etc","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/05\/Syntax-of-C.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/05\/Syntax-of-C.jpg","width":1200,"height":628,"caption":"C++ Syntax"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/syntax-of-cpp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"C++ Syntax | Learn C++ Programming Language"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=80737"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/80737\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/80741"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=80737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=80737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=80737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}