{"id":33,"date":"2018-07-09T11:08:11","date_gmt":"2018-07-09T11:08:11","guid":{"rendered":"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=33"},"modified":"2019-05-14T11:05:41","modified_gmt":"2019-05-14T11:05:41","slug":"overview-of-c","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/chapter\/overview-of-c\/","title":{"rendered":"Overview of C++"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/4CB6iIqFfGs\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Every Programming language like any language has basic character set on which the entire language is built. Language C++ has character set same as that of C.<\/p>\r\n&nbsp;\r\n\r\n<strong>Character sets<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The <em>basic source character set<\/em> consists of 96 characters: the space character, the control characters representing horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters:14<\/p>\r\n&nbsp;\r\n\r\na b c d e f g h i j k l m n o p q r s t u v w x y z\r\n\r\n&nbsp;\r\n\r\nA B C D E F G H I J K L M N O P Q R S T U V W X Y Z\r\n\r\n&nbsp;\r\n\r\n0 1 2 3 4 5 6 7 8 9\r\n\r\n_ { } [ ] # ( ) &lt; &gt; % : ; . ? * + - \/ ^ &amp; | \u223c ! = , \\ \" \u2019\r\n\r\n&nbsp;\r\n\r\n<strong>Trigraph Sequences<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Some characters from the C and C++ character set are not available in all environments. We can enter these characters into a C or C++ source program using a sequence of three characters called a <strong><em>trigraph<\/em><\/strong>. The trigraph sequences are:<\/p>\r\n&nbsp;\r\n<table class=\"aligncenter\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 144.063px\">??=<\/td>\r\n<td style=\"width: 94.0625px\">#<\/td>\r\n<td style=\"width: 408.063px\">pound sign<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??(<\/td>\r\n<td style=\"width: 94.0625px\">[<\/td>\r\n<td style=\"width: 408.063px\">left bracket<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??)<\/td>\r\n<td style=\"width: 94.0625px\">]<\/td>\r\n<td style=\"width: 408.063px\">right bracket<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??&lt;<\/td>\r\n<td style=\"width: 94.0625px\">{<\/td>\r\n<td style=\"width: 408.063px\">left brace<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??&gt;<\/td>\r\n<td style=\"width: 94.0625px\">}<\/td>\r\n<td style=\"width: 408.063px\">right brace<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??\/<\/td>\r\n<td style=\"width: 94.0625px\">\\<\/td>\r\n<td style=\"width: 408.063px\">backslash<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??\u2019<\/td>\r\n<td style=\"width: 94.0625px\">^<\/td>\r\n<td style=\"width: 408.063px\">caret<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??!<\/td>\r\n<td style=\"width: 94.0625px\">|<\/td>\r\n<td style=\"width: 408.063px\">vertical bar<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 144.063px\">??-<\/td>\r\n<td style=\"width: 94.0625px\">~<\/td>\r\n<td style=\"width: 408.063px\">tilde<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n\r\nThe preprocessor replaces trigraph sequences with the corresponding single-character representation.\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>Escape Sequences<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Nonprintable characters also known as execution characters can be represented by an <strong><em>escape<\/em><\/strong> <strong><em>sequence<\/em>. <\/strong>Escape sequences are primarily used to put nonprintable characters in character and string literals. For example, you can use escape sequences to put such characters as tab, carriage return, and backspace into an output stream.<\/p>\r\n&nbsp;\r\n\r\nThe escape sequences and the characters they represent are:\r\n\r\n<\/div>\r\n<img class=\"alignnone size-full wp-image-34 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2.png\" alt=\"\" width=\"664\" height=\"372\" \/>\r\n<div>\r\n<p style=\"text-align: justify\"><strong>Note: <\/strong>The line continuation sequence (\\ followed by a new-line character) is not an escape sequence. It is used in character strings to indicate that the current line continues on the next line. We can use escape sequences only in character constants or in string literals. An error message is issued if an escape sequence is not recognized. In string and character sequences, when you want the backslash to represent itself (rather than the beginning of an escape sequence), you must use a \\\\ backslash escape sequence. For example:<\/p>\r\n&nbsp;\r\n\r\ncout &lt;&lt; \"The escape sequence \\\\n.\" &lt;&lt; endl;\r\n\r\nThis statement results in the following output:\r\n\r\nThe escape sequence \\n.\r\n\r\n&nbsp;\r\n\r\n<strong>Alternative representations of operators and punctuators<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In addition to the reserved language keywords, the following alternative representations of operators and punctuators are also reserved in C and C++:<\/p>\r\n&nbsp;\r\n<table class=\"aligncenter\" style=\"width: 606px\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>Alternative<\/strong><\/td>\r\n<td style=\"width: 96.0625px\"><strong>Operator<\/strong><\/td>\r\n<td style=\"width: 106.063px\"><strong>Alternative<\/strong><\/td>\r\n<td style=\"width: 96.0625px\"><strong>Operator<\/strong><\/td>\r\n<td style=\"width: 106.063px\"><strong>Alternative<\/strong><\/td>\r\n<td style=\"width: 96.0625px\"><strong>Operator<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>Representation<\/strong><\/td>\r\n<td style=\"width: 96.0625px\"><strong>\/Punctuation<\/strong><\/td>\r\n<td style=\"width: 106.063px\"><strong>Representation<\/strong><\/td>\r\n<td style=\"width: 96.0625px\"><strong>\/Punctuation<\/strong><\/td>\r\n<td style=\"width: 106.063px\"><strong>Representation<\/strong><\/td>\r\n<td style=\"width: 96.0625px\"><strong>\/Punctuation<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><\/td>\r\n<td style=\"width: 96.0625px\"><strong>Represented<\/strong><\/td>\r\n<td style=\"width: 106.063px\"><\/td>\r\n<td style=\"width: 96.0625px\"><strong>Represented<\/strong><\/td>\r\n<td style=\"width: 106.063px\"><\/td>\r\n<td style=\"width: 96.0625px\"><strong>Represented<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>&lt;%<\/strong><\/td>\r\n<td style=\"width: 96.0625px\">{<\/td>\r\n<td style=\"width: 106.063px\">and<\/td>\r\n<td style=\"width: 96.0625px\">&amp;&amp;<\/td>\r\n<td style=\"width: 106.063px\">and_eq<\/td>\r\n<td style=\"width: 96.0625px\">&amp;=<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>%&gt;<\/strong><\/td>\r\n<td style=\"width: 96.0625px\">}<\/td>\r\n<td style=\"width: 106.063px\">bitor<\/td>\r\n<td style=\"width: 96.0625px\">|<\/td>\r\n<td style=\"width: 106.063px\">or_eq<\/td>\r\n<td style=\"width: 96.0625px\">|=<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>&lt;:<\/strong><\/td>\r\n<td style=\"width: 96.0625px\">[<\/td>\r\n<td style=\"width: 106.063px\">or<\/td>\r\n<td style=\"width: 96.0625px\">||<\/td>\r\n<td style=\"width: 106.063px\">xor_eq<\/td>\r\n<td style=\"width: 96.0625px\">^=<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>:&gt;<\/strong><\/td>\r\n<td style=\"width: 96.0625px\">]<\/td>\r\n<td style=\"width: 106.063px\">xor<\/td>\r\n<td style=\"width: 96.0625px\">^<\/td>\r\n<td style=\"width: 106.063px\">not<\/td>\r\n<td style=\"width: 96.0625px\">!<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>%:<\/strong><\/td>\r\n<td style=\"width: 96.0625px\">#<\/td>\r\n<td style=\"width: 106.063px\">compl<\/td>\r\n<td style=\"width: 96.0625px\">~<\/td>\r\n<td style=\"width: 106.063px\">not_eq<\/td>\r\n<td style=\"width: 96.0625px\">!=<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 106.063px\"><strong>%:%:<\/strong><\/td>\r\n<td style=\"width: 96.0625px\">##<\/td>\r\n<td style=\"width: 106.063px\">bitand<\/td>\r\n<td style=\"width: 96.0625px\">&amp;<\/td>\r\n<td style=\"width: 106.063px\"><\/td>\r\n<td style=\"width: 96.0625px\"><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>Wide Characters<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_Standard_Library\">C <\/a>and <a href=\"https:\/\/en.wikipedia.org\/wiki\/C%2B%2B_Standard_Library\">C++ <\/a>standard libraries include <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_string_handling\">a number of facilities <\/a>for dealing with wide characters and strings composed of them. The wide characters are defined using datatype wchar_t, which in the original C90 standard was defined as<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">\"an integral type whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales\" (ISO 9899:1990 \u00a74.1.5)<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Both C and <a href=\"https:\/\/en.wikipedia.org\/wiki\/C%2B%2B\">C++ <\/a>introduced fixed-size character types char16_t and char32_t in the 2011 revisions of their respective standards to provide unambiguous representation of 16-bit and 32-bit Unicode transformation formats, leaving wchar_t implementation-defined. The ISO\/IEC 10646:2003 Unicode standard 4.0 says that:\u00a0 \"The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.\"<\/p>\r\n&nbsp;\r\n\r\n<strong>Identifiers<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">An <em>identifier<\/em> is the user-defined name of a program element. In C++ identifier provides names for the following language elements:<\/p>\r\n&nbsp;\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Functions\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Objects\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Labels\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Function parameters\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Macros and macro parameters\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Typedefs\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Enumerated types and enumerators\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Classes and class members\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Templates\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Template parameters\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Namespaces\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Struct and union names\r\n<p style=\"text-align: justify\">An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9). In C++there is no limit on the length of the identifer , but implementers often impose one<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<strong>Keywords<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><em>Keywords <\/em>are identifiers reserved by the language for special use. Following is the list of keywords common to both the C and C++.<\/p>\r\n<img class=\"size-full wp-image-36 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/ss.png\" alt=\"\" width=\"851\" height=\"262\" \/>\r\n<p style=\"text-align: justify\">Only the exact spelling of keywords is reserved. For example, do is reserved but DO is not.<\/p>\r\n&nbsp;\r\n\r\n<strong>The C++ language also reserves the following keywords:<\/strong>\r\n\r\n<img class=\"size-full wp-image-37 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled.png\" alt=\"\" width=\"734\" height=\"321\" \/><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 We will see their use in successive modules<\/span><strong>Data Types<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Data type define the way you store the values used by and created by the program. Defining a data type means defining what constants (generally in terms of range) a variable of that data type can store and what operations can be performed on that value.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Data type can be built in or abstract. A built in data type compiler intrinsically understand. It is predefined and known to the compiler. Therefore we don\u2019t need to define them , they are made available to us for use. As C++ is superset of C, most of the built in data types are inherited as is in C++, and they can be used as we use them in C. The basic scalar data type namely int, float and double along with their modifiers signed, unsigned, short and long can be used as we use them in C. Pointers in C++ also can be used the way we use them in C except few additions that we will discuss in next module.<\/p>\r\n&nbsp;\r\n\r\n<\/div>\r\n<div>\r\n\r\nFollowing is the complete list of fundamental data types in C++:\r\n\r\n<img class=\"size-full wp-image-38 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1.png\" alt=\"\" width=\"838\" height=\"798\" \/>\r\n\r\n<strong>New Data types in C++<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In addition to these built in data types inherited from C , another data type boolean was added to standard C++ . The keyword used for this data type is bool . The variables of bool data type can have two possible values \u2013 built in constants true (which converts to integer 1) and false ( which converts to integer 0 ).<\/p>\r\n&nbsp;\r\n\r\nExample :\r\n\r\n&nbsp;\r\n\r\nbool found;\r\n\r\n&nbsp;\r\n\r\nIt can be assigned two values\r\n\r\n&nbsp;\r\n\r\nfound = true;\r\n\r\nOr\r\n\r\n&nbsp;\r\n\r\nfound = false\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"size-full wp-image-39 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2.png\" alt=\"\" width=\"882\" height=\"332\" \/>\r\n\r\n<strong>Abstract Data type<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Also C++ allows us to create our own data type, which with careful crafting can be made to look and behave quite similar to standard data type. They are also denoted as Abstract Data type. We will discuss about abstract data type in detail in modules 5.<\/p>\r\n&nbsp;\r\n\r\n<strong>Variable Declaration in C++<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">C and C++ are block structured programming languages. Scope and lifetime of the variables are determined by the block in which it is defined. The only difference being, that in C variables can only be defined in the beginning of the block , whereas in C++ variables can be defined anywhere in the block with only one restriction that they should be defined before their first use. For example<\/p>\r\n&nbsp;\r\n\r\n#include &lt;iostream&gt;\r\n\r\nUsing namesapce std;\r\n\r\nvoid main(void)\r\n\r\n{\r\n<table class=\"aligncenter\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 104.063px\">int value1 ;<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">value1 = 10;<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026.<\/td>\r\n<td style=\"width: 306.063px\">\/\/\u00a0 some executable code here<\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026.<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">int value2;<\/td>\r\n<td style=\"width: 306.063px\">\/\/\u00a0 this will not work in C but will work in C++<\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">{<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">int value 3;<\/td>\r\n<td style=\"width: 306.063px\">\/\/\u00a0 this will work in C and C++ both<\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026..<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026..\u2026<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">}<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\">}<\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 104.063px\"><\/td>\r\n<td style=\"width: 306.063px\"><\/td>\r\n<td style=\"width: 291.063px\"><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n<div>\r\n\r\n<strong>Storage Classes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Like C, C++ also has four storage classes namely auto, extern, register and static. Implementation of first three storage classes is similar to C. But static storage class has been extended in C++ for specific use with user defined data type. We will discuss this in detail in modules 6.<\/p>\r\n&nbsp;\r\n\r\n<strong>Operators in C++<\/strong>\r\n\r\n&nbsp;\r\n\r\nBeing superset of C, C++ has inherited all the operators from C. Apart from these operators, C++ has added new operators as well.\r\n\r\n&nbsp;\r\n\r\nHere we will discuss following commonly used operators.\r\n\r\n&nbsp;\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Scope resolution\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 New\r\n\r\n\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 delete\r\n\r\n&nbsp;\r\n\r\nDiscussion of other operators will require knowledge of other C++ constructs. We will discuss them in later modules as appropriate.\r\n\r\n&nbsp;\r\n\r\n<strong>Scope Resolution Operator ::<\/strong>\r\n\r\n&nbsp;\r\n\r\nWe know that in C &amp; C++. We can define the variables of the same name in different scope. For example have a look at the following program.\r\n\r\n&nbsp;\r\n\r\nint value = 10;\r\n\r\n&nbsp;\r\n\r\nvoid main(void)\r\n\r\n{\r\n\r\nint value = 20;\r\n\r\n&nbsp;\r\n\r\ncout &gt;&gt; value;\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Which value will be displayed ?<\/p>\r\n<p style=\"text-align: justify\">Yes you are right. The variable in the innermost scope will prevail and therefore 20 will be displayed. This is logical enough. But what if we want the global value to be displayed ? The answer to this is scope resolution operator ::<\/p>\r\n&nbsp;\r\n\r\nint value = 10;\r\n\r\n&nbsp;\r\n\r\nvoid main(void)\r\n\r\n{\r\n\r\nint value = 20;\r\n\r\n&nbsp;\r\n\r\ncout &gt;&gt; :: value;\r\n\r\n}\r\n\r\n&nbsp;\r\n\r\nHere 10 will be displayed.\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class. For example:<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\nint value = 0;\r\n\r\n&nbsp;\r\n\r\nvoid main(void)\r\n\r\n{\r\n\r\nint value = 0;\r\n\r\n&nbsp;\r\n\r\n::\u00a0\u00a0 value = 1; \/\/ set global count to 1\r\n\r\nvalue = 2; \/\/ set local count to\r\n\r\n2 return 0;\r\n\r\n&nbsp;\r\n\r\n}\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The declaration of value declared in the main() function hides the integer named value declared in global namespace scope. The statement :: value = 1 accesses the variable named value declared in global namespace scope.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">You can also use the class scope operator to qualify class names or class member names. If a class member name is hidden, you can use it by qualifying it with its class name and the class scope operator. We will discuss this in later modules.<\/p>\r\n&nbsp;\r\n\r\n<strong>New and Delete Operators<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We have used malloc(), calloc() , realloc() and free() functions for program controlled dynamic memory allocation and deallocation . These functions can be used in C++ as well, but apart from these functions C++ also provides operators new and delete for same.<\/p>\r\n&nbsp;\r\n\r\n<strong>New Operator<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe syntax of new operator is as follows\r\n\r\n&nbsp;\r\n\r\n&lt;data type&gt;\u00a0 *ptr\u00a0\u00a0 = new &lt;data type&gt;\r\n\r\nFor example\r\n\r\nint *iptr = new int;\r\n<p style=\"text-align: justify\">will allocate no of bytes needed to store integer and address of the allocated memory will be returned which we can store in a pointer to integer variable.<\/p>\r\nNew operator can be used to allocate memory to scalar data type as well as\u00a0<span style=\"text-align: initial;font-size: 1em\">float<\/span>\r\n\r\n<\/div>\r\n<div>\r\n\r\nfloat*fptr = new float ;\r\n\r\nchar*cptr = new char ;\r\n\r\n<\/div>\r\n<div>\r\n\r\nWe can initialize the allocated memory as follows\r\n\r\n&nbsp;\r\n\r\nint *iptr = new int(10);\r\n\r\nHere the memory allocated for integer will be initialized with value 10.\r\n\r\n<\/div>\r\nWe can also get memory allocated for array as follows\r\n\r\n&nbsp;\r\n\r\nint *array = new int [25];\r\n\r\nthis will allocate memory for 25 integers\r\n\r\nint\u00a0 *array = int[5][5];\r\n\r\n&nbsp;\r\n\r\nthis will allocate memory for 5 *5 two dimensional array.\r\n\r\n&nbsp;\r\n\r\n<strong>Delete operator<\/strong>\r\n\r\n&nbsp;\r\n\r\nDelete operator also has simple syntax\r\n\r\ndelete p;\r\n\r\nthis will release memory being ponted by pointer variable p.\r\n\r\n&nbsp;\r\n\r\n<strong>The advantage of using new and delete operator over memory allocation function.<\/strong>\r\n\r\n&nbsp;\r\n\r\nUse of new and delete operator is much more efficient and simple as compared to memory allocation functions\r\n<ul>\r\n \t<li>Function calls have executional overhead due to context switching. No such overhead is there with operators.<\/li>\r\n \t<li>Syntax<span style=\"text-align: initial;font-size: 1em\"> of new and delete operators is simple as need not pass <\/span>size<span style=\"text-align: initial;font-size: 1em\"> of data type and no type casting is needed.<\/span><\/li>\r\n \t<li>Also new and delete can be overloaded to meet specific<span style=\"text-align: initial;font-size: 1em\"> need of the application.<\/span><\/li>\r\n<\/ul>\r\n<strong>Conditional Structures<\/strong>\r\n\r\n&nbsp;\r\n\r\nAll the control structures such as\r\n<ul>\r\n \t<li>If and else<\/li>\r\n \t<li>switch case<\/li>\r\n \t<li>while loop<\/li>\r\n \t<li>do-while loop<\/li>\r\n \t<li>for loop<\/li>\r\n<\/ul>\r\nWork the same way as in C\r\n\r\n&nbsp;\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on Overview of C++<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/4CB6iIqFfGs\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<strong>Additional References<\/strong>\r\n\r\n&nbsp;\r\n\r\n1) Stanley Lippmann, \u201cC++ Primer\u201d, Pearson Education.\r\n\r\n2) Bjarne Stroustrup, \u201cThe C++ Programming Language\u201d, Pearson Education.\r\n\r\n3) Scott Mayer, \u201cEffective C++\u201d, Addison Wesley.\r\n\r\n4) Bhushan Trivedi , Programming with ANSI C++, 2\/e , Oxford University Press.\r\n\r\n5) Yashavant P. Kanetkar \u201cLet Us C++\u201d , Bpb Publications.\r\n\r\n6) Abhiram G. Ranade, \u201cAn Introduction to Programming through C++\u201d , McGraw Hill\r\n\r\n7) Ellis and B. Stroustrup \u201cAnnotated C++ Reference Manual\u201d, http:\/\/www.stroustrup.com\/arm.html\r\n\r\n8) Herbert Schildt, \u201cComplete Reference C++\u201d, McGraw Hill Publications.\r\n\r\n9) Ashok Kamthane, \u201cObject Oriented Programming with ANSI and Turbo C++\u201d, Pearson Education\r\n\r\n10) E Balaguruswami, \u201cObject Oriented Programming With C++\u201d, Tata McGraw Hill\r\n\r\n11) \u201cC++ FAQs\u201d, Pearson Education.\r\n\r\n","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/4CB6iIqFfGs\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Every Programming language like any language has basic character set on which the entire language is built. Language C++ has character set same as that of C.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Character sets<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The <em>basic source character set<\/em> consists of 96 characters: the space character, the control characters representing horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters:14<\/p>\n<p>&nbsp;<\/p>\n<p>a b c d e f g h i j k l m n o p q r s t u v w x y z<\/p>\n<p>&nbsp;<\/p>\n<p>A B C D E F G H I J K L M N O P Q R S T U V W X Y Z<\/p>\n<p>&nbsp;<\/p>\n<p>0 1 2 3 4 5 6 7 8 9<\/p>\n<p>_ { } [ ] # ( ) &lt; &gt; % : ; . ? * + &#8211; \/ ^ &amp; | \u223c ! = , \\ &#8221; \u2019<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Trigraph Sequences<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Some characters from the C and C++ character set are not available in all environments. We can enter these characters into a C or C++ source program using a sequence of three characters called a <strong><em>trigraph<\/em><\/strong>. The trigraph sequences are:<\/p>\n<p>&nbsp;<\/p>\n<table class=\"aligncenter\">\n<tbody>\n<tr>\n<td style=\"width: 144.063px\">??=<\/td>\n<td style=\"width: 94.0625px\">#<\/td>\n<td style=\"width: 408.063px\">pound sign<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??(<\/td>\n<td style=\"width: 94.0625px\">[<\/td>\n<td style=\"width: 408.063px\">left bracket<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??)<\/td>\n<td style=\"width: 94.0625px\">]<\/td>\n<td style=\"width: 408.063px\">right bracket<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??&lt;<\/td>\n<td style=\"width: 94.0625px\">{<\/td>\n<td style=\"width: 408.063px\">left brace<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??&gt;<\/td>\n<td style=\"width: 94.0625px\">}<\/td>\n<td style=\"width: 408.063px\">right brace<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??\/<\/td>\n<td style=\"width: 94.0625px\">\\<\/td>\n<td style=\"width: 408.063px\">backslash<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??\u2019<\/td>\n<td style=\"width: 94.0625px\">^<\/td>\n<td style=\"width: 408.063px\">caret<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??!<\/td>\n<td style=\"width: 94.0625px\">|<\/td>\n<td style=\"width: 408.063px\">vertical bar<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 144.063px\">??-<\/td>\n<td style=\"width: 94.0625px\">~<\/td>\n<td style=\"width: 408.063px\">tilde<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>The preprocessor replaces trigraph sequences with the corresponding single-character representation.<\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>Escape Sequences<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Nonprintable characters also known as execution characters can be represented by an <strong><em>escape<\/em><\/strong> <strong><em>sequence<\/em>. <\/strong>Escape sequences are primarily used to put nonprintable characters in character and string literals. For example, you can use escape sequences to put such characters as tab, carriage return, and backspace into an output stream.<\/p>\n<p>&nbsp;<\/p>\n<p>The escape sequences and the characters they represent are:<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-34 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2.png\" alt=\"\" width=\"664\" height=\"372\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2.png 664w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2-300x168.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2-65x36.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2-225x126.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/1-2-350x196.png 350w\" sizes=\"auto, (max-width: 664px) 100vw, 664px\" \/><\/p>\n<div>\n<p style=\"text-align: justify\"><strong>Note: <\/strong>The line continuation sequence (\\ followed by a new-line character) is not an escape sequence. It is used in character strings to indicate that the current line continues on the next line. We can use escape sequences only in character constants or in string literals. An error message is issued if an escape sequence is not recognized. In string and character sequences, when you want the backslash to represent itself (rather than the beginning of an escape sequence), you must use a \\\\ backslash escape sequence. For example:<\/p>\n<p>&nbsp;<\/p>\n<p>cout &lt;&lt; &#8220;The escape sequence \\\\n.&#8221; &lt;&lt; endl;<\/p>\n<p>This statement results in the following output:<\/p>\n<p>The escape sequence \\n.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Alternative representations of operators and punctuators<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In addition to the reserved language keywords, the following alternative representations of operators and punctuators are also reserved in C and C++:<\/p>\n<p>&nbsp;<\/p>\n<table class=\"aligncenter\" style=\"width: 606px\">\n<tbody>\n<tr>\n<td style=\"width: 106.063px\"><strong>Alternative<\/strong><\/td>\n<td style=\"width: 96.0625px\"><strong>Operator<\/strong><\/td>\n<td style=\"width: 106.063px\"><strong>Alternative<\/strong><\/td>\n<td style=\"width: 96.0625px\"><strong>Operator<\/strong><\/td>\n<td style=\"width: 106.063px\"><strong>Alternative<\/strong><\/td>\n<td style=\"width: 96.0625px\"><strong>Operator<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>Representation<\/strong><\/td>\n<td style=\"width: 96.0625px\"><strong>\/Punctuation<\/strong><\/td>\n<td style=\"width: 106.063px\"><strong>Representation<\/strong><\/td>\n<td style=\"width: 96.0625px\"><strong>\/Punctuation<\/strong><\/td>\n<td style=\"width: 106.063px\"><strong>Representation<\/strong><\/td>\n<td style=\"width: 96.0625px\"><strong>\/Punctuation<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><\/td>\n<td style=\"width: 96.0625px\"><strong>Represented<\/strong><\/td>\n<td style=\"width: 106.063px\"><\/td>\n<td style=\"width: 96.0625px\"><strong>Represented<\/strong><\/td>\n<td style=\"width: 106.063px\"><\/td>\n<td style=\"width: 96.0625px\"><strong>Represented<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>&lt;%<\/strong><\/td>\n<td style=\"width: 96.0625px\">{<\/td>\n<td style=\"width: 106.063px\">and<\/td>\n<td style=\"width: 96.0625px\">&amp;&amp;<\/td>\n<td style=\"width: 106.063px\">and_eq<\/td>\n<td style=\"width: 96.0625px\">&amp;=<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>%&gt;<\/strong><\/td>\n<td style=\"width: 96.0625px\">}<\/td>\n<td style=\"width: 106.063px\">bitor<\/td>\n<td style=\"width: 96.0625px\">|<\/td>\n<td style=\"width: 106.063px\">or_eq<\/td>\n<td style=\"width: 96.0625px\">|=<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>&lt;:<\/strong><\/td>\n<td style=\"width: 96.0625px\">[<\/td>\n<td style=\"width: 106.063px\">or<\/td>\n<td style=\"width: 96.0625px\">||<\/td>\n<td style=\"width: 106.063px\">xor_eq<\/td>\n<td style=\"width: 96.0625px\">^=<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>:&gt;<\/strong><\/td>\n<td style=\"width: 96.0625px\">]<\/td>\n<td style=\"width: 106.063px\">xor<\/td>\n<td style=\"width: 96.0625px\">^<\/td>\n<td style=\"width: 106.063px\">not<\/td>\n<td style=\"width: 96.0625px\">!<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>%:<\/strong><\/td>\n<td style=\"width: 96.0625px\">#<\/td>\n<td style=\"width: 106.063px\">compl<\/td>\n<td style=\"width: 96.0625px\">~<\/td>\n<td style=\"width: 106.063px\">not_eq<\/td>\n<td style=\"width: 96.0625px\">!=<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 106.063px\"><strong>%:%:<\/strong><\/td>\n<td style=\"width: 96.0625px\">##<\/td>\n<td style=\"width: 106.063px\">bitand<\/td>\n<td style=\"width: 96.0625px\">&amp;<\/td>\n<td style=\"width: 106.063px\"><\/td>\n<td style=\"width: 96.0625px\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>Wide Characters<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_Standard_Library\">C <\/a>and <a href=\"https:\/\/en.wikipedia.org\/wiki\/C%2B%2B_Standard_Library\">C++ <\/a>standard libraries include <a href=\"https:\/\/en.wikipedia.org\/wiki\/C_string_handling\">a number of facilities <\/a>for dealing with wide characters and strings composed of them. The wide characters are defined using datatype wchar_t, which in the original C90 standard was defined as<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">&#8220;an integral type whose range of values can represent distinct codes for all members of the largest extended character set specified among the supported locales&#8221; (ISO 9899:1990 \u00a74.1.5)<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Both C and <a href=\"https:\/\/en.wikipedia.org\/wiki\/C%2B%2B\">C++ <\/a>introduced fixed-size character types char16_t and char32_t in the 2011 revisions of their respective standards to provide unambiguous representation of 16-bit and 32-bit Unicode transformation formats, leaving wchar_t implementation-defined. The ISO\/IEC 10646:2003 Unicode standard 4.0 says that:\u00a0 &#8220;The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.&#8221;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Identifiers<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">An <em>identifier<\/em> is the user-defined name of a program element. In C++ identifier provides names for the following language elements:<\/p>\n<p>&nbsp;<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Functions<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Objects<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Labels<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Function parameters<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Macros and macro parameters<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Typedefs<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Enumerated types and enumerators<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Classes and class members<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Templates<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Template parameters<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 C++ Namespaces<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Struct and union names<\/p>\n<p style=\"text-align: justify\">An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9). In C++there is no limit on the length of the identifer , but implementers often impose one<\/p>\n<\/div>\n<div>\n<p><strong>Keywords<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><em>Keywords <\/em>are identifiers reserved by the language for special use. Following is the list of keywords common to both the C and C++.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-36 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/ss.png\" alt=\"\" width=\"851\" height=\"262\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/ss.png 851w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/ss-300x92.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/ss-768x236.png 768w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/ss-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/ss-225x69.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/ss-350x108.png 350w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/p>\n<p style=\"text-align: justify\">Only the exact spelling of keywords is reserved. For example, do is reserved but DO is not.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The C++ language also reserves the following keywords:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled.png\" alt=\"\" width=\"734\" height=\"321\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled.png 734w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-300x131.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-65x28.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-225x98.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-350x153.png 350w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 We will see their use in successive modules<\/span><strong>Data Types<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Data type define the way you store the values used by and created by the program. Defining a data type means defining what constants (generally in terms of range) a variable of that data type can store and what operations can be performed on that value.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Data type can be built in or abstract. A built in data type compiler intrinsically understand. It is predefined and known to the compiler. Therefore we don\u2019t need to define them , they are made available to us for use. As C++ is superset of C, most of the built in data types are inherited as is in C++, and they can be used as we use them in C. The basic scalar data type namely int, float and double along with their modifiers signed, unsigned, short and long can be used as we use them in C. Pointers in C++ also can be used the way we use them in C except few additions that we will discuss in next module.<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div>\n<p>Following is the complete list of fundamental data types in C++:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-38 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1.png\" alt=\"\" width=\"838\" height=\"798\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1.png 838w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1-300x286.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1-768x731.png 768w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1-65x62.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1-225x214.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-1-350x333.png 350w\" sizes=\"auto, (max-width: 838px) 100vw, 838px\" \/><\/p>\n<p><strong>New Data types in C++<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In addition to these built in data types inherited from C , another data type boolean was added to standard C++ . The keyword used for this data type is bool . The variables of bool data type can have two possible values \u2013 built in constants true (which converts to integer 1) and false ( which converts to integer 0 ).<\/p>\n<p>&nbsp;<\/p>\n<p>Example :<\/p>\n<p>&nbsp;<\/p>\n<p>bool found;<\/p>\n<p>&nbsp;<\/p>\n<p>It can be assigned two values<\/p>\n<p>&nbsp;<\/p>\n<p>found = true;<\/p>\n<p>Or<\/p>\n<p>&nbsp;<\/p>\n<p>found = false<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-39 aligncenter\" src=\"http:\/\/itp1.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2.png\" alt=\"\" width=\"882\" height=\"332\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2.png 882w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2-300x113.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2-768x289.png 768w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2-225x85.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-content\/uploads\/sites\/20\/2018\/07\/Untitled-2-350x132.png 350w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/p>\n<p><strong>Abstract Data type<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Also C++ allows us to create our own data type, which with careful crafting can be made to look and behave quite similar to standard data type. They are also denoted as Abstract Data type. We will discuss about abstract data type in detail in modules 5.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Variable Declaration in C++<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">C and C++ are block structured programming languages. Scope and lifetime of the variables are determined by the block in which it is defined. The only difference being, that in C variables can only be defined in the beginning of the block , whereas in C++ variables can be defined anywhere in the block with only one restriction that they should be defined before their first use. For example<\/p>\n<p>&nbsp;<\/p>\n<p>#include &lt;iostream&gt;<\/p>\n<p>Using namesapce std;<\/p>\n<p>void main(void)<\/p>\n<p>{<\/p>\n<table class=\"aligncenter\">\n<tbody>\n<tr>\n<td style=\"width: 104.063px\">int value1 ;<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">value1 = 10;<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026.<\/td>\n<td style=\"width: 306.063px\">\/\/\u00a0 some executable code here<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026.<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">int value2;<\/td>\n<td style=\"width: 306.063px\">\/\/\u00a0 this will not work in C but will work in C++<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">{<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">int value 3;<\/td>\n<td style=\"width: 306.063px\">\/\/\u00a0 this will work in C and C++ both<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026\u2026..<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">\u2026\u2026\u2026\u2026\u2026..\u2026<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">}<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\">}<\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 104.063px\"><\/td>\n<td style=\"width: 306.063px\"><\/td>\n<td style=\"width: 291.063px\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<p><strong>Storage Classes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Like C, C++ also has four storage classes namely auto, extern, register and static. Implementation of first three storage classes is similar to C. But static storage class has been extended in C++ for specific use with user defined data type. We will discuss this in detail in modules 6.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Operators in C++<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Being superset of C, C++ has inherited all the operators from C. Apart from these operators, C++ has added new operators as well.<\/p>\n<p>&nbsp;<\/p>\n<p>Here we will discuss following commonly used operators.<\/p>\n<p>&nbsp;<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Scope resolution<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 New<\/p>\n<p>\u00b7\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 delete<\/p>\n<p>&nbsp;<\/p>\n<p>Discussion of other operators will require knowledge of other C++ constructs. We will discuss them in later modules as appropriate.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Scope Resolution Operator ::<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>We know that in C &amp; C++. We can define the variables of the same name in different scope. For example have a look at the following program.<\/p>\n<p>&nbsp;<\/p>\n<p>int value = 10;<\/p>\n<p>&nbsp;<\/p>\n<p>void main(void)<\/p>\n<p>{<\/p>\n<p>int value = 20;<\/p>\n<p>&nbsp;<\/p>\n<p>cout &gt;&gt; value;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Which value will be displayed ?<\/p>\n<p style=\"text-align: justify\">Yes you are right. The variable in the innermost scope will prevail and therefore 20 will be displayed. This is logical enough. But what if we want the global value to be displayed ? The answer to this is scope resolution operator ::<\/p>\n<p>&nbsp;<\/p>\n<p>int value = 10;<\/p>\n<p>&nbsp;<\/p>\n<p>void main(void)<\/p>\n<p>{<\/p>\n<p>int value = 20;<\/p>\n<p>&nbsp;<\/p>\n<p>cout &gt;&gt; :: value;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>Here 10 will be displayed.<\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class. For example:<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>int value = 0;<\/p>\n<p>&nbsp;<\/p>\n<p>void main(void)<\/p>\n<p>{<\/p>\n<p>int value = 0;<\/p>\n<p>&nbsp;<\/p>\n<p>::\u00a0\u00a0 value = 1; \/\/ set global count to 1<\/p>\n<p>value = 2; \/\/ set local count to<\/p>\n<p>2 return 0;<\/p>\n<p>&nbsp;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The declaration of value declared in the main() function hides the integer named value declared in global namespace scope. The statement :: value = 1 accesses the variable named value declared in global namespace scope.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">You can also use the class scope operator to qualify class names or class member names. If a class member name is hidden, you can use it by qualifying it with its class name and the class scope operator. We will discuss this in later modules.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>New and Delete Operators<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We have used malloc(), calloc() , realloc() and free() functions for program controlled dynamic memory allocation and deallocation . These functions can be used in C++ as well, but apart from these functions C++ also provides operators new and delete for same.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>New Operator<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The syntax of new operator is as follows<\/p>\n<p>&nbsp;<\/p>\n<p>&lt;data type&gt;\u00a0 *ptr\u00a0\u00a0 = new &lt;data type&gt;<\/p>\n<p>For example<\/p>\n<p>int *iptr = new int;<\/p>\n<p style=\"text-align: justify\">will allocate no of bytes needed to store integer and address of the allocated memory will be returned which we can store in a pointer to integer variable.<\/p>\n<p>New operator can be used to allocate memory to scalar data type as well as\u00a0<span style=\"text-align: initial;font-size: 1em\">float<\/span><\/p>\n<\/div>\n<div>\n<p>float*fptr = new float ;<\/p>\n<p>char*cptr = new char ;<\/p>\n<\/div>\n<div>\n<p>We can initialize the allocated memory as follows<\/p>\n<p>&nbsp;<\/p>\n<p>int *iptr = new int(10);<\/p>\n<p>Here the memory allocated for integer will be initialized with value 10.<\/p>\n<\/div>\n<p>We can also get memory allocated for array as follows<\/p>\n<p>&nbsp;<\/p>\n<p>int *array = new int [25];<\/p>\n<p>this will allocate memory for 25 integers<\/p>\n<p>int\u00a0 *array = int[5][5];<\/p>\n<p>&nbsp;<\/p>\n<p>this will allocate memory for 5 *5 two dimensional array.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Delete operator<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Delete operator also has simple syntax<\/p>\n<p>delete p;<\/p>\n<p>this will release memory being ponted by pointer variable p.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The advantage of using new and delete operator over memory allocation function.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Use of new and delete operator is much more efficient and simple as compared to memory allocation functions<\/p>\n<ul>\n<li>Function calls have executional overhead due to context switching. No such overhead is there with operators.<\/li>\n<li>Syntax<span style=\"text-align: initial;font-size: 1em\"> of new and delete operators is simple as need not pass <\/span>size<span style=\"text-align: initial;font-size: 1em\"> of data type and no type casting is needed.<\/span><\/li>\n<li>Also new and delete can be overloaded to meet specific<span style=\"text-align: initial;font-size: 1em\"> need of the application.<\/span><\/li>\n<\/ul>\n<p><strong>Conditional Structures<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>All the control structures such as<\/p>\n<ul>\n<li>If and else<\/li>\n<li>switch case<\/li>\n<li>while loop<\/li>\n<li>do-while loop<\/li>\n<li>for loop<\/li>\n<\/ul>\n<p>Work the same way as in C<\/p>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on Overview of C++<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/4CB6iIqFfGs\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Additional References<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>1) Stanley Lippmann, \u201cC++ Primer\u201d, Pearson Education.<\/p>\n<p>2) Bjarne Stroustrup, \u201cThe C++ Programming Language\u201d, Pearson Education.<\/p>\n<p>3) Scott Mayer, \u201cEffective C++\u201d, Addison Wesley.<\/p>\n<p>4) Bhushan Trivedi , Programming with ANSI C++, 2\/e , Oxford University Press.<\/p>\n<p>5) Yashavant P. Kanetkar \u201cLet Us C++\u201d , Bpb Publications.<\/p>\n<p>6) Abhiram G. Ranade, \u201cAn Introduction to Programming through C++\u201d , McGraw Hill<\/p>\n<p>7) Ellis and B. Stroustrup \u201cAnnotated C++ Reference Manual\u201d, http:\/\/www.stroustrup.com\/arm.html<\/p>\n<p>8) Herbert Schildt, \u201cComplete Reference C++\u201d, McGraw Hill Publications.<\/p>\n<p>9) Ashok Kamthane, \u201cObject Oriented Programming with ANSI and Turbo C++\u201d, Pearson Education<\/p>\n<p>10) E Balaguruswami, \u201cObject Oriented Programming With C++\u201d, Tata McGraw Hill<\/p>\n<p>11) \u201cC++ FAQs\u201d, Pearson Education.<\/p>\n","protected":false},"author":4,"menu_order":3,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-jyoti-pareek"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-33","chapter","type-chapter","status-publish","hentry","contributor-dr-jyoti-pareek"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/chapters\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":12,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/chapters\/33\/revisions"}],"predecessor-version":[{"id":385,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/chapters\/33\/revisions\/385"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/chapters\/33\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/pressbooks\/v2\/chapter-type?post=33"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/wp\/v2\/contributor?post=33"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp1\/wp-json\/wp\/v2\/license?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}