tag:blogger.com,1999:blog-10331489576992922422024-03-27T16:53:28.625-07:00C++Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.comBlogger19125tag:blogger.com,1999:blog-1033148957699292242.post-37609722913301848912020-06-05T03:30:00.002-07:002020-06-05T03:30:37.100-07:00Directory implementation<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">The
selection of directory-allocation and directory-management algorithms
significantly affects the efficiency, performance, and reliability of the file
system. In this section, we discuss the trade-offs involved in choosing one of
these algorithms.</span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman"; mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1025" type="#_x0000_t75"
alt="Directory Implementation" style='width:541.5pt;height:423pt;visibility:visible;
mso-wrap-style:square'>
<v:imagedata src="file:///C:/Users/LENOVO/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png"
o:title="Directory Implementation"/>
</v:shape><![endif]--><!--[if !vml]--><img alt="Directory Implementation" height="564" src="file:///C:/Users/LENOVO/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png" v:shapes="Picture_x0020_1" width="722" /><!--[endif]--></span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<br /></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<b><span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Linear
List<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">The
simplest method of implementing a directory is to use a linear list of file
names with pointers to the data blocks. This method is simple to program but
time-consuming to execute. To create a new file., we must first search the
directory to be sure that no existing file has the same name. Then, we add a
new entry at the end of the directory. To delete a file, we search the
directory for the named file, then release the space allocated to it.</span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">To reuse
the directory entry, we can do one of several things. We can mark the entry as
unused (by assigning it a special name, such as an all-blank name, or with a
used-unused, bit in each entry), or we can attach it to a list of free
directory entries. A third alternative is to copy the last entry in the
directory into the freed location and to decrease the length of the directory.
A linked list can also be used to decrease the time required to delete a file.</span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">The real
disadvantage of a linear list of directory entries is that finding a file
requires a linear search. Directory information is used frequently, and users
will notice if access to it is slow. In fact, many operating systems implement
a software cache to store the most recently used directory information. A cache
hit avoids the need to constantly reread the information from disk. A sorted
list allows a binary search and decreases the average search time.</span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">However,
the requirement that the list be kept sorted may complicate creating and
deleting files, since we may have to move substantial amounts of directory
information to maintain a sorted directory. A more sophisticated tree data
structure, such as a B-tree, might help here. An advantage of the sorted list
is that a sorted directory listing can be produced without a separate sort
step.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<b><span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><span style="mso-spacerun: yes;"> </span>Hash Table</span></b><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Another
data structure used for a file directory is a hash table. With this method, a
linear list stores the directory entries, but a hash data structure is also
used. The hash table takes a value computed from the file name and returns a
pointer to the file name in the linear list. Therefore, it can greatly decrease
the directory search time. Insertion and deletion are also fairly
straightforward, although some provision must be made for collisions—situations
in which two file names hash to the same location.</span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: 7.2pt; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0cm; text-align: justify;">
<span style="color: black; font-family: "Verdana",sans-serif; font-size: 15.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">The major
difficulties with a hash table are its generally fixed size and the dependence
of the hash function on that size. For example, assume that we make a
linear-probing hash table that holds 64 entries. The hash function converts
file names into integers from 0 to 63, for instance, by using the remainder of
a division by 64. If we later try to create a 65th file, we must enlarge the
directory hash table—say, to 128 entries. As a result, we need a new hash
function that must map file names to the range 0 to 127, and we must reorganize
the existing directory entries to reflect their new hash-function values.
Alternatively, a chained-overflow hash table can be used. Each hash entry can
be a linked list instead of an individual value, and we can resolve collisions
by adding the new entry to the linked list. Lookups may be somewhat slowed,
because searching for a name might require stepping through a linked list of
colliding table entries. Still, this method is likely to be much faster than a
linear search through the entire directory.</span><span style="color: black; font-family: "Verdana",sans-serif; font-size: 12.0pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br /></div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-71331662251313268712019-07-20T06:07:00.002-07:002019-07-20T06:11:35.845-07:00binary files<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi5aL9ZRugec-_gFjDDU20jUffvEPS4Zz11DXEan3wS1e5QOI66OePCnmkBtiYuZm0cO2aKBxtRDVlIlCSANwdciSxnD4612nsjHRnAH2qbfYAZa4ODTKYQNTV_KHPPwR0x5zKgcIyP7I/s1600/p4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi5aL9ZRugec-_gFjDDU20jUffvEPS4Zz11DXEan3wS1e5QOI66OePCnmkBtiYuZm0cO2aKBxtRDVlIlCSANwdciSxnD4612nsjHRnAH2qbfYAZa4ODTKYQNTV_KHPPwR0x5zKgcIyP7I/s320/p4.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqmrimWZ550QSu2iGjtiQMgyhWJT-v5JLl2RG6LnodwZjE8cZhujmbP-_5R2W1B5g0VOUuVtTUgHU7ZR5r4X5i_kR72Z-yMW-s39VaqlZTZ2cXi-uqPHNZoOG14fCr3iglJPSjEsB9v4k/s1600/p5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqmrimWZ550QSu2iGjtiQMgyhWJT-v5JLl2RG6LnodwZjE8cZhujmbP-_5R2W1B5g0VOUuVtTUgHU7ZR5r4X5i_kR72Z-yMW-s39VaqlZTZ2cXi-uqPHNZoOG14fCr3iglJPSjEsB9v4k/s320/p5.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbuQvFIMiRpTCFdmuKioaU_7wKA_n54q0fP3RdsjeCq3QFEz9jPOGWoCXKBBPed2iS8fChzPA820OYdFa4HjJhChVk5Os25HufhjH5pOv6dy1hZNeIM63VL0hyphenhyphenUBzhQzrQ3aiPC5c8G_c/s1600/p6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbuQvFIMiRpTCFdmuKioaU_7wKA_n54q0fP3RdsjeCq3QFEz9jPOGWoCXKBBPed2iS8fChzPA820OYdFa4HjJhChVk5Os25HufhjH5pOv6dy1hZNeIM63VL0hyphenhyphenUBzhQzrQ3aiPC5c8G_c/s320/p6.jpg" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7sInenWvz4c0y5UW443OWJL-868Dru7wy1Kx5R5-v27FTPwmeQF8ndrN81anAmqLujSV0oHWzqjroXjGGLspBNz0hkVBX_t_G0z4wdzQv2uzS-Cz_xIEMw1QMDgEn8ldtTO286l-CG8s/s1600/p7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7sInenWvz4c0y5UW443OWJL-868Dru7wy1Kx5R5-v27FTPwmeQF8ndrN81anAmqLujSV0oHWzqjroXjGGLspBNz0hkVBX_t_G0z4wdzQv2uzS-Cz_xIEMw1QMDgEn8ldtTO286l-CG8s/s320/p7.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXGLNJrOvTYuvoPZzL-hPUTCoGknoOn43aNha0p5bIPIyLGJia_7uQFrUhuZl8YltXYQRqWE2qi1AEOMGs35LavmuHx9ECeqYxiVguLaKMmfmQcHI5i9RQA6XrWn5P9GmasVXDPp5g8GU/s1600/p8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXGLNJrOvTYuvoPZzL-hPUTCoGknoOn43aNha0p5bIPIyLGJia_7uQFrUhuZl8YltXYQRqWE2qi1AEOMGs35LavmuHx9ECeqYxiVguLaKMmfmQcHI5i9RQA6XrWn5P9GmasVXDPp5g8GU/s320/p8.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmUnjq_3VuJb_AZUMoygxn8gxIZ3e_q-2vm7cvKgk4HkL75plC8DD8F4h_j3NyZVU4lLqvTSr4gcXbWQjYS6fVvBMMfjrwVIcQFPY5ahzwOvfgk8oNKxBpvXNvpRKaVGT6f8Fe9S5wO1U/s1600/p9.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmUnjq_3VuJb_AZUMoygxn8gxIZ3e_q-2vm7cvKgk4HkL75plC8DD8F4h_j3NyZVU4lLqvTSr4gcXbWQjYS6fVvBMMfjrwVIcQFPY5ahzwOvfgk8oNKxBpvXNvpRKaVGT6f8Fe9S5wO1U/s320/p9.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVB0WpdyGkhUzOBhfXfJT6zeW_CPtECaRtjksdNCymCcD8dvoMERLnupZEHOPCtjd9h0KqB0CSg8QCk4HilNRr3i9G8v7j0WO-S38qST8QpiYZ3jWrGhhPQzvSLzEnkyntshZ1aNngG_o/s1600/p10.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVB0WpdyGkhUzOBhfXfJT6zeW_CPtECaRtjksdNCymCcD8dvoMERLnupZEHOPCtjd9h0KqB0CSg8QCk4HilNRr3i9G8v7j0WO-S38qST8QpiYZ3jWrGhhPQzvSLzEnkyntshZ1aNngG_o/s320/p10.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_U927TctX8G872iziQlGt4yT85VFXIxvexO-1czwEYwPcGaiN3yDzQokMluW8nfKRbLFYnjBsgWwpmLM6sdL3nNS7Ri0GNh_n9P_YlAv0KHQWZkaPF1tdVSwYF1SePyE_WAz8QMvE5GA/s1600/p1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_U927TctX8G872iziQlGt4yT85VFXIxvexO-1czwEYwPcGaiN3yDzQokMluW8nfKRbLFYnjBsgWwpmLM6sdL3nNS7Ri0GNh_n9P_YlAv0KHQWZkaPF1tdVSwYF1SePyE_WAz8QMvE5GA/s320/p1.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisIf90vS1e3i1Pl61e_DwMAXUAEdadvqkvZX7gE25B6af3Hq8R86kSHa_w5C80bXFCXrO4OuK8NFO4ybsXLhNCKxx6Xa2IVMHmxlbEcY3szgPjUjt9LcdZib5Rau2lsx_0NCRk0KmVzc4/s1600/p2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisIf90vS1e3i1Pl61e_DwMAXUAEdadvqkvZX7gE25B6af3Hq8R86kSHa_w5C80bXFCXrO4OuK8NFO4ybsXLhNCKxx6Xa2IVMHmxlbEcY3szgPjUjt9LcdZib5Rau2lsx_0NCRk0KmVzc4/s320/p2.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj87hGAfXKniLoNN5hAjRJjZx_9qmAQbAcCIDWgKpv_j3HBQYwHei9Fzc7RNX07_gduh2nRsDncF8Brfz3zIx4_qWeWXoxr2I6b5JfG4P_D1KivFgH9JZcKv7EuPc24p4cMnERSt4VSBng/s1600/p3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="179" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj87hGAfXKniLoNN5hAjRJjZx_9qmAQbAcCIDWgKpv_j3HBQYwHei9Fzc7RNX07_gduh2nRsDncF8Brfz3zIx4_qWeWXoxr2I6b5JfG4P_D1KivFgH9JZcKv7EuPc24p4cMnERSt4VSBng/s320/p3.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br /></div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com1tag:blogger.com,1999:blog-1033148957699292242.post-61636216082742600072019-06-27T09:21:00.002-07:002019-06-27T09:21:56.414-07:00library function programe<div dir="ltr" style="text-align: left;" trbidi="on">
<ol class="linenums" style="-webkit-font-smoothing: antialiased; background: rgb(246, 246, 246); border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgba(208, 211, 210, 0.8); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; color: #888888; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14px; line-height: 1.15 !important; margin: 0px 0px 0px 21px; min-width: 0px; outline: 0px; padding: 15px 0px 15px 6px; vertical-align: baseline; white-space: pre; word-spacing: 3px;">
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><iostream></span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cmath></span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">namespace</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> std</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> main</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">()</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">double</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> x </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">10.25</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> sqrt</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">x</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"Square root of "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> x </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">" is "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> endl</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
</ol>
<div>
<span style="font-family: Menlo, Consolas, Open Sans, sans-serif;"><span style="font-size: 13.9px; white-space: pre; word-spacing: 3px;"><br /></span></span></div>
<div>
<span style="background-color: white; color: #9999aa; font-family: "Open Sans", sans-serif; font-size: 16px; font-weight: 600; word-spacing: 3.5px;">The pow() function computes a base number raised to the power of exponent number.</span></div>
<div>
<span style="background-color: white; color: #9999aa; font-family: "Open Sans", sans-serif; font-size: 16px; font-weight: 600; word-spacing: 3.5px;"><br /></span></div>
<div>
<pre class="prettyprint linenums prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 14px; line-height: 1.5; margin-bottom: 10px; max-height: 600px; min-width: 0px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-spacing: 3px;"><ol class="linenums" style="-webkit-font-smoothing: antialiased; background: rgb(246, 246, 246); border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgba(208, 211, 210, 0.8); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; color: #888888; line-height: 1.15 !important; margin: 0px 0px 0px 21px; min-width: 0px; outline: 0px; padding: 15px 0px 15px 6px; vertical-align: baseline;">
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><iostream></span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cmath></span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">namespace</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> std</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> main </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">()</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">long</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">double</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">base</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">4.4</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> exponent </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">3</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> pow</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">base</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> exponent</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">base</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"^"</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> exponent </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">" = "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> endl</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">// Both arguments int</span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">// pow() returns double in this case</span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> intBase </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">4</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> intExponent </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">6</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">double</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> answer</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> answer </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> pow</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">intBase</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> intExponent</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> intBase </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"^"</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> intExponent </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">" = "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> answer</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
</ol>
</pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; border: 0px; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; line-height: inherit; margin-bottom: 1.5em; margin-top: 1.5em; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-spacing: 3px;">
When you run the program, the output will be:</div>
<pre style="background: rgb(239, 239, 241); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline; word-spacing: 3px;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">4.4^-3 = 0.0117393
-4^6 = 4096 </samp></pre>
<pre style="background: rgb(239, 239, 241); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline; word-spacing: 3px;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The abs() function in C++ returns the absolute value of the argument.</samp></pre>
<pre style="background: rgb(239, 239, 241); border: 1px solid rgb(234, 234, 236); line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline; word-spacing: 3px;"><samp style="background: none !important; border: 0px; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><pre class="prettyprint linenums prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.5; margin-bottom: 10px; max-height: 600px; min-width: 0px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><ol class="linenums" style="-webkit-font-smoothing: antialiased; background: rgb(246, 246, 246); border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgba(208, 211, 210, 0.8); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; color: #888888; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 14px; line-height: 1.15 !important; margin: 0px 0px 0px 21px; min-width: 0px; outline: 0px; padding: 15px 0px 15px 6px; vertical-align: baseline;">
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><iostream></span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cmath></span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">namespace</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> std</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> main</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">()</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">double</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> x </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">87.91</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> abs</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">x</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"abs("</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> x </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">") = |"</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> x </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"| = "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> result </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> endl</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
</ol>
<div>
<span style="font-family: Menlo, Consolas, Open Sans, sans-serif;"><span style="font-size: 13.9px;">
</span></span></div>
<div>
<span style="font-family: Menlo, Consolas, Open Sans, sans-serif;"><span style="font-size: 13.9px;">
</span></span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">
</span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">
</span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">
</span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">
</span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">
</span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">
</span></div>
<div>
<span style="background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; white-space: normal;">When you run the program, the output will be:</span></div>
</pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">abs(-87.91) = |-87.91| = 87.91</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The strlen() function in C++ returns the length of the given string.</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><pre class="prettyprint linenums prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; line-height: 1.5; margin-bottom: 10px; max-height: 600px; min-width: 0px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><ol class="linenums" style="-webkit-font-smoothing: antialiased; background: rgb(246, 246, 246); border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgba(208, 211, 210, 0.8); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; color: #888888; line-height: 1.15 !important; margin: 0px 0px 0px 21px; min-width: 0px; outline: 0px; padding: 15px 0px 15px 6px; vertical-align: baseline;">
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cstring></span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><iostream></span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">namespace</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> std</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> main</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">()</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str1</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"This a string"</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str2</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"This is another string"</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> len1 </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> strlen</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">str1</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> len2 </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> strlen</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">str2</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"Length of str1 = "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> len1 </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> endl</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"Length of str2 = "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> len2 </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> endl</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">if</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">len1 </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">></span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> len2</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">)</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"str1 is longer than str2"</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">else</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">if</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">len1 </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> len2</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">)</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"str2 is longer than str1"</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">else</span></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"str1 and str2 are of equal length"</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
</ol>
</pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; border: 0px; font-family: "Open Sans", sans-serif; font-size: 16px; line-height: inherit; margin-bottom: 1.5em; margin-top: 1.5em; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;">
When you run the program, the output will be:</div>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Length of str1 = 13
Length of str2 = 22
str2 is longer than str1</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The toupper() function in C++ converts a given character to uppercase.</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><pre class="prettyprint linenums prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; line-height: 1.5; margin-bottom: 10px; max-height: 600px; min-width: 0px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><ol class="linenums" style="-webkit-font-smoothing: antialiased; background: rgb(246, 246, 246); border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgba(208, 211, 210, 0.8); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; color: #888888; line-height: 1.15 !important; margin: 0px 0px 0px 21px; min-width: 0px; outline: 0px; padding: 15px 0px 15px 6px; vertical-align: baseline;">
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cctype></span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><iostream></span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cstring></span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cstdio></span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">namespace</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> std</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> main</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">()</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"John is from USA."</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"The uppercase version of \""</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"\" is "</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> endl</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">for</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">strlen</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">++)</span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> putchar</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">toupper</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">]));</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
</ol>
</pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; border: 0px; font-family: "Open Sans", sans-serif; font-size: 16px; line-height: inherit; margin-bottom: 1.5em; margin-top: 1.5em; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;">
When you run the program, the output will be:</div>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The uppercase version of "John is from USA." is
JOHN IS FROM USA.</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The isupper() function in C++ checks if the given character is a uppercase character or not.</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><pre class="prettyprint linenums prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; line-height: 1.5; margin-bottom: 10px; max-height: 600px; min-width: 0px; outline: 0px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><ol class="linenums" style="-webkit-font-smoothing: antialiased; background: rgb(246, 246, 246); border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgba(208, 211, 210, 0.8); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; color: #888888; line-height: 1.15 !important; margin: 0px 0px 0px 21px; min-width: 0px; outline: 0px; padding: 15px 0px 15px 6px; vertical-align: baseline;">
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cctype></span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><iostream></span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">#include</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><cstring></span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">namespace</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> std</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> main</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">()</span></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="str" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">"This Program Converts ALL UPPERCASE Characters to LOWERCASE"</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L0" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">for</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">int</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">strlen</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">++)</span></code></li>
<li class="L1" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">{</span></code></li>
<li class="L2" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">if</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">isupper</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">]))</span></code></li>
<li class="L3" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="com" style="border: 0px; color: grey; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">/* Converting uppercase characters to lowercase */</span></code></li>
<li class="L4" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">]</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">i</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">]</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">+</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">32</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L5" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
<li class="L6" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"></code></li>
<li class="L7" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> cout </span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><<</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> str</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L8" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="border: 0px; color: darkblue; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="border: 0px; color: maroon; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">;</span></code></li>
<li class="L9" style="border: 0px; font-size: 13px; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><code style="background: rgb(239, 240, 241); border-radius: 2px; border: 0px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 13.9px; line-height: 1.4; margin: 0px; min-width: 0px; outline: 0px; padding: 1px 5px; vertical-align: baseline;"><span class="pun" style="border: 0px; color: black; line-height: inherit; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">}</span></code></li>
</ol>
</pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; border: 0px; font-family: "Open Sans", sans-serif; font-size: 16px; line-height: inherit; margin-bottom: 1.5em; margin-top: 1.5em; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline; white-space: normal;">
When you run the program, the output will be:</div>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">this program converts all uppercase characters to lowercase</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</samp></pre>
</samp></pre>
</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</samp></pre>
<pre style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; line-height: 1.5; margin-bottom: 1.8em; margin-top: -0.8em; min-width: 0px; outline: 0px; overflow: auto; padding: 15px 18.5px; vertical-align: baseline;"><samp style="background: none !important; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; line-height: 1.5; margin: 0px; min-width: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
</samp></pre>
</samp></pre>
</samp></pre>
</div>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-81723202416304862019-06-27T05:50:00.000-07:002019-06-28T09:37:53.163-07:00programe<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #343a40; font-family: "muli" , , "blinkmacsystemfont" , "segoe ui" , "roboto" , "helvetica neue" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji" , "segoe ui symbol" , "noto color emoji"; font-size: 18.4px;">Write a C++ program to write number 1 to 100 in a data file NOTES.TXT.</span><br />
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 14px; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; white-space: pre-wrap; width: auto;">#include <iostream></pre>
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; width: auto;"><code style="box-sizing: border-box; word-break: normal;"><span class="pln" style="box-sizing: border-box; font-size: 14px; white-space: pre-wrap;">#include <conio.h>
#include <fstream>
using namespace std;
int main()
{
ofstream fout;
fout.open("KAT.TXT");
for(int i=1;i<=100;i++)
fout<<i<<endl;
fout.close();
return 0;
} </span></code></pre>
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; width: auto;"><code style="box-sizing: border-box; word-break: normal;"><span class="pln" style="box-sizing: border-box; font-size: 14px; white-space: pre-wrap;">simple program to write in text file </span></code></pre>
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; width: auto;"><code style="box-sizing: border-box; word-break: normal;"><span class="pln" style="box-sizing: border-box; font-size: 14px; white-space: pre-wrap;">#include <iostream>
#include <fstream> // std::fstream
using namespace std;
int main () {
fstream fs;
fs.open ("test.txt");
fs << " this line will store in test.txt file and we can display it on console";
fs.close();
return 0;
}
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; width: auto;"><code style="box-sizing: border-box; word-break: normal;"><span class="pln" style="box-sizing: border-box; font-size: 14px; white-space: pre-wrap;">#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;// read program from all what store in KA1T.TXT file
int main()
{
char ch;
string line;
ifstream fin;
fin.open("KA1T.TXT");
while (fin) {
getline(fin, line);
cout << line << endl;
}
fin.close();
return 0;
} </span></code></pre>
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; width: auto;"><span style="font-size: inherit; white-space: pre-wrap;">Write a C++ program, which initializes a string variable to the content "Time is a great teacher but unfortunately it kills all its pupils. Berlioz" and outputs the string to the disk file OUT.TXT. you have to include all the header files if required.</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: white; border: 1px solid rgb(136, 136, 136); box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 14px; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; white-space: pre-wrap; width: auto;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pln" style="box-sizing: border-box; color: black;"><pre class="prettyprint prettyprinted" style="border: 1px solid rgb(136, 136, 136); box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; white-space: pre-wrap; width: auto;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="com" style="box-sizing: border-box; color: #880000;">#include</span><span class="str" style="box-sizing: border-box; color: #008800;"><fstream.h></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> main</span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
ofstream fout</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fout</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">open</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="str" style="box-sizing: border-box; color: #008800;">"out.txt"</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">char</span><span class="pln" style="box-sizing: border-box; color: black;"> str</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="lit" style="box-sizing: border-box; color: #006666;">300</span><span class="pun" style="box-sizing: border-box; color: #666600;">]=</span><span class="str" style="box-sizing: border-box; color: #008800;">"Time is a great teacher but unfortunately it kills
all its pupils. Berlioz"</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fout</span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">str</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fout</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">close</span><span class="pun" style="box-sizing: border-box; color: #666600;">();</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
</span></code></pre>
<div>
<span style="color: #343a40; font-size: 18.4px; white-space: normal;">Write a user-defined function in C++ to read the content from a text file OUT.TXT, count and display the number of alphabets present in it.</span></div>
<div>
<code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;"></span></code>
<br />
<pre class="prettyprint prettyprinted" style="border: 1px solid rgb(136, 136, 136); box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; white-space: pre-wrap; width: auto;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="kwd" style="box-sizing: border-box; color: #000088;">void</span><span class="pln" style="box-sizing: border-box; color: black;"> alphabets</span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
ifstream fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">open</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="str" style="box-sizing: border-box; color: #008800;">"out.txt"</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">char</span><span class="pln" style="box-sizing: border-box; color: black;"> ch</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> count</span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">while</span><span class="pun" style="box-sizing: border-box; color: #666600;">(!</span><span class="pln" style="box-sizing: border-box; color: black;">fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">eof</span><span class="pun" style="box-sizing: border-box; color: #666600;">())</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="kwd" style="box-sizing: border-box; color: #000088;">get</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box; color: black;">ch</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">if</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box; color: black;">isalpha</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box; color: black;">ch</span><span class="pun" style="box-sizing: border-box; color: #666600;">))</span><span class="pln" style="box-sizing: border-box; color: black;">
count</span><span class="pun" style="box-sizing: border-box; color: #666600;">++;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="str" style="box-sizing: border-box; color: #008800;">"Number of alphabets in file are "</span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">count</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">close</span><span class="pun" style="box-sizing: border-box; color: #666600;">();</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
</span></code></span></code></pre>
<code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;"><span style="color: #343a40; font-family: "muli" , , "blinkmacsystemfont" , "segoe ui" , "roboto" , "helvetica neue" , "arial" , sans-serif , "apple color emoji" , "segoe ui emoji" , "segoe ui symbol" , "noto color emoji"; font-size: 18.4px; white-space: normal;">Write a function to count the number of blank present in a text file named "OUT.TXT"</span>
</span></code></div>
<div>
<code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;"></span></code>
<br />
<pre class="prettyprint prettyprinted" style="border: 1px solid rgb(136, 136, 136); box-sizing: border-box; color: #212529; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; margin-bottom: 1rem; overflow-wrap: normal; overflow: auto; padding: 2px; white-space: pre-wrap; width: auto;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="kwd" style="box-sizing: border-box; color: #000088;">void</span><span class="pln" style="box-sizing: border-box; color: black;"> blankspace</span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
ifstream fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">open</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="str" style="box-sizing: border-box; color: #008800;">"out.txt"</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">char</span><span class="pln" style="box-sizing: border-box; color: black;"> ch</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> count</span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">while</span><span class="pun" style="box-sizing: border-box; color: #666600;">(!</span><span class="pln" style="box-sizing: border-box; color: black;">fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">eof</span><span class="pun" style="box-sizing: border-box; color: #666600;">())</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="kwd" style="box-sizing: border-box; color: #000088;">get</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box; color: black;">ch</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">if</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box; color: black;">ch</span><span class="pun" style="box-sizing: border-box; color: #666600;">==</span><span class="str" style="box-sizing: border-box; color: #008800;">' '</span><span class="pun" style="box-sizing: border-box; color: #666600;">)</span><span class="pln" style="box-sizing: border-box; color: black;">
count</span><span class="pun" style="box-sizing: border-box; color: #666600;">++;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="str" style="box-sizing: border-box; color: #008800;">"Number of blank spaces in file are "</span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">count</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
fin</span><span class="pun" style="box-sizing: border-box; color: #666600;">.</span><span class="pln" style="box-sizing: border-box; color: black;">close</span><span class="pun" style="box-sizing: border-box; color: #666600;">();</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
</span></code></span></code></pre>
<code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;">
</span></code>
<br />
<div>
<code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;"><code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;">
</span></code></span></code></div>
<code style="box-sizing: border-box; color: inherit; font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: inherit; word-break: normal;"><span class="pun" style="box-sizing: border-box; color: #666600;">
</span></code></div>
</span></code></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-4895020193500317992019-06-27T05:15:00.002-07:002019-06-27T05:15:21.230-07:00Detailed Differences between C and C++ <div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; color: rgba(0, 0, 0, 0.84); font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.71429; margin-bottom: 10px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Detailed Differences between C and C++ are:</strong></div>
<table style="background-color: white; border-bottom-color: rgb(237, 237, 237); border-bottom-style: solid; border-collapse: collapse; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-spacing: 0px; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; color: rgba(0, 0, 0, 0.84); font-family: Roboto, sans-serif; font-size: 12px; line-height: 2; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; width: 100%px;"><thead style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><th style="background: rgb(15, 157, 88); border: 0px; color: black; font-size: 11px; line-height: 2.18182; margin: 0px; padding: 8px; text-align: center; text-transform: uppercase; vertical-align: baseline;">C</th><th style="background: rgb(15, 157, 88); border: 0px; color: black; font-size: 11px; line-height: 2.18182; margin: 0px; padding: 8px; text-align: center; text-transform: uppercase; vertical-align: baseline;">C++</th></tr>
</thead><tbody style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C was developed by Dennis Ritchie between the year 1969 and 1973 at AT&T Bell Labs.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ was developed by Bjarne Stroustrup in 1979.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C does no support polymorphism, encapsulation, and inheritance which means that C does not support object oriented programming.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ supports polymorphism, encapsulation, and inheritance because it is an object oriented programming language.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C is a subset of C++.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ is a superset of C. C codes can be run by C++ but C cannot run the C++ codes.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C contains 32 keywords.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ contains 52 keywords.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">For the development of code, C supports procedural programming.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ is known as hybrid language because C++ supports both procedural and object oriented programming paradigms.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Data and functions are separated in C because it is a procedural programming language.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Data and functions are encapsulated together in form of an object in C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C does not support information hiding.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Data is hidden by the Encapsulation to ensure that data structures and operators are used as intended.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Built-in data types is supported in C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Built-in & user-defined data types is supported in C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C is a function driven language because C is a procedural programming language.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ is an object driven language because it is an object oriented programming.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Function and operator overloading is not supported in C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Function and operator overloading is supported by C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C is a function-driven language.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ is an object-driven language</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Functions in C are not defined inside structures.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Functions can be used inside a structure in C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Namespace features are not present inside the C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">NAMESPACE is used by C++, which avoid name collisions.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Header file used by C is stdio.h.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Header file used by C++ is iostream.h.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Reference variables are not supported by C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Reference variables are supported by C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Virtual and friend functions are not supported by C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Virtual and friend functions are supported by C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C does not support inheritance.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ supports inheritance.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Instead of focusing on data, C focuses on method or process.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ focuses on data instead of focusing on method or procedure.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C provides malloc() and calloc()functions for dynamic memory allocation, and free() for memory de-allocation.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">C++ provides new operator for memory allocation and delete operator for memory de-allocation.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Direct support for exception handling is not supported by C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Exception handling is supported by C++.</td></tr>
<tr style="border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">scanf and printf functions are used for input/output in C.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">cin and cout are used for input/output in C++.</td></tr>
</tbody></table>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-20126495287414440202019-06-21T07:59:00.001-07:002019-07-09T10:03:04.668-07:00File Handling through C++ Classes<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">A stream is a name given to a flow of data at the lowest level.
At the lowest level, data is just the binary data without any notion of data
type. Different streams are used to represent the different kinds of data flow
such as whether data is flowing into the memory or out of the memory.<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">Each
stream is associated with a particular class, that contains the member functions and
definitions for dealing with that particular kind of data flow. For instance,
the ifstream class represents the input disk files.<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">The
stream that supplies data to the program is known as the input stream. It reads
the data from the file and hands it over to the program. The stream that
receives data from the program is known as output stream. It writes the
received data to the file.<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">The file
I/O system of C++ contains a set of classes that define the file handling
methods. These classes, designed to manage the disk files, are declared in the
header file named fstream.h. Therefore, we must include this file in a program
that works with files. The classes defined inside the header file, fstream.h,
derive from the classes under the header file iostream.h, the header file that
manages console I/O operations.<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">Therefore,
if you include the header file fstream.h in your <a href="https://codescracker.com/cpp/cpp-data-file-handling.htm"><span style="color: #0088cc;">file handling</span></a> programs, you need not to
include iostream.h header file as classes of fstream.h inherit from iostream.h
only.<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">The
function of these classes have been summarized in the following table :<o:p></o:p></span></div>
<table border="1" cellpadding="0" class="MsoNormalTable" style="border: solid teal 1.0pt; mso-border-alt: solid teal .75pt; mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184; width: 713px;">
<tbody>
<tr style="height: 25.35pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background: teal; border: none; height: 25.35pt; padding: 7.5pt 7.5pt 7.5pt 7.5pt;"><div class="MsoNormal">
<b><span style="color: white;">Class .................................</span></b><b><span style="color: white; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></b></div>
</td>
<td style="background: teal; border: none; height: 25.35pt; padding: 7.5pt 7.5pt 7.5pt 7.5pt;"><div class="MsoNormal">
<b><span style="color: white;">Functions</span></b><b><span style="color: white; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></b></div>
</td>
</tr>
<tr style="height: 25.35pt; mso-yfti-irow: 1;">
<td style="background: whitesmoke; border: none; height: 25.35pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">filebuf </span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 25.35pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">It sets the file buffers to
read and write. It contains close() and open() member functions to it</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 40.25pt; mso-yfti-irow: 2;">
<td style="background: mintcream; border: none; height: 40.25pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">fstreambase </span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 40.25pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">This is the base class for
fstream, ifstream and ofstream classes. Therefore, it provides operations
common to these file streams. It also contains the functions open() and
close()</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 55.9pt; mso-yfti-irow: 3;">
<td style="background: whitesmoke; border: none; height: 55.9pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">ifstream </span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span><br />
<span style="color: #333333;"><br /></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 55.9pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">Being an input file stream
class, it provides the input operations for file. It inherits the functions
get(), getline(), read() and functions supporting random access ( seekg() and tellg() ) from istream class defined inside the header file iostream.h</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 56.6pt; mso-yfti-irow: 4;">
<td style="background: mintcream; border: none; height: 56.6pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">ofstream</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 56.6pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">Being an output file stream
class, it provides the output operations. It inherits the functions put() and
write() along with functions supporting random access ( seekp() and tellp() )
from ostream class defined inside the header file iostream.h</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 55.9pt; mso-yfti-irow: 5; mso-yfti-lastrow: yes;">
<td style="background: whitesmoke; border: none; height: 55.9pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">fstream</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 55.9pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal">
<span style="color: #333333;">It is an input-output file
stream class. It provides support for the simultaneous input and output
operations. It inherits all the functions from istream and ostream classes
through the iostream class defined inside the header file iostream.h</span><span style="color: #333333; font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<h2 style="background: white;">
<div style="text-align: left;">
<span style="color: #454545; font-family: inherit; font-size: small; mso-bidi-font-family: Arial;">#</span><span style="color: #333333; font-weight: normal;"><span style="font-family: inherit;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: small;">include <iostream><br />
#include <conio.h><br />
<br />
#include <fstream><br />
<br />
using namespace std;<br />
<br />
int main()<br />
<br />
{<br />
<br />
ofstream fout;<br />
<br />
string line;<br />
<br />
fout.open("sample.txt");<br />
<br />
fout << line << endl;<br />
<br />
fout.close();<br />
<br />
return 0;<br />
<br />
}</span>
</span>
<!--[if !supportLineBreakNewLine]--><br /><br /><br /><br /><br />
<!--[endif]--><span style="font-family: "helvetica" , sans-serif; font-size: 12pt;"><o:p></o:p></span></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
#include <conio.h></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
#include <fstream></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
using namespace std;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
int main()</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
{</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
ofstream fout;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
string line;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
fout.open("sample.txt");</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
fout << line << endl;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
fout.close();</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
return 0;</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
}</span><span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;"><br /></span></div>
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt; font-weight: normal;">
<!--[if !supportLineBreakNewLine]--><br />
<!--[endif]--><o:p></o:p></span></h2>
<h2 style="background: white;">
<span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;"> </span></h2>
<h2 style="background: white;">
<span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">C++ File Streams Example<o:p></o:p></span></h2>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">Here is a
simple example program related to C++ file stream. This programs only ask to
enter the file name and then to enter a line to store the line in this file.<o:p></o:p></span></div>
<pre style="background: white;"><span style="color: #333333;">/* C++ File Streams */<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<conio.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<fstream.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<stdlib.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">void main()<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">{<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> char inform[80];<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> char fname[20];<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> char ch;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> clrscr();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Enter file name: ";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(fname, 20);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> ofstream fout(fname, ios::out);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> if(!fout)<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> {<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Error in creating the file..!!\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Press any key to exit...\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> getch();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> exit(1);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> }<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(ch);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Enter a line to store in the file:\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(inform, 80);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> fout<<inform<<"\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\nEntered informations successfully stored..!!\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> fout.close();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Press any key to exit...\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> getch();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">}<o:p></o:p></span></pre>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">Here is
the sample run of the above C++ program:<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype id="_x0000_t75"
coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1026" type="#_x0000_t75"
alt="Description: c++ file streams" style='width:369.75pt;height:125.25pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\NADEEM\AppData\Local\Temp\msohtmlclip1\01\clip_image001.jpg"
o:title="c++ file streams"/>
</v:shape><![endif]--><!--[if !vml]--><img alt="Description: c++ file streams" border="0" height="167" src="file:///C:/Users/NADEEM/AppData/Local/Temp/msohtmlclip1/01/clip_image001.jpg" v:shapes="Picture_x0020_1" width="493" /><!--[endif]--></span><span style="color: #333333; font-family: "helvetica" , "sans-serif";"><o:p></o:p></span></div>
<h3 style="background: white;">
<span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;"> </span></h3>
<h3 style="background: white;">
<span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;"> </span></h3>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<b><span style="color: red; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">TEXT and Binary Files:<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Files are required to store any information
permanently, for later use. The same holds for data files also.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">The data files are the files that store data
pertaining to a specific application, for later use. The data files can be
stored in the following two ways :<o:p></o:p></span></div>
<ol start="1" type="1">
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l4 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Text
files<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l4 level1 lfo1; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Binary
files<o:p></o:p></span></li>
</ol>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">Text file<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">A text file stores the information in ASCII
characters. In text files, each line of text is terminated or delimited with a
special character named EOF known as End of Line character.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">In text files, some internal translations take
place when this EOF character is read or written.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">Binary
file<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">A binary file is just a file that contains
information in the same format in which the information is held in memory.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">In binary file, there is no delimiter for a
line. Also no translations occur in binary file. As a result, binary files are
faster and easier for a program to read and write than are text files. As long
as the file doesn't need to be read by people or need to be ported to a
different type of system, binary files are the best way to store program
information.<o:p></o:p></span><br />
<h1 style="border-bottom-color: rgb(33, 150, 243); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 4px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 24px; font-weight: 400; line-height: 34px; margin: 30px 0px 20px; padding: 0px 0px 30px; transition: border-color 0.8s ease-out 0s; width: 739px;">
<b>Q:</b> What is the difference between binary and text files?</h1>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
<b>A:</b> All files can be categorized into one of two file formats — binary or text. The two file types may look the same on the surface, but they <a href="https://techterms.com/definition/encoding" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">encode</a> data differently. While both <a href="https://techterms.com/definition/binary" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">binary</a> and text files contain data stored as a series of bits (binary values of 1s and 0s), the <a href="https://techterms.com/definition/bit" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">bits</a> in text files represent characters, while the bits in binary files represent custom <a href="https://techterms.com/definition/data" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">data</a>.</div>
<div class="helpsummary" style="background-color: #fafafa; border-radius: 3px; border: 1px solid rgb(189, 189, 189); color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin: 20px auto; padding: 10px; transition: background-color 0.8s ease-out 0s, border-color 0.8s ease-out 0s; width: 650px;">
While text files contain only textual data, binary files may contain both textual and custom binary data.</div>
<h4 style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 20px; margin: 0px; padding: 0px; text-align: justify;">
Binary Files</h4>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
Binary files typically contain a sequence of <a href="https://techterms.com/definition/byte" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">bytes</a>, or ordered groupings of eight <a href="https://techterms.com/definition/bit" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">bits</a>. When creating a custom file format for a program, a developer arranges these bytes into a format that stores the necessary information for the application. Binary file formats may include multiple types of data in the same file, such as image, video, and audio data. This data can be interpreted by supporting programs, but will show up as garbled text in a text editor. Below is an example of a <a href="https://fileinfo.com/extension/png" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;">.PNG</a> image file opened in an image viewer and a text editor.</div>
<div class="listbox" style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin: 0px; padding: 0px; text-align: justify;">
<table class="list" style="background: rgb(250, 250, 250); border-collapse: collapse; border: 1px solid rgb(21, 101, 192); box-sizing: border-box; margin: 15px 0px; padding: 0px; transition: background-color 0.8s ease-out 0s, border-color 0.8s ease-out 0s; width: 739px;"><tbody style="border: 0px; margin: 0px; padding: 0px;">
<tr style="background: rgb(245, 245, 245); border: 0px; margin: 0px; padding: 0px;"><th class="center" style="background: rgb(30, 136, 229); border: 0px; color: white; margin: 0px; padding: 7px 10px 8px; text-align: center; transition: background-color 0.8s ease-out 0s, color 0.4s ease-out 0s;">Image Viewer</th><th class="center" style="background: rgb(30, 136, 229); border: 0px; color: white; margin: 0px; padding: 7px 10px 8px; text-align: center; transition: background-color 0.8s ease-out 0s, color 0.4s ease-out 0s;">Text Editor</th></tr>
<tr style="border: 0px; margin: 0px; padding: 0px;"><td class="center" style="border: 0px; height: 36px; margin: 0px; padding: 2px 10px 3px; text-align: center; vertical-align: middle;"><img alt="Flower - Image Viewer" src="https://cdn.fileinfo.com/img/help/flower.png" style="background-color: white; border: 0px; display: block; margin: 10px auto; max-width: 99%; padding: 4px;" /></td><td class="center" style="border: 0px; height: 36px; margin: 0px; padding: 2px 10px 3px; text-align: center; vertical-align: middle;"><img alt="Flower - Text Editor" src="https://cdn.fileinfo.com/img/help/flower-text.png" style="background-color: white; border: 0px; display: block; margin: 10px auto; max-width: 99%; padding: 4px;" /></td></tr>
</tbody></table>
</div>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
As you can see, the image viewer recognizes the binary data and displays the picture. When the image is opened in a text editor, the binary data is converted to unrecognizable text. However, you may notice that some of the text is readable. This is because the PNG format includes small sections for storing textual data. The text editor, while not designed to read this file format, still displays this text when the file is opened. Many other binary file types include sections of readable text as well. Therefore, it may be possible to find out some information about an unknown binary file type by opening it in a text editor.</div>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
Binary files often contain headers, which are bytes of data at the beginning of a file that identifies the file's contents. Headers often include the file type and other descriptive information. For example, in the image above, the "PNG" text indicates the file is a PNG image. If a file has invalid header information, software programs may not open the file or they may report that the file is corrupted.</div>
<h4 style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 20px; margin: 0px; padding: 0px; text-align: justify;">
Text Files</h4>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
Text files are more restrictive than binary files since they can only contain textual data. However, unlike binary files, they are less likely to become corrupted. While a small error in a binary file may make it unreadable, a small error in a text file may simply show up once the file has been opened. This is one of reasons Microsoft switched to a compressed text-based <a href="https://techterms.com/definition/xml" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">XML</a> format for the <a href="https://fileinfo.com/help/office_2007_formats" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;">Office 2007 file types</a>.</div>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
Text files may be saved in either a <a href="https://techterms.com/definition/plaintext" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">plain text</a> (<a href="https://fileinfo.com/extension/txt" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;">.TXT</a>) format and <a href="https://techterms.com/definition/richtext" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;" target="techterms">rich text</a> (<a href="https://fileinfo.com/extension/rtf" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;">.RTF</a>) format. A typical plain text file contains several lines of text that are each followed by an End-of-Line (EOL) character. An End-of-File (EOF) marker is placed after the final character, which signals the end of the file. Rich text files use a similar file structure, but may also include text styles, such as bold and italics, as well as page formatting information. Both plain text and rich text files include a (character encoding| characterencoding) scheme that determines how the characters are interpreted and what characters can be displayed.</div>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
Since text files use a simple, standard format, many programs are capable of reading and editing text files. Common <a href="https://fileinfo.com/help/text_editors" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;">text editors</a> include Microsoft Notepad and WordPad, which are bundled with Windows, and Apple TextEdit, which is included with Mac OS X.</div>
<h4 style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 20px; margin: 0px; padding: 0px; text-align: justify;">
Unknown Files</h4>
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
If you come across an unknown file type, first look up the <a href="https://fileinfo.com/help/file_extension" style="border: 0px; color: #1e88e5; margin: 0px; padding: 0px; text-decoration-line: none;">file extension</a> on FileInfo.com. If the file does not have an extension or you are unable to locate the file type, you can attempt to open the file in a text editor. If the file opens and displays fully readable text, it is a text file, which you have successfully opened.</div>
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;"></span><br />
<div style="border: 0px; color: #424242; font-family: "Open Sans", "Lucida Sans", sans-serif; font-size: 18px; margin-bottom: 15px; margin-top: 15px; padding: 0px; text-align: justify;">
If the file opens and displays mostly garbled text, it is a binary file. While the file is not mean to be opened in a text editor, there may be some clues within the text that reveal information about the file type, like in the PNG example above. This may help you determine what program you need to open the file correctly. Finally, if the file will not open in a text editor, it is a binary file that can only be opened by the appropriate program.</div>
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;"><br /></span>
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;"><br /></span>
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">In C++, you open a file, you must first obtain
a stream. There are the following three types of streams:<o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l3 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">input<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l3 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">output<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l3 level1 lfo2; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">input/output<o:p></o:p></span></li>
</ul>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 3;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;">Create an
Input Stream<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">To create an input stream, you must declare
the stream to be of class ifstream. Here is the syntax:<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 10.0pt;"><br />
ifstream fin;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 3;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;">Create an
Output Stream<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">To create an output stream, you must declare
it as class ofstream. Here is an example:<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 10.0pt;">ofstream fout;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 3;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;">Create
both Input/Output Streams<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Streams that will be performing both input and
output operations must be declared as class fstream. Here is an example:<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 10.0pt;">fstream fio;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">Opening a
File in C++<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Once a stream has been created, next step is
to associate a file with it. And thereafter the file is available (opened) for
processing.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Opening of files can be achieved in the
following two ways :<o:p></o:p></span></div>
<ol start="1" type="1">
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l1 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Using
the constructor function of the stream class.<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l1 level1 lfo3; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Using
the function open().<o:p></o:p></span></li>
</ol>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">The first method is preferred when a single
file is used with a stream. However, for managing multiple files with the same
stream, the second method is preferred. Let's discuss each of these methods one
by one.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">Opening
File Using Constructors<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">We know that a constructor of class
initializes an object of its class when it (the object) is being created. Same
way, the constructors of stream classes (ifstream, ofstream, or fstream) are
used to initialize file stream objects with the filenames passed to them. This
is carried out as explained here:<br />
To open a file named myfile as an input file (i.e., data will be need from it
and no other operation like writing or modifying would take place on the file),
we shall create a file stream object of input type i.e., ifstream type. Here is
an example:<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 14.0pt;">ifstream
fin("myfile", ios::in) ;<o:p></o:p></span></div>
<div class="MsoNormal">
Now to read from this file, this stream object will be used
using the getfrom operator (">>"). Here is an example:<o:p></o:p></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">ifstream
fin("myfile", ios::in) ;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">The above given statement creates an object,
fin, of input file stream. The object name is a user-defined name (i.e., any
valid identifier name can be given). After creating the ifstream object fin,
the file myfile is opened and attached to the input stream, fin. Now, both the
data being read from myfile has been channelised through the input stream
object.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Now to read from this file, this stream object
will be used using the getfrom operator (">>"). Here is an
example:<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">char ch;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">fin >> ch ; // read a character from the file<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">float amt ;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">fin >> amt
; // read a floating-point number
form the file<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Similarly, when you want a program to write a
file i.e., to open an output file (on which no operation can take place except
writing only). This will be accomplish by<o:p></o:p></span></div>
<ol start="1" type="1">
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l2 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">creating
ofstream object to manage the output stream<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l2 level1 lfo4; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">associating
that object with a particular file<o:p></o:p></span></li>
</ol>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Here is an example,<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">ofstream
fout("secret" ios::out) ;// create ofstream object named as fout<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">This would create an output stream, object
named as fout and attach the file secret with it.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Now, to write something to it, you can use
<< (put to operator) in familiar way. Here is an example,<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">int code = 2193 ;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">fout << code
<< "xyz" ; /* will
write value of code<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;"> and "xyz" to
fout's associated<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;"> file namely
"secret" here. */<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">The connections with a file are closed
automatically when the input and the output stream objects expires i.e., when
they go out of scope. (For example, a global object expires when the program
terminates). Also, you can close a connection with a file explicitly by using
the close() method :<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">fin.close() ; // close input connection to file<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #333333; font-family: "courier new"; font-size: 12.0pt;">fout.close() ; // close output connection to file<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">Closing such a connection does not eliminate the stream; it just
disconnects it from the file. The stream still remains there. For example,
after the above statements, the streams fin and fout still exist along with the
buffers they manage. You can reconnect the stream to the same file or to
another file, if required. Closing a file flushes the buffer which means the
data remaining in the buffer (input or output stream) is moved out of it in the
direction it is ought to be. For example, when an input file's connection is
closed, the data is moved from the input buffer to the program and when an
output file's connection is closed, the data is moved from the output buffer to
the disk file.<o:p></o:p></span></div>
<h2 style="background: white;">
<span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">Opening Files Using Open() Function<o:p></o:p></span></h2>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">There may
be situations requiring a program to open more than one file. The strategy for
opening multiple files depends upon how they will be used. If the situation
requires simultaneous processing of two files, then you need to create a
separate stream for each file. However, if the situation demands sequential
processing of files (i.e., processing them one by one), then you can open a
single stream and associate it with each file in turn. To use this approach,
declare a stream object without initializing it, then use a second statement to
associate the stream with a file. For example,<o:p></o:p></span></div>
<pre style="background: white;"><span style="color: #333333;">ifstream fin; // create an input stream<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">fin.open("Master.dat", ios::in); // associate fin stream with file Master.dat<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">: // process Master.dat <o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">fin.close(); // terminate association with Master.dat<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;">fin.open("Tran.dat", ios::in); // associate fin stream with file Tran.dat<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">: // process Tran.dat<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">fin.close(); // terminate association<o:p></o:p></span></pre>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">The above
code lets you handle reading two files in succession. Note that the first file
is closed before opening the second one. This is necessary because a stream can
be connected to only one file at a time.<o:p></o:p></span></div>
<h3 style="background: white;">
<span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;">The Concept of File Modes<o:p></o:p></span></h3>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">The
filemode describes how a file is to be used : to read from it, to write to it,
to append it, and so on.<o:p></o:p></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">When you
associate a stream with a file, either by initializing a file stream object
with a file name or by using the open() method, you can provide a second
argument specifying the file mode, as mentioned below :<o:p></o:p></span></div>
<pre style="background: white;"><span style="color: #333333;">stream_object.open("filename", (filemode) ) ;<o:p></o:p></span></pre>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif";">The
second method argument of open(), the filemode, is of type int, and you can
choose one from several constants defined in the ios class.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 3;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 13.0pt;">List of
File Modes in C++<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Following table lists the filemodes available
in C++ with their meaning :<o:p></o:p></span></div>
<table border="1" cellpadding="0" class="MsoNormalTable" style="border: solid teal 1.0pt; mso-border-alt: solid teal .75pt; mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184; width: 655px;">
<tbody>
<tr style="height: 13.35pt; mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background: teal; border: none; height: 13.35pt; padding: 7.5pt 7.5pt 7.5pt 7.5pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: white; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Constant<o:p></o:p></span></b></div>
</td>
<td style="background: teal; border: none; height: 13.35pt; padding: 7.5pt 7.5pt 7.5pt 7.5pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: white; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Meaning<o:p></o:p></span></b></div>
</td>
<td style="background: teal; border: none; height: 13.35pt; padding: 7.5pt 7.5pt 7.5pt 7.5pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<b><span style="color: white; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Stream Type<o:p></o:p></span></b></div>
</td>
</tr>
<tr style="height: 14.1pt; mso-yfti-irow: 1;">
<td style="background: whitesmoke; border: none; height: 14.1pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: in<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 14.1pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">It opens file for
reading, i.e., in input mode.<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 14.1pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Ifstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 54.15pt; mso-yfti-irow: 2;">
<td style="background: mintcream; border: none; height: 54.15pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: out<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 54.15pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">It opens file for
writing, i.e., in output mode.<br />
This also opens the file in ios :: trunc mode, by default.<br />
This means an existing file is truncated when opened,<br />
i.e., its previous contents are discarded.<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 54.15pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Ofstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 27.45pt; mso-yfti-irow: 3;">
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: ate<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">This seeks to
end-of-file upon opening of the file.<br />
I/O operations can still occur anywhere within the file.<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ofstream<br />
ifstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 27.45pt; mso-yfti-irow: 4;">
<td style="background: mintcream; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: app<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">This causes all
output to that file to be appended to the end.<br />
This value can be used only with files capable of output.<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Ofstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 27.45pt; mso-yfti-irow: 5;">
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: trunc<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">This value causes
the contents of a pre-existing file by the same name<br />
to be destroyed and truncates the file to zero length.<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Ofstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 26.7pt; mso-yfti-irow: 6;">
<td style="background: mintcream; border: none; height: 26.7pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: nocreate<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 26.7pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">This cause the
open() function to fail if the file does not already exist.<br />
It will not create a new file with that name.<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 26.7pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Ofstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 27.45pt; mso-yfti-irow: 7;">
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: noreplace<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">This causes the
open() function to fail if the file already exists.<br />
This is used when you want to create a new file and at the same time.<o:p></o:p></span></div>
</td>
<td style="background: whitesmoke; border: none; height: 27.45pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">Ofstream<o:p></o:p></span></div>
</td>
</tr>
<tr style="height: 82.35pt; mso-yfti-irow: 8; mso-yfti-lastrow: yes;">
<td style="background: mintcream; border: none; height: 82.35pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ios :: binary<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 82.35pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">This causes a file
to be opened in binary mode.<br />
By default, files are opened in text mode.<br />
When a file is opened in text mode,<br />
various character translations may take place,<br />
such as the conversion of carriage-return into newlines.<br />
However, no such character translations occur in file opened in binary mode.<o:p></o:p></span></div>
</td>
<td style="background: mintcream; border: none; height: 82.35pt; padding: 5.25pt 5.25pt 5.25pt 5.25pt;"><div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #333333; font-family: "times new roman" , "serif"; font-size: 12.0pt;">ofstream<br />
ifstream<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">If the ifstream and ofstream constructors and
the open() methods take two arguments each, how have we got by using just one
in the previous examples ? As you probably have guessed, the prototypes for
these class member functions provide default values for the second argument
(the filemode argument). For example, the ifstream open() method and
constructor use ios :: in (open for reading) as the default value for the mode
argument, while the ofstream open() method and constructor use ios :: out (open
for writing) as the default.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">The fstream class does not provide a mode by
default and, therefore, one must specify the mode explicitly when using an
object of fstream class.<span class="msoIns"><ins><o:p></o:p></ins></span></span></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; mso-outline-level: 2;">
<b><span style="color: green; font-family: "helvetica" , "sans-serif"; font-size: 14.0pt;">C++
Opening and Closing a File Example<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Here is an example given, for the complete
understanding on:<o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l0 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">how
to open a file in C++ ?<o:p></o:p></span></li>
<li class="MsoNormal" style="background: white; color: #333333; line-height: 18.75pt; mso-list: l0 level1 lfo5; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto; tab-stops: list .5in;"><span style="font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">how
to close a file in C++ ?<o:p></o:p></span></li>
</ul>
<div class="MsoNormal" style="background: white; line-height: 18.75pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<span style="color: #333333; font-family: "helvetica" , "sans-serif"; font-size: 12.0pt;">Let's look at this program.<o:p></o:p></span></div>
<pre style="background: white;"><span style="color: #333333;">/* C++ Opening and Closing a File<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> * This program demonstrates, how<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> * to open a file to store or retrieve<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> * information to/from it. And then how<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> * to close that file after storing<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> * or retrieving the information to/from it. */<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<conio.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<string.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<stdio.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<fstream.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">#include<stdlib.h><o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">void main()<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">{<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> ofstream fout;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> ifstream fin;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> char fname[20];<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> char rec[80], ch;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> clrscr();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Enter file name: ";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(fname, 20);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> fout.open(fname, ios::out);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> if(!fout)<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> {<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Error in opening the file "<<fname;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> getch();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> exit(1);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> }<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(ch);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\nEnter a line to store in the file:\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(rec, 80);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> fout<<rec<<"\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\nThe entered line stored in the file successfully..!!";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\nPress any key to see...\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> getch();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> fout.close();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> fin.open(fname, ios::in);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> if(!fin)<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> {<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"Error in opening the file "<<fname;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\nPress any key to exit...";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> getch();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> exit(2);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> }<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> cin.get(ch);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> fin.get(rec, 80);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\nThe file contains:\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<rec;<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> cout<<"\n\nPress any key to exit...\n";<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> fin.close();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;"> </span></pre>
<pre style="background: white;"><span style="color: #333333;"> getch();<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: #333333;">}<o:p></o:p></span></pre>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , sans-serif; font-size: 12pt;"><br /></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , sans-serif; font-size: 12pt;"><br /></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , sans-serif; font-size: 12pt;"><br /></span></div>
<div style="background: white; line-height: 18.75pt;">
<span style="color: #333333; font-family: "helvetica" , sans-serif; font-size: 12pt;"><br /></span></div>
<div style="background: white; line-height: 18.75pt;">
<br /></div>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">#include <iostream> </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">#include <conio.h></span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"> </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">#include <fstream> </span></span><br />
<br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">using namespace std; </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">int main() </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">{ </span></span><br />
<br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"> ofstream fout; </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"> string line; </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px;"><span style="white-space: pre;"> </span> fout.open("sample.txt"); </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"> <span style="white-space: pre;"> </span>fout << line << endl; </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"> <span style="white-space: pre;"> </span>fout.close(); </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"> return 0; </span></span><br />
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;"><br /></span></span>
<span style="color: #454545; font-family: "material icons";"><span style="font-size: 24px; white-space: nowrap;">} </span></span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<header class="entry-header" style="border: 0px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-family: Roboto, sans-serif; font-size: 10.8px; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;"><h1 class="entry-title" style="border: 0px; box-sizing: border-box; clear: both; font-size: 28px; font-weight: 400; line-height: 1.2; margin: 0px 0px 15px; padding: 0px; vertical-align: baseline;">
File Handling through C++ Classes</h1>
</header><br />
<div class="entry-content" style="border: 0px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-family: Roboto, sans-serif; font-size: 16px; line-height: 19px; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
In C++, files are mainly dealt by using three classes fstream, ifstream, ofstream available in fstream headerfile.<br />
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">ofstream:</strong> Stream class to write on files<br />
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">ifstream:</strong> Stream class to read from files<br />
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">fstream:</strong> Stream class to both read and write from/to files.</div>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
Now the first step to open the particular file for read or write operation. We can open file by<br />
1. passing file name in constructor at the time of object creation<br />
2. using the open method<br />
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">For e.g.</strong></div>
<div style="border: 0px; box-sizing: border-box; font-style: italic; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Open File by using constructor</strong><br />
ifstream (const char* filename, ios_base::openmode mode = ios_base::in);<br />
ifstream fin(filename, openmode) by default openmode = ios::in<br />
ifstream fin(“filename”);</div>
<div style="border: 0px; box-sizing: border-box; font-style: italic; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Open File by using open method</strong><br />
Calling of default constructor<br />
ifstream fin;</div>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"></strong></div>
<div style="border: 0px; box-sizing: border-box; font-style: italic; line-height: 1.71429; padding: 0px; text-align: left; vertical-align: baseline;">
fin.open(filename, openmode)<br />
fin.open(“filename”);<br />
<br /></div>
<div style="border: 0px; box-sizing: border-box; font-style: italic; line-height: 1.71429; padding: 0px; text-align: left; vertical-align: baseline;">
Mode<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 7.5pt; vertical-align: baseline;">
<br /></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: white; border-collapse: collapse; border: none; mso-border-alt: outset windowtext .25pt; mso-border-bottom-alt: solid #EDEDED .75pt; mso-padding-alt: 0in 0in 0in 0in; mso-table-layout-alt: fixed; mso-yfti-tbllook: 1184; width: 640px;">
<tbody>
<tr>
<td style="background: #4CB96B; border: none; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 136.5pt;" valign="bottom" width="182"><div align="center" class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b><span style="font-family: "times new roman" , serif; font-size: 8.5pt; line-height: 200%; text-transform: uppercase;">MEMBER CONSTANT<o:p></o:p></span></b></div>
</td>
<td style="background: #4CB96B; border: none; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 166.5pt;" valign="bottom" width="222"><div align="center" class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b><span style="font-family: "times new roman" , serif; font-size: 8.5pt; line-height: 200%; text-transform: uppercase;">STANDS FOR<o:p></o:p></span></b></div>
</td>
<td style="background: #4CB96B; border: none; padding: 6.0pt 6.0pt 6.0pt 6.0pt; width: 177.0pt;" valign="bottom" width="236"><div align="center" class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in; text-align: center;">
<b><span style="font-family: "times new roman" , serif; font-size: 8.5pt; line-height: 200%; text-transform: uppercase;">ACCESS<o:p></o:p></span></b></div>
</td>
</tr>
<tr>
<td style="border-top: solid #EDEDED 1.0pt; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 136.5pt;" valign="bottom" width="182"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">in *<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 166.5pt;" valign="bottom" width="222"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;"> input<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 177.0pt;" valign="bottom" width="236"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">File open for reading: the
internal stream buffer supports input operations.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 136.5pt;" width="182"></td>
<td style="border: none; padding: 0in 0in 0in 0in; width: 166.5pt;" width="222"></td>
<td style="border-right: inset 1.0pt; border: none; mso-border-right-alt: inset windowtext .25pt; padding: 0in 0in 0in 0in; width: 177.0pt;" width="236"></td>
</tr>
<tr>
<td style="border-top: none; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 136.5pt;" valign="bottom" width="182"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">Out<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 166.5pt;" valign="bottom" width="222"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">output<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 177.0pt;" valign="bottom" width="236"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">File open for writing: the
internal stream buffer supports output operations.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 136.5pt;" width="182"></td>
<td style="border: none; padding: 0in 0in 0in 0in; width: 166.5pt;" width="222"></td>
<td style="border-right: inset 1.0pt; border: none; mso-border-right-alt: inset windowtext .25pt; padding: 0in 0in 0in 0in; width: 177.0pt;" width="236"></td>
</tr>
<tr>
<td style="border-top: none; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 136.5pt;" valign="bottom" width="182"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">Binary<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 166.5pt;" valign="bottom" width="222"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">binary<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 177.0pt;" valign="bottom" width="236"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">Operations are performed in binary
mode rather than text.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 136.5pt;" width="182"></td>
<td style="border: none; padding: 0in 0in 0in 0in; width: 166.5pt;" width="222"></td>
<td style="border-right: inset 1.0pt; border: none; mso-border-right-alt: inset windowtext .25pt; padding: 0in 0in 0in 0in; width: 177.0pt;" width="236"></td>
</tr>
<tr>
<td style="border-top: none; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 136.5pt;" valign="bottom" width="182"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">Ate<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 166.5pt;" valign="bottom" width="222"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">at end<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 177.0pt;" valign="bottom" width="236"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">The output position starts at the
end of the file.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 136.5pt;" width="182"></td>
<td style="border: none; padding: 0in 0in 0in 0in; width: 166.5pt;" width="222"></td>
<td style="border-right: inset 1.0pt; border: none; mso-border-right-alt: inset windowtext .25pt; padding: 0in 0in 0in 0in; width: 177.0pt;" width="236"></td>
</tr>
<tr>
<td style="border-top: none; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 136.5pt;" valign="bottom" width="182"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">App<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 166.5pt;" valign="bottom" width="222"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">append<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 177.0pt;" valign="bottom" width="236"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">All output operations happen at
the end of the file, appending to its existing contents.<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="padding: 0in 0in 0in 0in; width: 136.5pt;" width="182"></td>
<td style="border: none; padding: 0in 0in 0in 0in; width: 166.5pt;" width="222"></td>
<td style="border-right: inset 1.0pt; border: none; mso-border-right-alt: inset windowtext .25pt; padding: 0in 0in 0in 0in; width: 177.0pt;" width="236"></td>
</tr>
<tr>
<td style="border-top: none; border: inset 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 136.5pt;" valign="bottom" width="182"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">Trunk<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 166.5pt;" valign="bottom" width="222"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">truncate<o:p></o:p></span></div>
</td>
<td style="border-bottom: inset 1.0pt; border-left: none; border-right: inset 1.0pt; border-top: solid #EDEDED 1.0pt; mso-border-alt: inset windowtext .25pt; mso-border-left-alt: inset windowtext .25pt; mso-border-top-alt: solid #EDEDED .75pt; padding: 5.25pt 10.5pt 5.25pt 10.5pt; width: 177.0pt;" valign="bottom" width="236"><div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="font-family: "times new roman" , "serif"; font-size: 12.0pt; line-height: 200%;">Any contents that existed in the
file before it is open are discarded.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: 200%; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal">
<br /></div>
<br />
<br /></div>
<div style="background-color: white; border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
</div>
<table border="1" style="background-color: white; border-bottom-color: rgb(237, 237, 237); border-bottom-style: solid; border-collapse: collapse; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-spacing: 0px; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-size: 12px; line-height: 2; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; width: 640px;"><tbody style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;"></td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;"></td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;"><div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; vertical-align: baseline;">
<b style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Default Open Modes :</b></div>
<table border="0" style="border-bottom-color: rgb(237, 237, 237); border-bottom-style: solid; border-collapse: collapse; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-spacing: 0px; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-size: 12px; line-height: 2; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; width: 640px;"><tbody style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">ifstream</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">ios::in</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">ofstream</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">ios::out</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">fstream</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">ios::in | ios::out</td></tr>
</tbody></table>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Problem Statement</strong> : To read and write a File in C++.<br />
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Examples:</strong></div>
<div id="practiceLinkDiv" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
</div>
<br style="box-sizing: border-box; text-align: justify;" />
<ins class="adsbygoogle" data-ad-client="ca-pub-9465609616171866" data-ad-format="auto" data-ad-slot="4501693235" data-adsbygoogle-status="done" style="background-attachment: initial; background-clip: initial; background-image: none; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; box-sizing: border-box; display: block; height: 0px; margin: 0px; padding: 0px; text-align: justify; text-decoration-line: none; vertical-align: baseline;"><ins id="aswift_2_expand" style="background: none transparent; border: none; box-sizing: border-box; display: inline-table; height: 0px; margin: 0px; padding: 0px; position: relative; text-decoration-line: none; vertical-align: baseline; visibility: visible; width: 640px;"><ins id="aswift_2_anchor" style="background: none transparent; border: none; box-sizing: border-box; display: block; height: 0px; margin: 0px; opacity: 0; overflow: hidden; padding: 0px; position: relative; text-decoration-line: none; vertical-align: baseline; visibility: visible; width: 640px;"><iframe allowfullscreen="true" allowtransparency="true" frameborder="0" height="60" hspace="0" id="aswift_2" marginheight="0" marginwidth="0" name="aswift_2" scrolling="no" style="border-style: initial; border-width: 0px; box-sizing: border-box; height: 60px; left: 0px; margin: 0px 0px 2px; max-width: 100%; padding: 0px; position: absolute; top: 0px; vertical-align: baseline; width: 640px;" vspace="0" width="640"></iframe></ins></ins></ins><br style="box-sizing: border-box; text-align: justify;" />
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; vertical-align: baseline;">
Below is the implementation by using <strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">ifsream & ofstream classes</strong>.</div>
<div class="responsive-tabs-wrapper" style="border: 0px; box-sizing: border-box; clear: both; margin: 0px 0px 20px; padding: 0px; text-align: justify; vertical-align: baseline; zoom: 1;">
<div class="responsive-tabs responsive-tabs--enabled" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">
<div aria-hidden="false" aria-labelledby="tablist1-tab1" class="tabcontent responsive-tabs__panel responsive-tabs__panel--active" id="tablist1-panel1" role="tabpanel" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-radius: 0px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; clear: left; margin: 0px; overflow-wrap: break-word; padding: 0px 5px; vertical-align: baseline;">
<div class="code-block" style="border: 0px; box-sizing: border-box; display: flex; flex-direction: row; margin: 0px 0px 10px; padding: 0px; vertical-align: baseline;">
<div class="code-gutter" style="border: 0px; box-sizing: border-box; flex-flow: column; margin: 0px; padding: 0px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons-container" style="border: 0px; bottom: 0px; box-sizing: border-box; left: 0px; margin: 0px; padding: 0px; position: sticky; top: 30px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons" style="align-items: center; border: 0px; box-sizing: border-box; display: flex; flex-flow: column; margin: 0px; padding: 6px 0px 0px; position: sticky; top: 0px; vertical-align: baseline; width: 40px; z-index: 1;">
<div class="editor-buttons-div" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;" title="Run and Edit">
<div style="border: 0px; box-sizing: border-box; line-height: inherit; padding: 0px; text-align: left; vertical-align: baseline;">
<br /></div>
</div>
</div>
</div>
</div>
<div class="code-container" style="border: 0px; box-sizing: border-box; flex: 1 1 0%; margin: 0px; min-width: 0px; overflow-y: hidden; padding: 0px; vertical-align: baseline; width: 588.438px;">
<div class="syntaxhighlighter nogutter " id="highlighter_858059" style="border: 0px; box-sizing: border-box; font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 588.438px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none !important; border-collapse: collapse; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgba(0, 0, 0, 0.84) !important; direction: ltr !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 588px;"><tbody style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="code" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 588px;"><div class="container" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 5px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* File Handling with C++ using ifstream & ofstream class object*/</code></div>
<div class="line number2 index1 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* To write the Content in File*/</code></div>
<div class="line number3 index2 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* Then to read the content of file*/</code></div>
<div class="line number4 index3 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="preprocessor" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">#include <iostream> </code></div>
<div class="line number5 index4 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number6 index5 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* fstream header file for ifstream, ofstream, </code></div>
<div class="line number7 index6 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fstream classes */</code></div>
<div class="line number8 index7 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="preprocessor" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">#include <fstream> </code></div>
<div class="line number9 index8 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number10 index9 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">using</code> <code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">namespace</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">std; </code></div>
<div class="line number11 index10 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number12 index11 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Driver Code </code></div>
<div class="line number13 index12 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">main() </code></div>
<div class="line number14 index13 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">{ </code></div>
<div class="line number15 index14 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Creation of ofstream class object </code></div>
<div class="line number16 index15 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">ofstream fout; </code></div>
<div class="line number17 index16 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number18 index17 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">string line; </code></div>
<div class="line number19 index18 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number20 index19 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// by default ios::out mode, automatically deletes </code></div>
<div class="line number21 index20 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// the content of file. To append the content, open in ios:app </code></div>
<div class="line number22 index21 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// fout.open("sample.txt", ios::app) </code></div>
<div class="line number23 index22 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fout.open(</code><code class="string" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: blue !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">"sample.txt"</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">); </code></div>
<div class="line number24 index23 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number25 index24 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Execute a loop If file successfully opened </code></div>
<div class="line number26 index25 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">while</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">(fout) { </code></div>
<div class="line number27 index26 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number28 index27 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Read a Line from standard input </code></div>
<div class="line number29 index28 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">getline(cin, line); </code></div>
<div class="line number30 index29 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number31 index30 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Press -1 to exit </code></div>
<div class="line number32 index31 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">if</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">(line == </code><code class="string" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: blue !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">"-1"</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">) </code></div>
<div class="line number33 index32 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">break</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">; </code></div>
<div class="line number34 index33 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number35 index34 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Write line in file </code></div>
<div class="line number36 index35 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fout << line << endl; </code></div>
<div class="line number37 index36 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
<div class="line number38 index37 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number39 index38 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Close the File </code></div>
<div class="line number40 index39 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fout.close(); </code></div>
<div class="line number41 index40 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number42 index41 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Creation of ifstream class object to read the file </code></div>
<div class="line number43 index42 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">ifstream fin; </code></div>
<div class="line number44 index43 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number45 index44 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// by default open mode = ios::in mode </code></div>
<div class="line number46 index45 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fin.open(</code><code class="string" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: blue !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">"sample.txt"</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">); </code></div>
<div class="line number47 index46 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number48 index47 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Execute a loop until EOF (End of File) </code></div>
<div class="line number49 index48 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">while</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">(fin) { </code></div>
<div class="line number50 index49 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number51 index50 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Read a Line from File </code></div>
<div class="line number52 index51 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">getline(fin, line); </code></div>
<div class="line number53 index52 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number54 index53 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Print line in Console </code></div>
<div class="line number55 index54 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">cout << line << endl; </code></div>
<div class="line number56 index55 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
<div class="line number57 index56 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number58 index57 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Close the file </code></div>
<div class="line number59 index58 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fin.close(); </code></div>
<div class="line number60 index59 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number61 index60 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">return</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">0; </code></div>
<div class="line number62 index61 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; vertical-align: baseline;">
Below is the implementation by using <strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">fstream class</strong>.</div>
<div class="responsive-tabs-wrapper" style="border: 0px; box-sizing: border-box; clear: both; margin: 0px 0px 20px; padding: 0px; text-align: justify; vertical-align: baseline; zoom: 1;">
<div class="responsive-tabs responsive-tabs--enabled" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">
<ul class="responsive-tabs__list" role="tablist" style="border: 0px; box-sizing: border-box; font-size: 18px; line-height: 18px; list-style-image: initial; list-style-position: outside; margin: 20px 0px 0px; padding: 0px; vertical-align: baseline;">
<li aria-controls="tablist2-panel1" class="responsive-tabs__list__item responsive-tabs__list__item--active" id="tablist2-tab1" role="tab" style="border-bottom: none rgb(221, 221, 221); border-left: 1px solid rgb(221, 221, 221); border-right: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-top: 1px solid rgb(221, 221, 221); box-sizing: border-box; color: #ec4e20; cursor: pointer; display: inline; float: left; line-height: 19px; margin: 0px 0px 0px 12px; padding: 10px 12px 11px; position: relative; text-align: left; text-transform: inherit; top: 1px; vertical-align: baseline; white-space: nowrap;" tabindex="0">C++</li>
</ul>
<div aria-hidden="false" aria-labelledby="tablist2-tab1" class="tabcontent responsive-tabs__panel responsive-tabs__panel--active" id="tablist2-panel1" role="tabpanel" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-radius: 0px; border: 1px solid rgb(221, 221, 221); box-sizing: border-box; clear: left; margin: 0px; overflow-wrap: break-word; padding: 0px 5px; vertical-align: baseline;">
<div class="code-block" style="border: 0px; box-sizing: border-box; display: flex; flex-direction: row; margin: 0px 0px 10px; padding: 0px; vertical-align: baseline;">
<div class="code-gutter" style="border: 0px; box-sizing: border-box; flex-flow: column; margin: 0px; padding: 0px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons-container" style="border: 0px; bottom: 0px; box-sizing: border-box; left: 0px; margin: 0px; padding: 0px; position: sticky; top: 30px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons" style="align-items: center; border: 0px; box-sizing: border-box; display: flex; flex-flow: column; margin: 0px; padding: 6px 0px 0px; position: sticky; top: 0px; vertical-align: baseline; width: 40px; z-index: 1;">
<div class="editor-buttons-div" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;" title="Run and Edit">
<span class="material-icons code-sidebar-button copy-code-button" id="copy-code-button" style="border-radius: 50%; border: 0px; box-shadow: rgb(204 , 204 , 204) 1px 1px 2px 2px; box-sizing: border-box; color: #454545; cursor: pointer; direction: ltr; display: inline-block; font-family: "material icons"; font-size: 24px; line-height: 1; margin: 5px 0px 0px; overflow-wrap: normal; padding: 0.15em; transform: rotate(90deg); vertical-align: baseline; white-space: nowrap;" title="Copy Code">filt</span></div>
</div>
</div>
</div>
<div class="code-container" style="border: 0px; box-sizing: border-box; flex: 1 1 0%; margin: 0px; min-width: 0px; overflow-y: hidden; padding: 0px; vertical-align: baseline; width: 588.438px;">
<div class="syntaxhighlighter nogutter " id="highlighter_939301" style="border: 0px; box-sizing: border-box; font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 588.438px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none !important; border-collapse: collapse; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgba(0, 0, 0, 0.84) !important; direction: ltr !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 588px;"><tbody style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="code" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 588px;"><div class="container" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 5px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* File Handling with C++ using fstream class object */</code></div>
<div class="line number2 index1 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* To write the Content in File */</code></div>
<div class="line number3 index2 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* Then to read the content of file*/</code></div>
<div class="line number4 index3 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="preprocessor" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">#include <iostream> </code></div>
<div class="line number5 index4 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number6 index5 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">/* fstream header file for ifstream, ofstream, </code></div>
<div class="line number7 index6 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fstream classes */</code></div>
<div class="line number8 index7 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="preprocessor" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">#include <fstream> </code></div>
<div class="line number9 index8 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number10 index9 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">using</code> <code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">namespace</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">std; </code></div>
<div class="line number11 index10 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number12 index11 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Driver Code </code></div>
<div class="line number13 index12 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">main() </code></div>
<div class="line number14 index13 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">{ </code></div>
<div class="line number15 index14 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Creation of fstream class object </code></div>
<div class="line number16 index15 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fstream fio; </code></div>
<div class="line number17 index16 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number18 index17 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">string line; </code></div>
<div class="line number19 index18 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number20 index19 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// by default openmode = ios::in|ios::out mode </code></div>
<div class="line number21 index20 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Automatically overwrites the content of file, To append </code></div>
<div class="line number22 index21 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// the content, open in ios:app </code></div>
<div class="line number23 index22 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// fio.open("sample.txt", ios::in|ios::out|ios::app) </code></div>
<div class="line number24 index23 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// ios::trunc mode delete all conetent before open </code></div>
<div class="line number25 index24 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fio.open(</code><code class="string" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: blue !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">"sample.txt"</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">, ios::trunc | ios::out | ios::in); </code></div>
<div class="line number26 index25 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number27 index26 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Execute a loop If file successfully Opened </code></div>
<div class="line number28 index27 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">while</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">(fio) { </code></div>
<div class="line number29 index28 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number30 index29 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Read a Line from standard input </code></div>
<div class="line number31 index30 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">getline(cin, line); </code></div>
<div class="line number32 index31 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number33 index32 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Press -1 to exit </code></div>
<div class="line number34 index33 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">if</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">(line == </code><code class="string" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: blue !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">"-1"</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">) </code></div>
<div class="line number35 index34 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">break</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">; </code></div>
<div class="line number36 index35 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number37 index36 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Write line in file </code></div>
<div class="line number38 index37 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fio << line << endl; </code></div>
<div class="line number39 index38 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
<div class="line number40 index39 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number41 index40 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Execute a loop untill EOF (End of File) </code></div>
<div class="line number42 index41 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// point read pointer at beginning of file </code></div>
<div class="line number43 index42 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fio.seekg(0, ios::beg); </code></div>
<div class="line number44 index43 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number45 index44 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">while</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">(fio) { </code></div>
<div class="line number46 index45 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number47 index46 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Read a Line from File </code></div>
<div class="line number48 index47 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">getline(fio, line); </code></div>
<div class="line number49 index48 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number50 index49 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Print line in Console </code></div>
<div class="line number51 index50 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">cout << line << endl; </code></div>
<div class="line number52 index51 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
<div class="line number53 index52 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number54 index53 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// Close the file </code></div>
<div class="line number55 index54 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">fio.close(); </code></div>
<div class="line number56 index55 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code> </div>
<div class="line number57 index56 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">return</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">0; </code></div>
<div class="line number58 index57 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
</div>
</div>
</div>
</div>
<br style="box-sizing: border-box; text-align: justify;" />
<ins class="adsbygoogle" data-ad-client="ca-pub-9465609616171866" data-ad-format="auto" data-ad-slot="8385097921" data-adsbygoogle-status="done" style="background-attachment: initial; background-clip: initial; background-image: none; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 0px; box-sizing: border-box; display: block; height: 0px; margin: 0px; padding: 0px; text-align: justify; text-decoration-line: none; vertical-align: baseline;"><ins id="aswift_3_expand" style="background: none transparent; border: none; box-sizing: border-box; display: inline-table; height: 0px; margin: 0px; padding: 0px; position: relative; text-decoration-line: none; vertical-align: baseline; visibility: visible; width: 640px;"><ins id="aswift_3_anchor" style="background: none transparent; border: none; box-sizing: border-box; display: block; height: 0px; margin: 0px; opacity: 0; overflow: hidden; padding: 0px; position: relative; text-decoration-line: none; vertical-align: baseline; visibility: visible; width: 640px;"><iframe allowfullscreen="true" allowtransparency="true" frameborder="0" height="60" hspace="0" id="aswift_3" marginheight="0" marginwidth="0" name="aswift_3" scrolling="no" style="border-style: initial; border-width: 0px; box-sizing: border-box; height: 60px; left: 0px; margin: 0px 0px 2px; max-width: 100%; padding: 0px; position: absolute; top: 0px; vertical-align: baseline; width: 640px;" vspace="0" width="640"></iframe></ins></ins></ins><br style="box-sizing: border-box; text-align: justify;" />
<div class="recommendedPostsDiv" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
<h2 style="border: 0px; box-sizing: border-box; clear: both; color: #838383; font-size: 20px; line-height: 1.6; margin: 5px 0px; padding: 0px; vertical-align: baseline;">
</h2>
</div>
</td></tr>
</tbody></table>
</div>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-83384390735102950752019-06-18T07:12:00.001-07:002019-06-21T07:30:37.235-07:00structure<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background: white; margin-bottom: 16.8pt;">
<span style="color: #252830; font-family: "arial" , "sans-serif";">structure is a collection of variables of different data types
under a single name. It is similar to a <a href="https://www.programiz.com/cpp-programming/object-class" style="-webkit-font-smoothing: antialiased;" title="C++ class"><span style="color: #2b6dad; text-decoration: none;">class</span></a> in that, both
holds a collecion of data of different data types.<o:p></o:p></span></div>
<div style="-webkit-font-smoothing: antialiased; -webkit-text-stroke-width: 0px; background: white; font-variant-caps: normal; font-variant-ligatures: normal; margin-bottom: 16.8pt; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; widows: 2; word-spacing: 3px;">
<strong><span style="color: #555555; font-family: "arial" , "sans-serif";">For example: </span></strong><span style="color: #252830; font-family: "arial" , "sans-serif";">You want to store some
information about a person: his/her name, citizenship number and salary. You
can easily create different variables </span><var style="border-radius: 2px;"><span style="background: #eff0f1; color: #252830; font-family: "consolas"; font-size: 10.5pt; font-style: normal;">name, citNo, salary</span></var><span style="color: #252830; font-family: "arial" , "sans-serif";"> to store these
information separately.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 5.4pt; margin-left: 0in; margin-right: 0in; margin-top: 9.6pt; mso-outline-level: 2;">
<b><span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 19.0pt;">How to declare a structure in C++ programming?<o:p></o:p></span></b></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 16.8pt; mso-margin-top-alt: auto;">
<span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;">The </span><span style="background: #eff0f1; color: #252830; font-family: "consolas"; font-size: 10.5pt;">struct</span><span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;"> keyword defines a structure type
followed by an identifier (name of the structure).<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 16.8pt; mso-margin-top-alt: auto;">
<span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;">Then
inside the curly braces, you can declare one or more members (declare variables
inside curly braces) of that structure. For example:<o:p></o:p></span></div>
<div style="background: #F6F6F6; border: solid #EAEAEC 1.0pt; mso-border-alt: solid #EAEAEC .75pt; mso-element: para-border-div; padding: 11.0pt 14.0pt 11.0pt 14.0pt;">
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<b><span style="color: #555555; font-family: "consolas"; font-size: 11.5pt;">struct</span></b><span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"> Person<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>int age;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>float
salary;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">};<o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 16.8pt; mso-margin-top-alt: auto;">
<span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;">Here
a structure </span><span style="background: #eff0f1; color: #252830; font-family: "consolas"; font-size: 10.5pt;">person</span><span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;"> is defined which has two members: </span><span style="background: #eff0f1; color: #252830; font-family: "consolas"; font-size: 10.5pt;">age</span><span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;"> and </span><span style="background: #eff0f1; color: #252830; font-family: "consolas"; font-size: 10.5pt;">salary</span><span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;">.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 16.8pt; mso-margin-top-alt: auto;">
<br /></div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 16.8pt; mso-margin-top-alt: auto;">
<span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;">C++
Program to assign data to members of a structure variable and display it.<o:p></o:p></span></div>
<div style="background: #EEEEEE; border: solid #EAEAEC 1.0pt; mso-border-alt: solid #EAEAEC .75pt; mso-element: para-border-div; padding: 4.0pt 4.0pt 4.0pt 4.0pt;">
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: grey; font-family: "consolas"; font-size: 11.5pt;">#include</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> </span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;"><iostream></span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">using</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> </span><span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">namespace</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> std;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">struct</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> </span><span style="color: #2b91af; font-family: "consolas"; font-size: 11.5pt;">Person</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">int</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> age;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">float</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> salary;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;">};<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">int</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> main()<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #2b91af; font-family: "consolas"; font-size: 11.5pt;">Person</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> p1;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>cout <<
</span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;">"Enter
age: "</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>cin >>
p1.age;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>cout <<
</span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;">"Enter
salary: "</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>cin >>
p1.salary;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>cout <<
</span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;">"\nDisplaying
Information."</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> << endl;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span>cout <<</span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;">"Age: "</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> << p1.age << endl;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>cout << </span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;">"Salary: "</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> << p1.salary;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: darkblue; font-family: "consolas"; font-size: 11.5pt;">return</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;"> </span><span style="color: maroon; font-family: "consolas"; font-size: 11.5pt;">0</span><span style="color: black; font-family: "consolas"; font-size: 11.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: normal; margin-bottom: 7.5pt; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: "consolas"; font-size: 11.5pt;">}</span><span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="background: white; line-height: normal; margin-bottom: 16.8pt; mso-margin-top-alt: auto;">
<b><span style="color: #555555; font-family: "arial" , "sans-serif"; font-size: 12.0pt;">Output</span></b><span style="color: #252830; font-family: "arial" , "sans-serif"; font-size: 12.0pt;"><o:p></o:p></span></div>
<div style="background: #F6F6F6; border: solid #EAEAEC 1.0pt; mso-border-alt: solid #EAEAEC .75pt; mso-element: para-border-div; padding: 11.0pt 14.0pt 11.0pt 14.0pt;">
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">Enter age: 27<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">Enter salary: 1024.4<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">Displaying Information.<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">Age: 27<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F6F6F6; border: none; line-height: normal; margin-bottom: .3in; mso-border-alt: solid #EAEAEC .75pt; mso-padding-alt: 11.0pt 14.0pt 11.0pt 14.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">Salary: 1024.4<o:p></o:p></span><br />
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><br /></span>
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><br /></span>
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;">EXAMPLE :</span><br />
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><br /></span>
<span style="color: #252830; font-family: "consolas"; font-size: 11.5pt;"><br /></span>
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;">#include <iostream></span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;">using namespace std;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"><br /></span></span>
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;">int main()</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;">{</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> <span style="white-space: pre;"> </span>struct product {</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> <span style="white-space: pre;"> </span>int weight;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> <span style="white-space: pre;"> </span>double price;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"><span style="white-space: pre;"> </span>} apple, banana, melon;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> </span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> </span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> apple.weight=10;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> apple.price=20;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"><br /></span></span>
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> cout << "\nDisplaying Information." << endl;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> cout <<"Apple weight " <<apple.weight << endl;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> cout << "apple price " << apple.price;</span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"><br /></span></span>
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;"> return 0;</span></span><br />
<span style="font-size: 15.3333px;"><span style="color: #252830; font-family: "consolas";"></span></span><br />
<span style="color: #252830; font-family: "consolas";"><span style="font-size: 15.3333px;">}</span></span><br />
<div>
<br /></div>
</div>
</div>
<div style="background: #EEEEEE; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-element: para-border-div; padding: 4.0pt 4.0pt 4.0pt 4.0pt;">
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">#include</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;"><iostream></span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">#include</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;"><cstring></span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">using</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">namespace</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> std</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">struct</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Books</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">{</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">char</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>title</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">[</span><span style="color: #006666; font-family: "consolas"; font-size: 10.0pt;">50</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">];</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">char</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>author</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">[</span><span style="color: #006666; font-family: "consolas"; font-size: 10.0pt;">50</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">];</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">char</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>subject</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">[</span><span style="color: #006666; font-family: "consolas"; font-size: 10.0pt;">100</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">];</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">int</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>book_id</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">};</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">int</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> main</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">()</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">{</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">struct</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Books</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">// Declare Book1 of type Book</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">struct</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Books</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">// Declare Book2 of type Book</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">// book 1 specification</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>strcpy</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">(</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">title</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Learn C++
Programming"</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>strcpy</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">(</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">author</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Chand Miyan"</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>strcpy</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">(</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">subject</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"C++ Programming"</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">book_id </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">=</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #006666; font-family: "consolas"; font-size: 10.0pt;">6495407</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">// book 2 specification</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>strcpy</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">(</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">title</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Telecom Billing"</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>strcpy</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">(</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">author</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Yakit Singha"</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>strcpy</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">(</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">subject</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">,</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Telecom"</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">);</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">book_id </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">=</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #006666; font-family: "consolas"; font-size: 10.0pt;">6495700</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">// Print Book1 info</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 1 title : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">title </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 1 author : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">author </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 1 subject : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">subject </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 1 id : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book1</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">book_id </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #880000; font-family: "consolas"; font-size: 10.0pt;">// Print Book2 info</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 2 title : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">title </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 2 author : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">author </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 2 subject : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">subject </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span>cout </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #008800; font-family: "consolas"; font-size: 10.0pt;">"Book 2 id : "</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #7f0055; font-family: "consolas"; font-size: 10.0pt;">Book2</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">.</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">book_id </span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;"><<</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;">endl</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<br /></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><span style="mso-spacerun: yes;"> </span></span><span style="color: #000088; font-family: "consolas"; font-size: 10.0pt;">return</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"> </span><span style="color: #006666; font-family: "consolas"; font-size: 10.0pt;">0</span><span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">;</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #EEEEEE; border: none; line-height: 12.0pt; margin-bottom: 7.5pt; margin-left: 0in; margin-right: 0in; margin-top: 11.25pt; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #666600; font-family: "consolas"; font-size: 10.0pt;">}</span><span style="color: #313131; font-family: "consolas"; font-size: 10.0pt;"><o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="line-height: 18.0pt; margin-bottom: .1in; margin-left: 2.4pt; margin-right: 2.4pt; margin-top: 0in; text-align: justify;">
<span style="color: black; font-family: "verdana" , "sans-serif"; font-size: 12.0pt;">When the
above code is compiled and executed, it produces the following result −<o:p></o:p></span></div>
<div style="background: #F1F1F1; border: solid #D6D6D6 1.0pt; mso-border-alt: solid #D6D6D6 .75pt; mso-element: para-border-div; padding: 4.0pt 4.0pt 4.0pt 4.0pt;">
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 1 title : Learn C++ Programming<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 1 author : Chand Miyan<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 1 subject : C++ Programming<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 1 id : 6495407<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 2 title : Telecom Billing<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 2 author : Yakit Singha<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 2 subject : Telecom<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #F1F1F1; border: none; line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-border-alt: solid #D6D6D6 .75pt; mso-padding-alt: 4.0pt 4.0pt 4.0pt 4.0pt; padding: 0in; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: #313131; font-family: "consolas"; font-size: 9.0pt;">Book 2 id : 6495700<o:p></o:p></span></div>
</div>
<div class="MsoNormal" style="margin-bottom: 2.4pt; margin-left: 0in; margin-right: 2.4pt; margin-top: 2.4pt; mso-line-height-alt: 18.0pt; mso-outline-level: 2;">
<br />
<br />
<pre style="background-color: black; border-radius: 4px; border: 1px solid black; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; font-style: italic; line-height: 1.42857; margin-bottom: 10px; overflow-wrap: break-word; overflow: auto; padding: 9.5px; word-break: break-all; word-spacing: 1px;"><span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;">#include</span> <span class="cpf" style="box-sizing: border-box; color: #999999;"><iostream></span><span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;"></span>
<span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;">#include</span> <span class="cpf" style="box-sizing: border-box; color: #999999;"><cstring></span><span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;"></span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">using</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">namespace</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">std</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="kt" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">int</span> <span class="nf" style="box-sizing: border-box; color: #447fcf;">main</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">(){</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">struct</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">student</span>
<span class="p" style="box-sizing: border-box; color: #d0d0d0;">{</span>
<span class="kt" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">int</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">string</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="kt" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">int</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">phone_number</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="p" style="box-sizing: border-box; color: #d0d0d0;">};</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">struct</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">student</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p1</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="p" style="box-sizing: border-box; color: #d0d0d0;">{</span><span class="mi" style="box-sizing: border-box; color: #3677a9;">1</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">,</span><span class="s" style="box-sizing: border-box; color: #ed9d13;">"Brown"</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">,</span><span class="mi" style="box-sizing: border-box; color: #3677a9;">123443</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">};</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">struct</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">student</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">,</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="mi" style="box-sizing: border-box; color: #3677a9;">2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"Sam"</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">phone_number</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="mi" style="box-sizing: border-box; color: #3677a9;">1234567822</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="mi" style="box-sizing: border-box; color: #3677a9;">3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"Addy"</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">phone_number</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="mi" style="box-sizing: border-box; color: #3677a9;">1234567844</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"First Student"</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"roll no : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p1</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"name : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p1</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"phone no : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p1</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">phone_number</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"Second Student"</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"roll no : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"name : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"phone no : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p2</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">phone_number</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"Third Student"</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"roll no : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"name : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="s" style="box-sizing: border-box; color: #ed9d13;">"phone no : "</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">p3</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">phone_number</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">return</span> <span class="mi" style="box-sizing: border-box; color: #3677a9;">0</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="p" style="box-sizing: border-box; color: #d0d0d0;">}</span></pre>
<br />
<br />
<br />
<br />
<br />
<header class="entry-header" style="background-color: white; box-sizing: border-box; color: #222426; font-family: "PT Sans", Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 17px;"><h1 class="entry-title" itemprop="headline" style="box-sizing: border-box; color: #444542; font-family: "PT Sans", "Trebuchet MS", "Lucida Grande", Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 30px; line-height: 1.2; margin: 0px 0px 16px;">
Structure and Function in C++</h1>
</header><br />
<div class="entry-content" itemprop="text" style="box-sizing: border-box;">
<div style="background-color: white; box-sizing: border-box; color: #222426; font-family: "pt sans", arial, "helvetica neue", helvetica, sans-serif; font-size: 17px; margin-bottom: 26px; padding: 0px;">
In this <a href="https://beginnersbook.com/2017/09/cpp-structures/" style="box-sizing: border-box; color: #7dc246; font-weight: bold !important; text-decoration-line: none; transition: all 0.1s ease-in-out 0s;">previous tutorial</a> we learnt about structures, the compound data type that groups different types of variables. In this tutorial, we will learn how to pass structures as an argument to the function and how to return the structure from the function.</div>
<h2 style="background-color: white; box-sizing: border-box; color: #444542; font-family: "pt sans", "trebuchet ms", "lucida grande", arial, "helvetica neue", helvetica, sans-serif; font-size: 26px; line-height: 1.2; margin: 0px 0px 16px;">
How to pass structure as an argument to function</h2>
<div style="background-color: white; box-sizing: border-box; color: #222426; font-family: "pt sans", arial, "helvetica neue", helvetica, sans-serif; font-size: 17px; margin-bottom: 26px; padding: 0px;">
Here we have a function <code style="background-color: #eeeeee; box-sizing: border-box; font-family: "PT Sans", Arial, "Helvetica Neue", Helvetica, sans-serif;">printStudentInfo()</code> which takes structure <code style="background-color: #eeeeee; box-sizing: border-box; font-family: "PT Sans", Arial, "Helvetica Neue", Helvetica, sans-serif;">Student</code> as an argument and prints the details of student using structure varaible. The important point to note here is that you should always declare the structure before function declarations, otherwise you will get compilation error.</div>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="com" style="box-sizing: border-box; color: grey;">#include</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: maroon;"><iostream></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">using</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">namespace</span><span class="pln" style="box-sizing: border-box; color: black;"> std</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">struct</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pun" style="box-sizing: border-box; color: black;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">char</span><span class="pln" style="box-sizing: border-box; color: black;"> stuName</span><span class="pun" style="box-sizing: border-box; color: black;">[</span><span class="lit" style="box-sizing: border-box; color: maroon;">30</span><span class="pun" style="box-sizing: border-box; color: black;">];</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> stuRollNo</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> stuAge</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">};</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">void</span><span class="pln" style="box-sizing: border-box; color: black;"> printStudentInfo</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pun" style="box-sizing: border-box; color: black;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> main</span><span class="pun" style="box-sizing: border-box; color: black;">(){</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pln" style="box-sizing: border-box; color: black;"> s</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Enter Student Name: "</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cin</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">getline</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">stuName</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">30</span><span class="pun" style="box-sizing: border-box; color: black;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Enter Student Roll No: "</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cin</span><span class="pun" style="box-sizing: border-box; color: black;">>></span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">stuRollNo</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Enter Student Age: "</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cin</span><span class="pun" style="box-sizing: border-box; color: black;">>></span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">stuAge</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
printStudentInfo</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">0</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">void</span><span class="pln" style="box-sizing: border-box; color: black;"> printStudentInfo</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pln" style="box-sizing: border-box; color: black;"> s</span><span class="pun" style="box-sizing: border-box; color: black;">){</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Student Record:"</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">endl</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Name: "</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">stuName</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">endl</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Roll No: "</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">stuRollNo</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">endl</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="str" style="box-sizing: border-box; color: maroon;">"Age: "</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">s</span><span class="pun" style="box-sizing: border-box; color: black;">.</span><span class="pln" style="box-sizing: border-box; color: black;">stuAge</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span></pre>
<div style="background-color: white; box-sizing: border-box; color: #222426; font-family: "pt sans", arial, "helvetica neue", helvetica, sans-serif; font-size: 17px; margin-bottom: 26px; padding: 0px;">
<span style="box-sizing: border-box; font-weight: 700;">Output:</span></div>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="typ" style="box-sizing: border-box; color: #2b91af;">Enter</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Name</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Rick</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Enter</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Roll</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">No</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">666123</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Enter</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Age</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">19</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Student</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Record</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Name</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Rick</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Roll</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="typ" style="box-sizing: border-box; color: #2b91af;">No</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">666123</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="typ" style="box-sizing: border-box; color: #2b91af;">Age</span><span class="pun" style="box-sizing: border-box; color: black;">:</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">19</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="lit" style="box-sizing: border-box; color: maroon;">
</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="lit" style="box-sizing: border-box; color: maroon;">
</span></pre>
<pre class="prettyprint prettyprinted" style="box-sizing: border-box; clear: both; overflow: auto; padding: 2px;"><span class="lit" style="box-sizing: border-box; color: maroon;"><h2 style="background-color: white; box-sizing: border-box; color: #333333; font-family: "noto sans", sans-serif; font-size: 30px; font-weight: 500; line-height: 1.1; margin-bottom: 10px; margin-top: 20px; white-space: normal; word-spacing: 2px;">
Array of Structures</h2>
<span style="background-color: #eeeeee; box-sizing: border-box; color: #222426; font-family: "consolas" , "menlo" , "monaco" , "lucida console" , "liberation mono" , "dejavu sans mono" , "bitstream vera sans mono" , "courier new" , monospace , sans-serif; font-size: 13px;">
</span><hr style="background-color: white; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top-color: rgb(238, 238, 238); border-top-style: solid; box-sizing: content-box; color: #333333; font-family: "noto sans", sans-serif; font-size: 16px; height: 0px; margin-bottom: 20px; margin-top: 20px; white-space: normal; word-spacing: 2px;" />
<span style="background-color: #eeeeee; box-sizing: border-box; color: #222426; font-family: "consolas" , "menlo" , "monaco" , "lucida console" , "liberation mono" , "dejavu sans mono" , "bitstream vera sans mono" , "courier new" , monospace , sans-serif; font-size: 13px;">
</span><div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "noto sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
We can also make an array of structures. In the first example in structures, we stored the data of 3 students. Now suppose we need to store the data of 100 such children. Declaring 100 separate variables of the structure is definitely not a good option. For that, we need to create an array of structures.</div>
<span style="background-color: #eeeeee; box-sizing: border-box; color: #222426; font-family: "consolas" , "menlo" , "monaco" , "lucida console" , "liberation mono" , "dejavu sans mono" , "bitstream vera sans mono" , "courier new" , monospace , sans-serif; font-size: 13px;">
</span><div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "noto sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
Let's see an example for 5 students.</div>
<span style="background-color: #eeeeee; box-sizing: border-box; color: #222426; font-family: "consolas" , "menlo" , "monaco" , "lucida console" , "liberation mono" , "dejavu sans mono" , "bitstream vera sans mono" , "courier new" , monospace , sans-serif; font-size: 13px;">
</span></span><span style="box-sizing: border-box;">#include <iostream>
#include <cstring>
using namespace std;</span><span style="box-sizing: border-box;">
struct student
{
int roll_no;
string name;
int phone_number;
};
int main(){
struct student stud[5];
int i;
for(i=0; i<5; i++)</span></pre>
<pre class="prettyprint prettyprinted" style="box-sizing: border-box; clear: both; overflow: auto; padding: 2px;"><span style="box-sizing: border-box;">{ //taking values from user
cout << "Student " << i + 1 << endl;
cout << "Enter roll no" << endl;
cin >> stud[i].roll_no;
cout << "Enter name" << endl;
cin >> stud[i].name;
cout << "Enter phone number" << endl;
cin >> stud[i].phone_number;
}
for(i=0; i<5; i++)</span></pre>
<pre class="prettyprint prettyprinted" style="box-sizing: border-box; clear: both; overflow: auto; padding: 2px;"><span style="box-sizing: border-box;">{ //printing values
cout << "Student " << i + 1 << endl;
cout << "Roll no : " << stud[i].roll_no << endl;
cout << "Name : " << stud[i].name << endl;
cout << "Phone no : " << stud[i].phone_number << endl;
}
return 0;
}</span><span class="lit" style="box-sizing: border-box; color: maroon;"><span style="background-color: #eeeeee; box-sizing: border-box; color: #222426; font-family: "consolas" , "menlo" , "monaco" , "lucida console" , "liberation mono" , "dejavu sans mono" , "bitstream vera sans mono" , "courier new" , monospace , sans-serif; font-size: 13px;">
</span></span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="lit" style="box-sizing: border-box; color: maroon;">
</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="lit" style="box-sizing: border-box; color: maroon;">
</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="lit" style="box-sizing: border-box; color: maroon;"><h2 style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 30px; font-weight: 500; line-height: 1.1; margin-bottom: 10px; margin-top: 20px; white-space: normal; word-spacing: 2px;">
Pointers to Structures</h2>
<hr style="background-color: white; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 0px; border-top-color: rgb(238, 238, 238); border-top-style: solid; box-sizing: content-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; height: 0px; margin-bottom: 20px; margin-top: 20px; white-space: normal; word-spacing: 2px;" />
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
Like we have pointers to int, char and other data-types, we also have pointers pointing to structures. These pointers are called <span style="box-sizing: border-box; font-weight: 700;">structure pointers</span>.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
Now, how to define a pointer to a structure? The answer is below:</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
<span style="box-sizing: border-box; font-weight: 700;"><span style="box-sizing: border-box; color: brown;">struct</span> structure_name
<span style="box-sizing: border-box; color: blue;">{</span>
<span style="box-sizing: border-box; color: brown;">data-type</span> member-1<span style="box-sizing: border-box; color: brown;">;</span>
<span style="box-sizing: border-box; color: brown;">data-type</span> member-1<span style="box-sizing: border-box; color: brown;">;</span>
<span style="box-sizing: border-box; color: brown;">data-type</span> member-1<span style="box-sizing: border-box; color: brown;">;</span>
<span style="box-sizing: border-box; color: brown;">data-type</span> member-1<span style="box-sizing: border-box; color: brown;">;</span>
<span style="box-sizing: border-box; color: blue;">}</span><span style="box-sizing: border-box; color: brown;">;</span>
<span style="box-sizing: border-box; color: brown;">int</span> main<span style="box-sizing: border-box; color: blue;">()</span>
<span style="box-sizing: border-box; color: brown;">{</span>
<span style="box-sizing: border-box; color: brown;">struct</span> structure_name *ptr<span style="box-sizing: border-box; color: brown;">;</span>
<span style="box-sizing: border-box; color: blue;">}</span></span></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
Let's see an example using structure pointer.</div>
<pre style="background-color: black; border-radius: 4px; border: 1px solid black; box-sizing: border-box; color: #333333; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-style: italic; line-height: 1.42857; margin-bottom: 10px; overflow-wrap: break-word; overflow: auto; padding: 9.5px; word-break: break-all; word-spacing: 1px;"><span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;">#include</span> <span class="cpf" style="box-sizing: border-box; color: #999999;"><iostream></span><span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;"></span>
<span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;">#include</span> <span class="cpf" style="box-sizing: border-box; color: #999999;"><cstring></span><span class="cp" style="box-sizing: border-box; color: #cd2828; font-weight: bold;"></span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">using</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">namespace</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">std</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">struct</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">student</span>
<span class="p" style="box-sizing: border-box; color: #d0d0d0;">{</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">string</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="kt" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">int</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="p" style="box-sizing: border-box; color: #d0d0d0;">};</span>
<span class="kt" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">int</span> <span class="nf" style="box-sizing: border-box; color: #447fcf;">main</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">(){</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">struct</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">student</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">stud</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="p" style="box-sizing: border-box; color: #d0d0d0;">{</span><span class="s" style="box-sizing: border-box; color: #ed9d13;">"Sam"</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">,</span><span class="mi" style="box-sizing: border-box; color: #3677a9;">1</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">};</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">struct</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">student</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">*</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">ptr</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">ptr</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">=</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;">&</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">stud</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">stud</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">stud</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">.</span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="n" style="box-sizing: border-box; color: #d0d0d0;">cout</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">ptr</span><span class="o" style="box-sizing: border-box; color: #d0d0d0;">-></span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">name</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">ptr</span><span class="o" style="box-sizing: border-box; color: #d0d0d0;">-></span><span class="n" style="box-sizing: border-box; color: #d0d0d0;">roll_no</span> <span class="o" style="box-sizing: border-box; color: #d0d0d0;"><<</span> <span class="n" style="box-sizing: border-box; color: #d0d0d0;">endl</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="k" style="box-sizing: border-box; color: #6ab825; font-weight: bold;">return</span> <span class="mi" style="box-sizing: border-box; color: #3677a9;">0</span><span class="p" style="box-sizing: border-box; color: #d0d0d0;">;</span>
<span class="p" style="box-sizing: border-box; color: #d0d0d0;">}</span></pre>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Noto Sans", sans-serif; font-size: 16px; margin-bottom: 10px; white-space: normal; word-spacing: 2px;">
</div>
</span></pre>
</div>
</div>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-91369798741864079742019-06-14T03:33:00.000-07:002019-06-14T10:39:09.627-07:00Dynamic memory allocation <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="outline-2" id="outline-container-org4a16795" style="font-family: verdana, sans-serif;">
<h1 style="font-size: 1.7em; margin: 0px; padding: 0px;">
Dynamic memory allocation with new and delete</h1>
<h2 id="org4a16795" style="line-height: 1;">
<div class="post-headline" style="background-color: white; font-family: verdana, arial, sans-serif; font-size: 13px; font-weight: 400;">
</div>
<div class="post-byline" style="background-color: white; color: #999999; font-family: verdana, arial, sans-serif; font-size: 11px; font-weight: 400; letter-spacing: 1px; margin: 5px 0px 10px; text-transform: uppercase;">
BY ALEX ON JULY 13TH, 2007 | LAST MODIFIED BY ALEX ON APRIL 24TH, 2019</div>
<div class="post-bodycopy clearfix" style="background-color: white; font-family: verdana, arial, sans-serif; font-weight: 400; min-width: 0px;">
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>The need for dynamic memory allocation</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C++ supports three basic types of memory allocation, of which you’ve already seen two.</div>
<ul style="font-size: 13px; list-style-position: inside; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;">
<li><strong>Static memory allocation</strong> happens for static and global variables. Memory for these types of variables is allocated once when your program is run and persists throughout the life of your program.</li>
<li><strong>Automatic memory allocation</strong> happens for function parameters and local variables. Memory for these types of variables is allocated when the relevant block is entered, and freed when the block is exited, as many times as necessary.</li>
<li><strong>Dynamic memory allocation</strong> is the topic of this article.</li>
</ul>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Both static and automatic allocation have two things in common:</div>
<ul style="font-size: 13px; list-style-position: inside; margin-bottom: 10px; margin-top: 10px; padding-bottom: 0px; padding-top: 0px;">
<li>The size of the variable / array must be known at compile time.</li>
<li>Memory allocation and deallocation happens automatically (when the variable is instantiated / destroyed).</li>
</ul>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Most of the time, this is just fine. However, you will come across situations where one or both of these constraints cause problems, usually when dealing with external (user or file) input.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
For example, we may want to use a string to hold someone’s name, but we do not know how long their name is until they enter it. Or we may want to read in a number of records from disk, but we don’t know in advance how many records there are. Or we may be creating a game, with a variable number of monsters (that changes over time as some monsters die and new ones are spawned) trying to kill the player.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
If we have to declare the size of everything at compile time, the best we can do is try to make a guess the maximum size of variables we’ll need and hope that’s enough:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55fd0095411864" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55fd0095411864-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fd0095411864-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fd0095411864-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fd0095411864-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55fd0095411864-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">char</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">name</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">[</span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">25</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">]</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// let's hope their name is less than 25 chars!</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fd0095411864-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">Record </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">record</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">[</span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">500</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">]</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// let's hope there are less than 500 records!</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55fd0095411864-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">Monster </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">monster</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">[</span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">40</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">]</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// 40 monsters maximum</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fd0095411864-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">Polygon </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">rendering</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">[</span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">30000</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">]</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// this 3d rendering better not have more than 30,000 polygons!</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
This is a poor solution for at least four reasons:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
First, it leads to wasted memory if the variables aren’t actually used. For example, if we allocate 25 chars for every name, but names on average are only 12 chars long, we’re using over twice what we really need. Or consider the rendering array above: if a rendering only uses 10,000 polygons, we have 20,000 Polygons worth of memory not being used!</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Second, how do we tell which bits of memory are actually used? For strings, it’s easy: a string that starts with a \0 is clearly not being used. But what about monster[24]? Is it alive or dead right now? That necessitates having some way to tell active from inactive items, which adds complexity and can use up additional memory.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Third, most normal variables (including fixed arrays) are allocated in a portion of memory called the <strong>stack</strong>. The amount of stack memory for a program is generally quite small -- Visual Studio defaults the stack size to 1MB. If you exceed this number, stack overflow will result, and the operating system will probably close down the program.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
On Visual Studio, you can see this happen when running this program:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55fde538874094" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55fde538874094-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fde538874094-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fde538874094-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fde538874094-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55fde538874094-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">main</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fde538874094-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">{</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55fde538874094-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">array</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">[</span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">1000000</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">]</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// allocate 1 million integers (probably 4MB of memory)</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fde538874094-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">}</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Being limited to just 1MB of memory would be problematic for many programs, especially those that deal with graphics.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Fourth, and most importantly, it can lead to artificial limitations and/or array overflows. What happens when the user tries to read in 600 records from disk, but we’ve only allocated memory for a maximum of 500 records? Either we have to give the user an error, only read the 500 records, or (in the worst case where we don’t handle this case at all) overflow the record array and watch something bad happen.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Fortunately, these problems are easily addressed via dynamic memory allocation. <strong>Dynamic memory allocation</strong> is a way for running programs to request memory from the operating system when needed. This memory does not come from the program’s limited stack memory -- instead, it is allocated from a much larger pool of memory managed by the operating system called the <strong>heap</strong>. On modern machines, the heap can be gigabytes in size.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Dynamically allocating single variables</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
To allocate a <em>single</em> variable dynamically, we use the scalar (non-array) form of the <strong>new</strong> operator:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55fe3585040353" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55fe3585040353-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55fe3585040353-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// dynamically allocate an integer (and discard the result)</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
In the above case, we’re requesting an integer’s worth of memory from the operating system. The new operator creates the object using that memory, and then returns a pointer containing the <i>address</i> of the memory that has been allocated.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Most often, we’ll assign the return value to our own pointer variable so we can access the allocated memory later.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55ff2605700518" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55ff2605700518-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55ff2605700518-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// dynamically allocate an integer and assign the address to ptr so we can access it later</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
We can then dereference the pointer to access the memory:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55ff6767481922" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55ff6767481922-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55ff6767481922-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">7</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// assign value of 7 to allocated memory</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
If it wasn’t before, it should now be clear at least one case in which pointers are useful. Without a pointer to hold the address of the memory that was just allocated, we’d have no way to access the memory that was just allocated for us!</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>How does dynamic memory allocation work?</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Your computer has memory (probably lots of it) that is available for applications to use. When you run an application, your operating system loads the application into some of that memory. This memory used by your application is divided into different areas, each of which serves a different purpose. One area contains your code. Another area is used for normal operations (keeping track of which functions were called, creating and destroying global and local variables, etc…). We’ll talk more about those later. However, much of the memory available just sits there, waiting to be handed out to programs that request it.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
When you dynamically allocate memory, you’re asking the operating system to reserve some of that memory for your program’s use. If it can fulfill this request, it will return the address of that memory to your application. From that point forward, your application can use this memory as it wishes. When your application is done with the memory, it can return the memory back to the operating system to be given to another program.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<div style="font-size: 13px;">
Unlike static or automatic memory, the program itself is responsible for requesting and disposing of dynamically allocated memory.<span style="font-family: "roboto" , sans-serif , "arial" , "verdana" , "tahoma"; font-size: 16px;">To allocate space dynamically, use the unary operator</span><span style="font-family: "roboto" , sans-serif , "arial" , "verdana" , "tahoma"; font-size: 16px;"> </span><em style="background-color: #f9f9f9; border-radius: 2px; box-sizing: border-box; display: inline-block; font-family: Roboto, sans-serif, Arial, Verdana, Tahoma; font-size: 16px; padding: 0px 4px;">new</em><span style="font-family: "roboto" , sans-serif , "arial" , "verdana" , "tahoma"; font-size: 16px;">, followed by the type being allocated.</span></div>
<div style="font-size: 13px;">
<span style="font-family: "roboto" , sans-serif , "arial" , "verdana" , "tahoma"; font-size: 16px;"><br /></span></div>
<div style="font-size: 13px;">
<span style="font-family: "roboto" , sans-serif , "arial" , "verdana" , "tahoma"; font-size: 16px;"><br /></span></div>
<span style="font-family: "roboto" , sans-serif , "arial" , "verdana" , "tahoma";"><span style="color: blue; font-size: large;">EXAMPLE 1:</span></span><br />
<div style="box-sizing: border-box; font-family: Roboto, sans-serif, Arial, Verdana, Tahoma; font-size: 16px; line-height: 1.7em; margin-bottom: 1rem;">
<span style="box-sizing: border-box; text-decoration-line: underline;">Here is a code snippet showing the use of <em style="background-color: #f9f9f9; border-radius: 2px; box-sizing: border-box; display: inline-block; padding: 0px 4px;">new</em>:</span></div>
<pre style="background-color: rgba(247, 247, 247, 0.4); border-radius: 4px; border: 2px solid rgb(204, 204, 204); box-shadow: rgb(221, 221, 221) 0px 3px 0px; box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 16px; margin-bottom: 20px; max-height: 600px; overflow-wrap: initial; overflow: auto; padding: 8px; position: relative; tab-size: 4; word-break: initial;"><code class="prettyprint prettyprinted" style="box-sizing: border-box; color: #111111; display: block; font-family: "Source Code Pro", monospace; font-size: inherit; overflow-wrap: break-word; tab-size: 4; width: 839.328px; word-break: break-all;"><span class="kwd" style="box-sizing: border-box; color: #000088;">new</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">//dynamically allocates an integer type</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">new</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">double</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">// dynamically allocates an double type</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">new</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="lit" style="box-sizing: border-box; color: #006666;">60</span><span class="pun" style="box-sizing: border-box; color: #666600;">];</span></code></pre>
<div style="box-sizing: border-box; font-family: Roboto, sans-serif, Arial, Verdana, Tahoma; font-size: 16px; line-height: 1.7em; margin-bottom: 1rem;">
The above-declared statements are not so useful as the allocated space has no names. But the lines written below are useful:</div>
<pre style="background-color: rgba(247, 247, 247, 0.4); border-radius: 4px; border: 2px solid rgb(204, 204, 204); box-shadow: rgb(221, 221, 221) 0px 3px 0px; box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 16px; margin-bottom: 20px; max-height: 600px; overflow-wrap: initial; overflow: auto; padding: 8px; position: relative; tab-size: 4; word-break: initial;"><code class="prettyprint prettyprinted" style="box-sizing: border-box; color: #111111; display: block; font-family: "Source Code Pro", monospace; font-size: inherit; overflow-wrap: break-word; tab-size: 4; width: 839.328px; word-break: break-all;"><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box; color: black;"> p</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">// declares a pointer p</span><span class="pln" style="box-sizing: border-box; color: black;">
p </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">new</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">// dynamically allocate an int for loading the address in p</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">double</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box; color: black;"> d</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">// declares a pointer d</span><span class="pln" style="box-sizing: border-box; color: black;">
d </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">new</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">double</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">// dynamically allocate a double and loading the address in p</span></code></pre>
<div style="font-size: 13px;">
<br /></div>
<div style="box-sizing: border-box; font-family: Roboto, sans-serif, Arial, Verdana, Tahoma; font-size: 16px; line-height: 1.7em; margin-bottom: 1rem;">
<span style="box-sizing: border-box; text-decoration-line: underline;">Here is a simple program showing the concept of dynamic memory allocation:</span></div>
<div class="example" style="box-sizing: border-box; color: #ed143d; display: inline-block; font-family: Roboto, sans-serif, Arial, Verdana, Tahoma; font-size: 14.4px; text-decoration-line: underline; user-select: none;">
Example:</div>
<pre style="background-color: rgba(247, 247, 247, 0.4); border-radius: 4px; border: 2px solid rgb(204, 204, 204); box-shadow: rgb(221, 221, 221) 0px 3px 0px; box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 16px; margin-bottom: 20px; max-height: 600px; overflow-wrap: initial; overflow: auto; padding: 8px; position: relative; tab-size: 4; word-break: initial;"><code class="prettyprint prettyprinted" style="box-sizing: border-box; color: #111111; display: block; font-family: "Source Code Pro", monospace; font-size: inherit; overflow-wrap: break-word; tab-size: 4; width: 839.328px; word-break: break-all;"><span class="com" style="box-sizing: border-box; color: #880000;">#include</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: #008800;"><iostream></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">using</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">namespace</span><span class="pln" style="box-sizing: border-box; color: black;"> std</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> main</span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">double</span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box; color: black;"> val </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> NULL</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
val </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">new</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">double</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box; color: black;">val </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">38184.26</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Value is : "</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box; color: black;">val </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box; color: black;"> endl</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">delete</span><span class="pln" style="box-sizing: border-box; color: black;"> val</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span></code></pre>
<div style="font-size: 13px;">
<br /></div>
<div style="font-size: 13px;">
<span style="color: lime;"><br /></span></div>
<span style="color: lime; font-size: large;">EXAMPLE 2:</span><br />
<div style="font-size: 13px;">
<br /></div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Initializing a dynamically allocated variable</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
When you dynamically allocate a variable, you can also initialize it via direct initialization or uniform initialization (in C++11):</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55ff9987211970" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55ff9987211970-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55ff9987211970-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55ff9987211970-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr1</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">5</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// use direct initialization</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55ff9987211970-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr2</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">{</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">6</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">}</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// use uniform initialization</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Deleting single variables</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
When we are done with a dynamically allocated variable, we need to explicitly tell C++ to free the memory for reuse. For single variables, this is done via the scalar (non-array) form of the <strong>delete</strong> operator:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55ffc571688027" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55ffc571688027-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55ffc571688027-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55ffc571688027-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55ffc571688027-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// assume ptr has previously been allocated with operator new</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55ffc571688027-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// return the memory pointed to by ptr to the operating system</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55ffc571688027-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">0</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// set ptr to be a null pointer (use nullptr instead of 0 in C++11)</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>What does it mean to delete memory?</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
The delete operator does not <em>actually</em> delete anything. It simply returns the memory being pointed to back to the operating system. The operating system is then free to reassign that memory to another application (or to this application again later).</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Although it looks like we’re deleting a <em>variable</em>, this is not the case! The pointer variable still has the same scope as before, and can be assigned a new value just like any other variable.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Note that deleting a pointer that is not pointing to dynamically allocated memory may cause bad things to happen.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Dangling pointers</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
C++ does not make any guarantees about what will happen to the contents of deallocated memory, or to the value of the pointer being deleted. In most cases, the memory returned to the operating system will contain the same values it had before it was returned, and the pointer will be left pointing to the now deallocated memory.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
A pointer that is pointing to deallocated memory is called a <strong>dangling pointer</strong>. Dereferencing or deleting a dangling pointer will lead to undefined behavior. Consider the following program:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc55fff245380916" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-5" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
5</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-6" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
6</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-7" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
7</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-8" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
8</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-9" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
9</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-10" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
10</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-11" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
11</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-12" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
12</div>
<div class="crayon-num" data-line="crayon-5d03a9bc55fff245380916-13" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
13</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc55fff245380916-14" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
14</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 838px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-p" style="color: rgb(184 , 92 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">#include <iostream></span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">main</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">{</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-5" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// dynamically allocate an integer</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-6" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">7</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// put a value in that memory location</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-7" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-8" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// return the memory to the operating system. ptr is now a dangling pointer.</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-9" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-10" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">std</span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">::</span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">cout</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"><<</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// Dereferencing a dangling pointer will cause undefined behavior</span></div>
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-11" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// trying to deallocate the memory again will also lead to undefined behavior.</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-12" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line" id="crayon-5d03a9bc55fff245380916-13" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-st" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">return</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">0</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc55fff245380916-14" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">}</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
In the above program, the value of 7 that was previously assigned to the allocated memory will probably still be there, but it’s possible that the value at that memory address could have changed. It’s also possible the memory could be allocated to another application (or for the operating system’s own usage), and trying to access that memory will cause the operating system to shut the program down.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Deallocating memory may create multiple dangling pointers. Consider the following example:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc56008537898010" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-5" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
5</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-6" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
6</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-7" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
7</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-8" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
8</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-9" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
9</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-10" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
10</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-11" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
11</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-12" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
12</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56008537898010-13" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
13</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56008537898010-14" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
14</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 838px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-p" style="color: rgb(184 , 92 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">#include <iostream></span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">main</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">{</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-5" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// dynamically allocate an integer</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-6" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">otherPtr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// otherPtr is now pointed at that same memory location</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-7" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-8" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// return the memory to the operating system. ptr and otherPtr are now dangling pointers.</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-9" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">0</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// ptr is now a nullptr</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-10" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-11" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// however, otherPtr is still a dangling pointer!</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-12" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
</div>
<div class="crayon-line" id="crayon-5d03a9bc56008537898010-13" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-st" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">return</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">0</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56008537898010-14" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">}</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
There are a few best practices that can help here.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
First, try to avoid having multiple pointers point at the same piece of dynamic memory. If this is not possible, be clear about which pointer “owns” the memory (and is responsible for deleting it) and which are just accessing it.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Second, when you delete a pointer, if that pointer is not going out of scope immediately afterward, set the pointer to 0 (or nullptr in C++11). We’ll talk more about null pointers, and why they are useful in a bit.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<em>Rule: Set deleted pointers to 0 (or nullptr in C++11) unless they are going out of scope immediately afterward.</em></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Operator new can fail</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
When requesting memory from the operating system, in rare circumstances, the operating system may not have any memory to grant the request with.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
By default, if new fails, a <em>bad_alloc</em> exception is thrown. If this exception isn’t properly handled (and it won’t be, since we haven’t covered exceptions or exception handling yet), the program will simply terminate (crash) with an unhandled exception error.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
In many cases, having new throw an exception (or having your program crash) is undesirable, so there’s an alternate form of new that can be used instead to tell new to return a null pointer if memory can’t be allocated. This is done by adding the constant std::nothrow between the new keyword and the allocation type:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc5600c716587042" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc5600c716587042-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc5600c716587042-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">value</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">std</span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">::</span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">nothrow</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// value will be set to a null pointer if the integer allocation fails</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
In the above example, if new fails to allocate memory, it will return a null pointer instead of the address of the allocated memory.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Note that if you then attempt to dereference this memory, undefined behavior will result (most likely, your program will crash). Consequently, the best practice is to check all memory requests to ensure they actually succeeded before using the allocated memory.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc5600f816909241" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc5600f816909241-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc5600f816909241-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc5600f816909241-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc5600f816909241-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
<div class="crayon-num" data-line="crayon-5d03a9bc5600f816909241-5" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
5</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc5600f816909241-6" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
6</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc5600f816909241-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">value</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">std</span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">::</span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">nothrow</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// ask for an integer's worth of memory</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc5600f816909241-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-st" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">if</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">!</span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">value</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// handle case where new returned null</span></div>
<div class="crayon-line" id="crayon-5d03a9bc5600f816909241-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">{</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc5600f816909241-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// Do error handling here</span></div>
<div class="crayon-line" id="crayon-5d03a9bc5600f816909241-5" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">std</span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">::</span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">cout</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"><<</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-s" style="color: rgb(206 , 0 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">"Could not allocate memory"</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc5600f816909241-6" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">}</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Because asking new for memory only fails rarely (and almost never in a dev environment), it’s common to forget to do this check!</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Null pointers and dynamic memory allocation</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Null pointers (pointers set to address 0 or nullptr) are particularly useful when dealing with dynamic memory allocation. In the context of dynamic memory allocation, a null pointer basically says “no memory has been allocated to this pointer”. This allows us to do things like conditionally allocate memory:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc56017673286174" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc56017673286174-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56017673286174-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56017673286174-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc56017673286174-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// If ptr isn't already allocated, allocate it</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56017673286174-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-st" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">if</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">!</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56017673286174-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Deleting a null pointer has no effect. Thus, there is no need for the following:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc5601b401186228" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc5601b401186228-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc5601b401186228-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc5601b401186228-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-st" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">if</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc5601b401186228-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Instead, you can just write:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc5601e825707913" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc5601e825707913-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc5601e825707913-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
If ptr is non-null, the dynamically allocated variable will be deleted. If it is null, nothing will happen.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Memory leaks</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dynamically allocated memory stays allocated until it is explicitly deallocated or until the program ends (and the operating system cleans it up, assuming your operating system does that). However, the pointers used to hold dynamically allocated memory addresses follow the normal scoping rules for local variables. This mismatch can create interesting problems.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Consider the following function:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc56021834108500" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc56021834108500-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56021834108500-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56021834108500-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56021834108500-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc56021834108500-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">void</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">doSomething</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">(</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">)</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56021834108500-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">{</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56021834108500-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56021834108500-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">}</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
This function allocates an integer dynamically, but never frees it using delete. Because pointers variables are just normal variables, when the function ends, ptr will go out of scope. And because ptr is the only variable holding the address of the dynamically allocated integer, when ptr is destroyed there are no more references to the dynamically allocated memory. This means the program has now “lost” the address of the dynamically allocated memory. As a result, this dynamically allocated integer can not be deleted.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
This is called a <strong>memory leak</strong>. Memory leaks happen when your program loses the address of some bit of dynamically allocated memory before giving it back to the operating system. When this happens, your program can’t delete the dynamically allocated memory, because it no longer knows where it is. The operating system also can’t use this memory, because that memory is considered to be still in use by your program.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Memory leaks eat up free memory while the program is running, making less memory available not only to this program, but to other programs as well. Programs with severe memory leak problems can eat all the available memory, causing the entire machine to run slowly or even crash. Only after your program terminates is the operating system able to clean up and “reclaim” all leaked memory.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Although memory leaks can result from a pointer going out of scope, there are other ways that memory leaks can result. For example, a memory leak can occur if a pointer holding the address of the dynamically allocated memory is assigned another value:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc56024868439280" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc56024868439280-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56024868439280-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56024868439280-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc56024868439280-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">value</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">5</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56024868439280-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// allocate memory</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56024868439280-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">&value</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// old address lost, memory leak results</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
This can be fixed by deleting the pointer before reassigning it:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc56027425171745" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row alt" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: rgb(244, 244, 244); border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc56027425171745-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56027425171745-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
<div class="crayon-num" data-line="crayon-5d03a9bc56027425171745-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
3</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc56027425171745-4" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
4</div>
</div>
</td><td class="crayon-code" style="background: rgb(244, 244, 244); border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc56027425171745-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">value</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-cn" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">5</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56027425171745-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// allocate memory</span></div>
<div class="crayon-line" id="crayon-5d03a9bc56027425171745-3" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-e" style="color: rgb(0 , 78 , 208); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">delete </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// return memory back to operating system</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc56027425171745-4" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">&value</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// reassign pointer to address of value</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Relatedly, it is also possible to get a memory leak via double-allocation:</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div class="crayon-syntax crayon-theme-familiar-learncppcom crayon-font-monaco crayon-os-pc print-yes notranslate crayon-wrapped" data-settings=" no-popup minimize scroll-mouseover wrap" id="crayon-5d03a9bc5603d517525141" style="border-width: 1px; box-sizing: border-box; direction: ltr; font-family: monaco, monacoregular, "courier new", monospace; font-size: 12px; height: auto; line-height: 16px; margin: 12px 0px; overflow: hidden; padding: 0px; position: relative; text-shadow: none; width: 871px;">
<div class="crayon-plain-wrap" style="background: 0px center; border: 0px; height: auto !important; margin: 0px !important; padding: 0px !important;">
</div>
<div class="crayon-main" style="background: 0px center; border: 0px; margin: 0px; overflow: hidden; padding: 0px; position: relative; width: 871px; z-index: 1;">
<table class="crayon-table" style="background: none !important; border-collapse: collapse !important; border-spacing: 0px !important; border: none !important; font-size: 12px; margin-bottom: 0px !important; margin-left: 0px; margin-right: 0px !important; margin-top: 0px !important; padding: 0px !important; table-layout: auto !important; width: auto !important;"><tbody>
<tr class="crayon-row" style="background: 0px center; border: none !important; margin: 0px !important; padding: 0px !important; vertical-align: top !important;"><td class="crayon-nums " data-settings="show" style="background: 0px center; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 3px solid rgb(108, 226, 108) !important; border-top: 0px; color: rgb(175, 175, 175) !important; margin: 0px !important; padding: 0px 5px 0px 0px !important; vertical-align: top !important;"><div class="crayon-nums-content" style="background: 0px center; border: 0px; line-height: 16px !important; margin: 0px; padding: 0px; white-space: nowrap;">
<div class="crayon-num" data-line="crayon-5d03a9bc5603d517525141-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
1</div>
<div class="crayon-num crayon-striped-num" data-line="crayon-5d03a9bc5603d517525141-2" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: 16px; line-height: inherit !important; margin: 0px; padding: 0px 5px; text-align: center;">
2</div>
</div>
</td><td class="crayon-code" style="background: 0px center; border: 0px; margin: 0px !important; padding: 0px !important; vertical-align: top !important; width: 845px;"><div class="crayon-pre" style="background: none !important; border: none !important; line-height: 16px !important; margin: 0px; overflow: visible; padding: 0px; tab-size: 4; white-space: pre;">
<div class="crayon-line" id="crayon-5d03a9bc5603d517525141-1" style="background: 0px center; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">*</span><span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span></div>
<div class="crayon-line crayon-striped-line" id="crayon-5d03a9bc5603d517525141-2" style="background: rgb(249, 249, 249) !important; border: 0px; font-family: inherit; font-size: inherit !important; font-weight: inherit !important; height: inherit; line-height: inherit !important; margin: 0px; padding-bottom: 0px; padding-left: 10px !important; padding-right: 5px; padding-top: 0px; white-space: pre-wrap !important; word-break: break-all;">
<span class="crayon-v" style="color: rgb(0 , 45 , 122); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">ptr</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-o" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">=</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-r" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">new</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-t" style="color: rgb(128 , 0 , 128); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">int</span><span class="crayon-sy" style="color: rgb(51 , 51 , 51); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">;</span><span class="crayon-h" style="color: rgb(0 , 111 , 224); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;"> </span><span class="crayon-c" style="color: rgb(0 , 128 , 0); font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit;">// old address lost, memory leak results</span></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
The address returned from the second allocation overwrites the address of the first allocation. Consequently, the first allocation becomes a memory leak!</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Similarly, this can be avoided by ensuring you delete the pointer before reassigning.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<strong>Conclusion</strong></div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Operators new and delete allow us to dynamically allocate single variables for our programs.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Dynamically allocated memory has no scope and will stay allocated until you deallocate it or the program terminates.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
Be careful not to dereference dangling or null pointers.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
In the next lesson, we’ll take a look at using new and delete to allocate and delete arrays.</div>
<div style="font-size: 13px; margin-bottom: 1em; margin-top: 1em; padding: 0px;">
<br /></div>
</div>
</h2>
<h2 id="org4a16795" style="font-size: 14pt; line-height: 1;">
</h2>
<h2 id="org4a16795" style="font-size: 14pt; line-height: 1;">
</h2>
<h2 id="org4a16795" style="font-size: 14pt; line-height: 1;">
</h2>
<h1 class="entry-title" style="border: 0px; box-sizing: border-box; clear: both; font-size: 28px; font-weight: 400; line-height: 1.2; margin: 0px 0px 15px; padding: 0px; vertical-align: baseline;">
Stack vs Heap Memory Allocation</h1>
<h2 id="org4a16795" style="font-size: 14pt; line-height: 1;">
<header class="entry-header" style="border: 0px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-family: Roboto, sans-serif; font-size: 10.8px; font-weight: 400; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;"></header><div class="entry-content" style="border: 0px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-family: Roboto, sans-serif; font-size: 16px; font-weight: 400; line-height: 19px; margin: 0px; padding: 0px; text-align: justify; vertical-align: baseline;">
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
Memory in a C/C++ program can either be allocated on stack or heap.</div>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Stack Allocation :</strong> The allocation happens on contiguous blocks of memory. We call it stack memory allocation because the allocation happens in function call stack. The size of memory to be allocated is known to compiler and whenever a function is called, its variables get memory allocated on the stack. And whenever the function call is over, the memory for the variables is deallocated. This all happens using some predefined routines in compiler. Programmer does not have to worry about memory allocation and deallocation of stack variables.</div>
<div class="code-block" style="border: 0px; box-sizing: border-box; display: flex; flex-direction: row; margin: 0px 0px 10px; padding: 0px; vertical-align: baseline;">
<div class="code-gutter" style="border: 0px; box-sizing: border-box; flex-flow: column; margin: 0px; padding: 0px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons-container" style="border: 0px; bottom: 0px; box-sizing: border-box; left: 0px; margin: 0px; padding: 0px; position: sticky; top: 30px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons" style="align-items: center; border: 0px; box-sizing: border-box; display: flex; flex-flow: column; margin: 0px; padding: 6px 0px 0px; position: sticky; top: 0px; vertical-align: baseline; width: 40px; z-index: 1;">
<div class="editor-buttons-div" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;" title="Run and Edit">
<span class="material-icons code-sidebar-button copy-code-button" id="copy-code-button" style="background: rgb(255 , 255 , 255); border-radius: 50%; border: 0px; box-shadow: rgb(204 , 204 , 204) 1px 1px 2px 2px; box-sizing: border-box; color: #454545; cursor: pointer; direction: ltr; display: inline-block; font-family: "material icons"; font-size: 24px; line-height: 1; margin: 5px 0px 0px; overflow-wrap: normal; padding: 0.15em; transform: rotate(90deg); vertical-align: baseline; white-space: nowrap;" title="Copy Code">filter_none</span><br />
<div style="border: 0px; box-sizing: border-box; line-height: inherit; padding: 0px; text-align: left; vertical-align: baseline;">
<span class="material-icons code-sidebar-button" id="run-and-edit-button" lang="cpp" style="background: rgb(255 , 255 , 255); border-radius: 50%; border: 0px; box-shadow: rgb(204 , 204 , 204) 1px 1px 2px 2px; box-sizing: border-box; color: #454545; cursor: pointer; direction: ltr; display: inline-block; font-family: "material icons"; font-size: 24px; line-height: 1; margin: 5px 0px 0px; overflow-wrap: normal; padding: 0.15em; vertical-align: baseline; white-space: nowrap;" title="Edit Code">edit</span></div>
<div style="border: 0px; box-sizing: border-box; line-height: inherit; padding: 0px; text-align: left; vertical-align: baseline;">
<span class="material-icons code-sidebar-button" id="run-code-button" lang="cpp" style="background: rgb(255 , 255 , 255); border-radius: 50%; border: 0px; box-shadow: rgb(204 , 204 , 204) 1px 1px 2px 2px; box-sizing: border-box; color: #454545; cursor: pointer; direction: ltr; display: inline-block; font-family: "material icons"; font-size: 24px; line-height: 1; margin: 5px 0px 0px; overflow-wrap: normal; padding: 0.15em; vertical-align: baseline; white-space: nowrap;" title="Run Code and See Output">play_arrow</span></div>
<div style="border: 0px; box-sizing: border-box; line-height: inherit; padding: 0px; text-align: left; vertical-align: baseline;">
<span class="material-icons code-sidebar-button dark-editor-button" style="background: rgb(255 , 255 , 255); border-radius: 50%; border: 0px; box-shadow: rgb(204 , 204 , 204) 1px 1px 2px 2px; box-sizing: border-box; color: #454545; cursor: pointer; direction: ltr; display: inline-block; font-family: "material icons"; font-size: 24px; line-height: 1; margin: 5px 0px 0px; overflow-wrap: normal; padding: 0.15em; vertical-align: baseline; white-space: nowrap;" title="Dark Mode">brightness_4</span></div>
</div>
</div>
</div>
</div>
<div class="code-container" style="border: 0px; box-sizing: border-box; flex: 1 1 0%; margin: 0px; min-width: 0px; overflow-y: hidden; padding: 0px; vertical-align: baseline; width: 600.438px;">
<div class="syntaxhighlighter nogutter " id="highlighter_271815" style="background-color: white !important; border: 0px; box-sizing: border-box; font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 600.438px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none !important; border-collapse: collapse; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgba(0, 0, 0, 0.84) !important; direction: ltr !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 600px;"><tbody style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="code" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 600px;"><div class="container" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 5px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">main() </code></div>
<div class="line number2 index1 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">{ </code></div>
<div class="line number3 index2 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// All these variables get memory </code></div>
<div class="line number4 index3 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// allocated on stack </code></div>
<div class="line number5 index4 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">a; </code></div>
<div class="line number6 index5 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">b[10]; </code></div>
<div class="line number7 index6 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">n = 20; </code></div>
<div class="line number8 index7 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">c[n]; </code></div>
<div class="line number9 index8 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Heap Allocation : </strong>The memory is allocated during execution of instructions written by programmers. Note that the name heap has nothing to do with heap data structure. It is called heap because it is a pile of memory space available to programmers to allocated and de-allocate. If a programmer does not handle this memory well, <a href="https://www.geeksforgeeks.org/what-is-memory-leak-how-can-we-avoid/" style="border: 0px; box-sizing: border-box; color: #ec4e20; margin: 0px; outline: none; padding: 0px; text-decoration-line: none; vertical-align: baseline;">memory leak</a> can happen in the program.</div>
<div class="code-block" style="border: 0px; box-sizing: border-box; display: flex; flex-direction: row; margin: 0px 0px 10px; padding: 0px; vertical-align: baseline;">
<div class="code-gutter" style="border: 0px; box-sizing: border-box; flex-flow: column; margin: 0px; padding: 0px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons-container" style="border: 0px; bottom: 0px; box-sizing: border-box; left: 0px; margin: 0px; padding: 0px; position: sticky; top: 30px; vertical-align: baseline; width: 40px;">
<div class="editor-buttons" style="align-items: center; border: 0px; box-sizing: border-box; display: flex; flex-flow: column; margin: 0px; padding: 6px 0px 0px; position: sticky; top: 0px; vertical-align: baseline; width: 40px; z-index: 1;">
<div class="editor-buttons-div" style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;" title="Run and Edit">
</div>
</div>
</div>
</div>
<div class="code-container" style="border: 0px; box-sizing: border-box; flex: 1 1 0%; margin: 0px; min-width: 0px; overflow-y: hidden; padding: 0px; vertical-align: baseline; width: 600.438px;">
<div class="syntaxhighlighter nogutter " id="highlighter_733881" style="background-color: white !important; border: 0px; box-sizing: border-box; font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 600.438px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none !important; border-collapse: collapse; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgba(0, 0, 0, 0.84) !important; direction: ltr !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 600px;"><tbody style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="code" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 600px;"><div class="container" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 5px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">main() </code></div>
<div class="line number2 index1 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">{ </code></div>
<div class="line number3 index2 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// This memory for 10 integers </code></div>
<div class="line number4 index3 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="comments" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 130, 0) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">// is allocated on heap. </code></div>
<div class="line number5 index4 alt2" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="undefined spaces" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"> </code><code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code> <code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">*ptr = </code><code class="keyword bold" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">new</code> <code class="color1 bold" style="background: none; border-radius: 0px; border: 0px; bottom: auto; box-shadow: none; box-sizing: content-box; color: grey; direction: ltr; display: inline; float: none; font-family: "consolas" , "bitstream vera sans mono" , "courier new" , "courier" , monospace "important"; font-size: 0.99em; font-weight: bold; height: auto; left: auto; line-height: 1.2em; margin: 0px; min-height: auto; outline: 0px; overflow: hidden; padding: 0px; position: static; right: auto; top: auto; vertical-align: baseline; width: auto;">int</code><code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">[10]; </code></div>
<div class="line number6 index5 alt1" style="background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="plain" style="background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: black !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; font-size: 0.99em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: hidden !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">} </code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Key Differences Between Stack and Heap Allocations</strong></div>
<ol style="border: 0px; box-sizing: border-box; line-height: 1.71429; list-style-image: initial; list-style-position: outside; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline;">
<li style="border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;">In a stack, the allocation and deallocation is automatically done by whereas, in heap, it needs to be done by the programmer manually.</li>
<li style="border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;">Handling of Heap frame is costlier than handling of stack frame.</li>
<li style="border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;">Memory shortage problem is more likely to happen in stack whereas the main issue in heap memory is fragmentation.</li>
<li style="border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;">Stack frame access is easier than the heap frame as the stack have small region of memory and is cache friendly, but in case of heap frames which are dispersed throughout the memory so it cause more cache misses.</li>
<li style="border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;">Stack is not flexible, the memory size allotted cannot be changed whereas a heap is flexible, and the allotted memory can be altered.</li>
<li style="border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;">Accessing time of heap takes is more than a stack.</li>
</ol>
<div style="border: 0px; box-sizing: border-box; line-height: 1.71429; margin-bottom: 10px; padding: 0px; text-align: left; vertical-align: baseline;">
<strong style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">Comparison Chart:</strong></div>
<table style="border-bottom-color: rgb(237, 237, 237); border-bottom-style: solid; border-collapse: collapse; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-spacing: 0px; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84) !important; font-size: 12px; line-height: 2; margin: 0px 0px 24px; padding: 0px; vertical-align: baseline; width: 576px;"><thead style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><th style="background: rgb(15, 157, 88); border: 0px; box-sizing: border-box; color: black; font-size: 11px; line-height: 2.18182; margin: 0px; padding: 8px; text-align: center; text-transform: uppercase; vertical-align: baseline;">PARAMETER</th><th style="background: rgb(15, 157, 88); border: 0px; box-sizing: border-box; color: black; font-size: 11px; line-height: 2.18182; margin: 0px; padding: 8px; text-align: center; text-transform: uppercase; vertical-align: baseline;">STACK</th><th style="background: rgb(15, 157, 88); border: 0px; box-sizing: border-box; color: black; font-size: 11px; line-height: 2.18182; margin: 0px; padding: 8px; text-align: center; text-transform: uppercase; vertical-align: baseline;">HEAP</th></tr>
</thead><tbody style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;">
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Basic</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Memory is allocated in a contiguous block.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Memory is allocated in any random order.</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Allocation and Deallocation</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Automatic by compiler instructions.</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Manual by programmer.</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Cost</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Less</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">More</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Implementation</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Hard</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Easy</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Access time</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Faster</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Slower</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Main Issue</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Shortage of memory</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Memory fragmentation</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Locality of reference</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Excellent</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Adequate</td></tr>
<tr style="border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;"><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Flexibility</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Fixed size</td><td style="border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: rgb(237, 237, 237); border-top-style: solid; border-width: 1px 0px 0px; box-sizing: border-box; font-size: 16px; margin: 0px; padding: 7px 14px; vertical-align: baseline;">Resizing is possible</td></tr>
</tbody></table>
</div>
</h2>
</div>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-8161148254915239512019-06-11T10:29:00.001-07:002019-06-11T10:29:36.716-07:00Enter name by using console<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint notranslate prettyprinted" style="background-color: #eeeeee; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; margin-top: 15px; overflow: auto; padding: 5px; width: 604px;"><span class="com" style="box-sizing: border-box; color: #880000;">#include</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;"><iostream></span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">using</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">namespace</span><span class="pln" style="box-sizing: border-box;"> std</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> main</span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">char</span><span class="pln" style="box-sizing: border-box;"> name</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="lit" style="box-sizing: border-box; color: #006666;">50</span><span class="pun" style="box-sizing: border-box; color: #666600;">];</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Please enter your name: "</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
cin </span><span class="pun" style="box-sizing: border-box; color: #666600;">>></span><span class="pln" style="box-sizing: border-box;"> name</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Your name is: "</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> name </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> endl</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-88873671474980993362019-05-17T06:46:00.002-07:002019-05-24T08:39:25.161-07:00Pointers<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;"><div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Pointers are powerful features of C++ that differentiates it from other programming languages like Java and Python.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Pointers are used in C++ program to access the memory and manipulate the address.</div>
<hr style="background-color: white; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 0px; border-top-color: rgb(221, 221, 221); border-top-style: solid; box-sizing: content-box; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; height: 0px; margin: 20px 0px; white-space: normal;" />
<h2 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.6em; line-height: 1.15; margin: 0.8em 0px 0.45em; white-space: normal; word-spacing: 0px;">
Address in C++</h2>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
To understand pointers, you should first know how data is stored on the computer.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Each variable you create in your program is assigned a location in the computer's memory. The value the variable stores is actually stored in the location assigned.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
To know where the data is stored, C++ has an & operator. The <b style="color: #555555; font-size: 0.98em;">&</b> (reference) operator gives you the address occupied by a variable.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
If <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">var</code> is a variable then, <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">&var</code> gives the address of that variable.</div>
<h2 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.6em; line-height: 1.15; margin: 0.8em 0px 0.45em; white-space: normal; word-spacing: 0px;">
Example 1: Address in C++</h2>
<pre class="prettyprint prettyprinted" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">#include</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;"><iostream></span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">using</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">namespace</span><span class="pln" style="color: black;"> std</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> main</span><span class="pun" style="color: black;">()</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> var1 </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">3</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> var2 </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">24</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> var3 </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">17</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">var1 </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">var2 </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">var3 </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span></code></pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<b style="color: #555555; font-size: 0.98em;">Output</b></div>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;"><samp style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;">0x7fff5fbff8ac
0x7fff5fbff8a8
0x7fff5fbff8a4
</samp></pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<strong style="color: #555555; font-size: 0.98em;">Note: </strong>You may not get the same result on your system.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
The <b style="color: #555555; font-size: 0.98em;">0x</b> in the beginning represents the address is in hexadecimal form.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Notice that first address differs from second by 4-bytes and second address differs from third by 4-bytes.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
This is because the size of integer (variable of type <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">int</code>) is 4 bytes in 64-bit system.</div>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">#include</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;"><iostream></span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">using</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">namespace</span><span class="pln" style="color: black;"> std</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> main</span><span class="pun" style="color: black;">()</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">*</span><span class="pln" style="color: black;">pc</span><span class="pun" style="color: black;">,</span><span class="pln" style="color: black;"> c</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
c </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">5</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Address of c (&c): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">c </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Value of c (c): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> c </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
pc </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">c</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="com" style="color: grey;">// Pointer pc holds the memory address of variable c</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Address that pointer pc holds (pc): "</span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> pc </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Content of the address pointer pc holds (*pc): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">*</span><span class="pln" style="color: black;">pc </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
c </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">11</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="com" style="color: grey;">// The content inside memory address &c is changed from 5 to 11.</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Address pointer pc holds (pc): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> pc </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Content of the address pointer pc holds (*pc): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">*</span><span class="pln" style="color: black;">pc </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">*</span><span class="pln" style="color: black;">pc </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">2</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Address of c (&c): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">c </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Value of c (c): "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> c </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">return</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;"><div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<strong style="color: #555555; font-size: 0.98em;">Output</strong></div>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;"><samp style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;">Address of c (&c): 0x7fff5fbff80c
Value of c (c): 5
Address that pointer pc holds (pc): 0x7fff5fbff80c
Content of the address pointer pc holds (*pc): 5
Address pointer pc holds (pc): 0x7fff5fbff80c
Content of the address pointer pc holds (*pc): 11
Address of c (&c): 0x7fff5fbff80c
Value of c (c): 2</samp></pre>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;"><samp style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;">
</samp></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihFW_Dup_zlarR54GzX3t5ERAVEe5Jb33j-WeRkVdUU07XxGXQYCAyVSru4-RsxXclRCcxtViCTwOBQfx4js-BtRA7f7s1vV6fkTK3NTMygmxH7g6vwY5czQLY1UDO1SOqUbIwKsk3LoE/s1600/pointers.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="355" data-original-width="450" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihFW_Dup_zlarR54GzX3t5ERAVEe5Jb33j-WeRkVdUU07XxGXQYCAyVSru4-RsxXclRCcxtViCTwOBQfx4js-BtRA7f7s1vV6fkTK3NTMygmxH7g6vwY5czQLY1UDO1SOqUbIwKsk3LoE/s320/pointers.jpg" width="320" /></a></div>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;"><samp style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;">
</samp></pre>
<div>
<samp style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;">
</samp></div>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;"><div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<strong style="color: #555555; font-size: 0.98em;">Explanation of program</strong></div>
<ul style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.8em; white-space: normal;">
<li>When <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">c = 5;</code> the value 5 is stored in the address of variable <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">c</var> - 0x7fff5fbff8c.</li>
<li>When <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">pc = &c;</code> the pointer <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">pc</var> holds the address of <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">c</var> - 0x7fff5fbff8c, and the expression (dereference operator) <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">*pc</code> outputs the value stored in that address, 5.</li>
<li>When <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">c = 11;</code> since the address pointer <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">pc</var> holds is the same as <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">c</var> - 0x7fff5fbff8c, change in the value of c is also reflected when the expression <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">*pc</code> is executed, which now outputs 11.</li>
<li>When <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">*pc = 2;</code> it changes the content of the address stored by <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">pc</var> - 0x7fff5fbff8c. This is changed from 11 to 2. So, when we print the value of <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">c</var>, the value is 2 as well.</li>
</ul>
<h2 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.6em; line-height: 1.15; margin: 0.8em 0px 0.45em; white-space: normal; word-spacing: 0px;">
Common mistakes when working with pointers</h2>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Suppose, you want pointer pc to point to the address of c. Then,</div>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;">int c, *pc;
pc=c; /* Wrong! pc is address whereas, c is not an address. */
*pc=&c; /* Wrong! *pc is the value pointed by address whereas, %amp;c is an address. */
pc=&c; /* Correct! pc is an address and, %amp;pc is also an address. */
*pc=c; /* Correct! *pc is the value pointed by address and, c is also a value. */</pre>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;"><div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<a href="https://www.programiz.com/cpp-programming/pointers" style="-webkit-font-smoothing: antialiased; background-color: transparent; color: #2b6dad; text-decoration-line: none;" title="C++ Pointers">Pointers</a> are the variables that hold address. Not only can pointers store address of a single variable, it can also store address of cells of an <a href="https://www.programiz.com/cpp-programming/arrays" style="-webkit-font-smoothing: antialiased; background-color: transparent; color: #2b6dad; text-decoration-line: none;" title="C++ arrays">array</a>.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Consider this example:</div>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;">int* ptr;
int a[5];
ptr = &a[2]; // &a[2] is the address of third element of a[5].
</pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<img alt="Pointer pointing to an array cell" src="https://cdn.programiz.com/sites/tutorial2program/files/cpp-array-as-pointers.jpg" style="border: 0px; font-size: 13.008px; margin: 1.2em 0px; max-width: 100%; vertical-align: middle;" title="Pointers to array" /></div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Suppose, pointer needs to point to the fourth element of an array, that is, hold address of fourth array element in above case.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Since <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">ptr</var> points to the third element in the above example, <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr + 1</code> will point to the fourth element.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
You may think, <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr + 1</code> gives you the address of next byte to the <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr</code>. But it's not correct.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
This is because pointer <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">ptr</var> is a pointer to an <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">int</code> and size of <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">int</code> is fixed for a operating system (size of <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">int</code> is 4 byte of 64-bit operating system). Hence, the address between <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr</code>and <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr + 1</code> differs by 4 bytes.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
If pointer <var style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; font-style: normal; padding: 1px 5px;">ptr</var> was pointer to <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">char</code> then, the address between <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr</code> and <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">ptr + 1</code> would have differed by 1 byte since size of a character is 1 byte.</div>
<hr style="background-color: white; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 0px; border-top-color: rgb(221, 221, 221); border-top-style: solid; box-sizing: content-box; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; height: 0px; margin: 20px 0px; white-space: normal;" />
<h2 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.6em; line-height: 1.15; margin: 0.8em 0px 0.45em; white-space: normal; word-spacing: 0px;">
Example 1: C++ Pointers and Arrays</h2>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<strong style="color: #555555; font-size: 0.98em;">C++ Program to display address of elements of an array using both array and pointers</strong></div>
<pre class="prettyprint prettyprinted" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">#include</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;"><iostream></span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">using</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">namespace</span><span class="pln" style="color: black;"> std</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> main</span><span class="pun" style="color: black;">()</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">float</span><span class="pln" style="color: black;"> arr</span><span class="pun" style="color: black;">[</span><span class="lit" style="color: maroon;">5</span><span class="pun" style="color: black;">];</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">float</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">*</span><span class="pln" style="color: black;">ptr</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Displaying address using arrays: "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">for</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">(</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">5</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">++</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">)</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"&arr["</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"] = "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">&</span><span class="pln" style="color: black;">arr</span><span class="pun" style="color: black;">[</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">]</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span><span class="pln" style="color: black;">
</span><span class="com" style="color: grey;">// ptr = &arr[0]</span><span class="pln" style="color: black;">
ptr </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> arr</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout</span><span class="pun" style="color: black;"><<</span><span class="str" style="color: maroon;">"\nDisplaying address using pointers: "</span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">for</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">(</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">5</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">++</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">)</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"ptr + "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">" = "</span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> ptr </span><span class="pun" style="color: black;">+</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">return</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span></code></pre>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<b style="color: #555555; font-size: 0.98em;">Output</b></div>
<pre style="background: rgb(246, 246, 246); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; margin-bottom: 1.8em; margin-top: -0.8em; overflow: auto; padding: 15px 18.5px;"><samp style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;">Displaying address using arrays:
&arr[0] = 0x7fff5fbff880
&arr[1] = 0x7fff5fbff884
&arr[2] = 0x7fff5fbff888
&arr[3] = 0x7fff5fbff88c
&arr[4] = 0x7fff5fbff890
Displaying address using pointers:
ptr + 0 = 0x7fff5fbff880
ptr + 1 = 0x7fff5fbff884
ptr + 2 = 0x7fff5fbff888
ptr + 3 = 0x7fff5fbff88c
ptr + 4 = 0x7fff5fbff890</samp></pre>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;"><pre class="prettyprint notranslate prettyprinted" style="border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; margin-top: 15px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;"><span class="com" style="box-sizing: border-box; color: #880000;">#include</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;"><iostream></span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">using</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">namespace</span><span class="pln" style="box-sizing: border-box;"> std</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">const</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> MAX </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">3</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> main </span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">var</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">]</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="lit" style="box-sizing: border-box; color: #006666;">10</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">100</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">200</span><span class="pun" style="box-sizing: border-box; color: #666600;">};</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">for</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><</span><span class="pln" style="box-sizing: border-box;"> MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i</span><span class="pun" style="box-sizing: border-box; color: #666600;">++)</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Value of var["</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"] = "</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">var</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">i</span><span class="pun" style="box-sizing: border-box; color: #666600;">]</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> endl</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">return</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span></pre>
<div style="box-sizing: border-box; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
When the above code is compiled and executed, it produces the following result −</div>
<pre class="result notranslate" style="background-color: #f1f1f1; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;">Value of var[0] = 10
Value of var[1] = 100
Value of var[2] = 200
</pre>
<div style="box-sizing: border-box; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
There may be a situation, when we want to maintain an array, which can store pointers to an int or char or any other data type available. Following is the declaration of an array of pointers to an integer −</div>
<pre class="result notranslate" style="background-color: #f1f1f1; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;">int *ptr[MAX];
</pre>
<div style="box-sizing: border-box; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
This declares <span style="box-sizing: border-box; font-weight: 640;">ptr</span> as an array of MAX integer pointers. Thus, each element in ptr, now holds a pointer to an int value. Following example makes use of three integers which will be stored in an array of pointers as follows −</div>
<i class="fa-external-link" style="box-sizing: border-box;"></i> Live Demo<pre class="prettyprint notranslate prettyprinted" style="border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; margin-top: 15px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;"><span class="com" style="box-sizing: border-box; color: #880000;">#</span><span class="com" style="box-sizing: border-box; color: #880000;">include</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;"><iostream></span></pre>
<pre class="prettyprint notranslate prettyprinted" style="border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; margin-top: 15px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;"><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">using</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">namespace</span><span class="pln" style="box-sizing: border-box;"> std</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">const</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> MAX </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">3</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> main </span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">var</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">]</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="lit" style="box-sizing: border-box; color: #006666;">10</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">100</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">200</span><span class="pun" style="box-sizing: border-box; color: #666600;">};</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box;">ptr</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">];</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">for</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><</span><span class="pln" style="box-sizing: border-box;"> MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i</span><span class="pun" style="box-sizing: border-box; color: #666600;">++)</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
ptr</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">i</span><span class="pun" style="box-sizing: border-box; color: #666600;">]</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">&</span><span class="kwd" style="box-sizing: border-box; color: #000088;">var</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">i</span><span class="pun" style="box-sizing: border-box; color: #666600;">];</span><span class="pln" style="box-sizing: border-box;"> </span><span class="com" style="box-sizing: border-box; color: #880000;">// assign the address of integer.</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">for</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><</span><span class="pln" style="box-sizing: border-box;"> MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i</span><span class="pun" style="box-sizing: border-box; color: #666600;">++)</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Value of var["</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"] = "</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box;">ptr</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">i</span><span class="pun" style="box-sizing: border-box; color: #666600;">]</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> endl</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">return</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span></pre>
<div style="box-sizing: border-box; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
When the above code is compiled and executed, it produces the following result −</div>
<pre class="result notranslate" style="background-color: #f1f1f1; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;">Value of var[0] = 10
Value of var[1] = 100
Value of var[2] = 200
</pre>
<div style="box-sizing: border-box; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
You can also use an array of pointers to character to store a list of strings as follows −</div>
<a class="demo" href="http://tpcg.io/0kooHI" rel="nofollow" style="background: rgb(0, 68, 129); border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: white; font-family: "Open Sans", Arial, sans-serif; font-size: 13px; margin: -6px 17px 0px 0px; outline: none !important; padding: 3px 10px; position: absolute; right: 5px; text-decoration-line: none; white-space: normal; word-spacing: 0px;" target="_blank"><i class="fa-external-link" style="box-sizing: border-box;"></i> Live Demo</a><pre class="prettyprint notranslate prettyprinted" style="border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; line-height: 16px; margin-bottom: 10px; margin-top: 15px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;"><span class="com" style="box-sizing: border-box; color: #880000;">#include</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;"><iostream></span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">using</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">namespace</span><span class="pln" style="box-sizing: border-box;"> std</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">const</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> MAX </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">4</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> main </span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">const</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">char</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">*</span><span class="pln" style="box-sizing: border-box;">names</span><span class="pun" style="box-sizing: border-box; color: #666600;">[</span><span class="pln" style="box-sizing: border-box;">MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">]</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Zara Ali"</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Hina Ali"</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Nuha Ali"</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Sara Ali"</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">};</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">for</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><</span><span class="pln" style="box-sizing: border-box;"> MAX</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;"> i</span><span class="pun" style="box-sizing: border-box; color: #666600;">++)</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Value of names["</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> i </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"] = "</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box;">names </span><span class="pun" style="box-sizing: border-box; color: #666600;">+</span><span class="pln" style="box-sizing: border-box;"> i</span><span class="pun" style="box-sizing: border-box; color: #666600;">)</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> endl</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">return</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span></pre>
<div style="box-sizing: border-box; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
When the above code is compiled and executed, it produces the following result −</div>
<pre class="result notranslate" style="background-color: #f1f1f1; border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 12px; overflow: auto; padding: 5px; width: 604px; word-spacing: 0px;">Value of names[0] = 0x7ffd256683c0
Value of names[1] = 0x7ffd256683c8
Value of names[2] = 0x7ffd256683d0
Value of names[3] = 0x7ffd256683d8
</pre>
<div>
</div>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, serif; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="background-color: red; color: #45818e; font-size: large;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border: 1px solid rgb(234, 234, 236); font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, serif; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="background-color: red; color: #45818e; font-size: large;">pointer and array</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">#include <iostream>
using namespace std;
int main ()
{
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p++; *p = 30;
p++; *p = 40;
p++; *p = 50;
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
return 0;
}
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">pointer and arrays.</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code><span class="pun" style="font-family: consolas, menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, courier, monospace; font-size: 15px; word-spacing: 3px;">#include <iostream>
using namespace std;
int main ()
{
cout <<"simple array out put inilization\n";
int numbers[5]={100,200,300,400,500};
int *p;
p = numbers;
// for simple out put
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
cout <<"\n\n loop using pointers";
for (int n=0; n<5; n++)
cout << *(p+n) << ", ";
cout<<"GGGGGGGGGGGGGGGGGGGGGG\n\n";
cout << numbers[2];
p = &numbers[2];
*p = 30;
cout << "after *p=30................>"<<numbers[2];
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
return 0;
}</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code><span class="pun" style="font-family: consolas, menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, courier, monospace; font-size: 15px; word-spacing: 3px;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code><span class="pun" style="font-family: consolas, menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, courier, monospace; font-size: 15px; word-spacing: 3px;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code><span class="pun" style="font-family: consolas, menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, courier, monospace; font-size: 15px; word-spacing: 3px;">output</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code><span class="pun" style="font-family: consolas, menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, courier, monospace; font-size: 15px; word-spacing: 3px;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto;"><code><span class="pun" style="font-family: consolas, menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, courier, monospace; font-size: 15px; word-spacing: 3px;">simple array out put inilization
100, 200, 300, 400, 500,
loop using pointers100, 200, 300, 400, 500, GGGGGGGGGGGGGGGGGGGGGG
300after *p=30................>30100, 200, 30, 40, 50,
--------------------------------
Process exited with return value 0
Press any key to continue . . .</span></code></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com2tag:blogger.com,1999:blog-1033148957699292242.post-67917952736503390542019-05-14T04:26:00.000-07:002019-05-16T09:57:26.862-07:00 Library Function or built in function<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;"><div style="box-sizing: border-box; color: black; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
A function is a group of statements that together perform a task. Every C++ program has at least one function, which is <span style="box-sizing: border-box; font-weight: 640;">main()</span>, and all the most trivial programs can define additional functions.</div>
<div style="box-sizing: border-box; color: black; font-family: Verdana, Geneva, Tahoma, Arial, Helvetica, sans-serif; line-height: 24px; margin: 0em 0.2em 0.6em; overflow-wrap: break-word; padding: 0px; text-align: justify; white-space: normal; word-spacing: 0px;">
You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is such that each function performs a specific task.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
In programming, function refers to a segment that groups code to perform a specific task.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Depending on whether a function is predefined or created by programmer; there are two types of function:</div>
<ol style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.8em; white-space: normal;">
<li>Library Function</li>
<li>User-defined Function</li>
</ol>
<hr style="background-color: white; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 0px; border-top-color: rgb(221, 221, 221); border-top-style: solid; box-sizing: content-box; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; height: 0px; margin: 20px 0px; white-space: normal;" />
<h2 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.6em; line-height: 1.15; margin: 0.8em 0px 0.45em; white-space: normal; word-spacing: 0px;">
Library Function</h2>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Library functions are the built-in function in C++ programming.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Programmer can use library function by invoking function directly; they don't need to write it themselves.</div>
<h2 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.6em; line-height: 1.15; margin: 0.8em 0px 0.45em; white-space: normal; word-spacing: 0px;">
User-defined Function</h2>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
C++ allows programmer to define their own function.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
A user-defined function groups code to perform a specific task and that group of code is given a name(identifier).</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
When the function is invoked from any part of program, it all executes the codes defined in the body of function.</div>
<hr style="background-color: white; border-bottom: 0px; border-image: initial; border-left: 0px; border-right: 0px; border-top-color: rgb(221, 221, 221); border-top-style: solid; box-sizing: content-box; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; height: 0px; margin: 20px 0px; white-space: normal;" />
<h3 style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 1.4em; line-height: 1.15; margin: 0.8em 0px 0.35em; white-space: normal; word-spacing: 0px;">
How user-defined function works in C Programming?</h3>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
<img alt="Working of function in C++ programming" src="https://cdn.programiz.com/sites/tutorial2program/files/function.jpg" style="border: 0px; margin: 1.2em 0px; max-width: 100%; vertical-align: middle;" /></div>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;"><div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
When a program begins running, the system calls the <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">main()</code> function, that is, the system starts executing codes from <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">main()</code> function.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
When control of the program reaches to <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">function_name()</code> inside <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">main()</code>, it moves to <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">void function_name() </code>and all codes inside <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">void function_name()</code> is executed.</div>
<div style="-webkit-font-smoothing: antialiased; background-color: white; color: #252830; font-family: "Open Sans", sans-serif; font-size: 16px; margin-bottom: 1.4em; white-space: normal;">
Then, control of the program moves back to the main function where the code after the call to the <code style="background: rgb(239, 240, 241); border-radius: 2px; font-family: Menlo, Consolas, "Open Sans", sans-serif; font-size: 0.86em; padding: 1px 5px;">function_name()</code> is executed as shown in figure above.</div>
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">#include</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;"><iostream></span><span class="pln" style="color: black;">
</span><span class="com" style="color: grey;">#include</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;"><cmath></span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">using</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">namespace</span><span class="pln" style="color: black;"> std</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> main</span><span class="pun" style="color: black;">()</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">double</span><span class="pln" style="color: black;"> number</span><span class="pun" style="color: black;">,</span><span class="pln" style="color: black;"> squareRoot</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Enter a number: "</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cin </span><span class="pun" style="color: black;">>></span><span class="pln" style="color: black;"> number</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="com" style="color: grey;">// sqrt() is a library function to calculate square root</span><span class="pln" style="color: black;">
squareRoot </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> sqrt</span><span class="pun" style="color: black;">(</span><span class="pln" style="color: black;">number</span><span class="pun" style="color: black;">);</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Square root of "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> number </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">" = "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> squareRoot</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">return</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;">
</span></code></pre>
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="pun" style="color: black;"><pre class="prettyprint prettyprinted" style="box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px; word-spacing: 0px;"><span class="com" style="box-sizing: border-box; color: grey;">#include</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: maroon;"><iostream></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">#include</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: maroon;"><cmath></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">using</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">namespace</span><span class="pln" style="box-sizing: border-box; color: black;"> std</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> main</span><span class="pun" style="box-sizing: border-box; color: black;">(){</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">/* Calling the built-in function
* pow(x, y) which is x to the power y
* We are directly calling this function
*/</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">pow</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="lit" style="box-sizing: border-box; color: maroon;">2</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="lit" style="box-sizing: border-box; color: maroon;">5</span><span class="pun" style="box-sizing: border-box; color: black;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">0</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span></pre>
</span></code></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-30845004806483760592019-05-14T04:21:00.002-07:002019-05-14T04:21:34.952-07:00Default Arguments in C++ Functions<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="com" style="box-sizing: border-box; color: grey;">#include</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: maroon;"><iostream></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">using</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">namespace</span><span class="pln" style="box-sizing: border-box; color: black;"> std</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> a</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> b</span><span class="pun" style="box-sizing: border-box; color: black;">=</span><span class="lit" style="box-sizing: border-box; color: maroon;">10</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> c</span><span class="pun" style="box-sizing: border-box; color: black;">=</span><span class="lit" style="box-sizing: border-box; color: maroon;">20</span><span class="pun" style="box-sizing: border-box; color: black;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> main</span><span class="pun" style="box-sizing: border-box; color: black;">(){</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">/* In this case a value is passed as
* 1 and b and c values are taken from
* default arguments.
*/</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="lit" style="box-sizing: border-box; color: maroon;">1</span><span class="pun" style="box-sizing: border-box; color: black;">)<<</span><span class="pln" style="box-sizing: border-box; color: black;">endl</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">/* In this case a value is passed as
* 1 and b value as 2, value of c values is
* taken from default arguments.
*/</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="lit" style="box-sizing: border-box; color: maroon;">1</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">2</span><span class="pun" style="box-sizing: border-box; color: black;">)<<</span><span class="pln" style="box-sizing: border-box; color: black;">endl</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">/* In this case all the three values are
* passed during function call, hence no
* default arguments have been used.
*/</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="lit" style="box-sizing: border-box; color: maroon;">1</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">2</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">3</span><span class="pun" style="box-sizing: border-box; color: black;">)<<</span><span class="pln" style="box-sizing: border-box; color: black;">endl</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">0</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> a</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> b</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> c</span><span class="pun" style="box-sizing: border-box; color: black;">){</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> z</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
z </span><span class="pun" style="box-sizing: border-box; color: black;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> a</span><span class="pun" style="box-sizing: border-box; color: black;">+</span><span class="pln" style="box-sizing: border-box; color: black;">b</span><span class="pun" style="box-sizing: border-box; color: black;">+</span><span class="pln" style="box-sizing: border-box; color: black;">c</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> z</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-41686298488111200602019-05-14T04:16:00.001-07:002019-05-14T04:27:06.685-07:00sum of two values by using function<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="com" style="box-sizing: border-box; color: grey;">#include</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="str" style="box-sizing: border-box; color: maroon;"><iostream></span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">using</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">namespace</span><span class="pln" style="box-sizing: border-box; color: black;"> std</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">/* This function adds two integer values
* and returns the result
*/</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;">
sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> num1</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> num2</span><span class="pun" style="box-sizing: border-box; color: black;">){</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> num3 </span><span class="pun" style="box-sizing: border-box; color: black;">=</span><span class="pln" style="box-sizing: border-box; color: black;"> num1</span><span class="pun" style="box-sizing: border-box; color: black;">+</span><span class="pln" style="box-sizing: border-box; color: black;">num2</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="kwd" style="box-sizing: border-box; color: darkblue;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> num3</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">int</span><span class="pln" style="box-sizing: border-box; color: black;"> main</span><span class="pun" style="box-sizing: border-box; color: black;">(){</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="com" style="box-sizing: border-box; color: grey;">//Calling the function</span><span class="pln" style="box-sizing: border-box; color: black;">
cout</span><span class="pun" style="box-sizing: border-box; color: black;"><<</span><span class="pln" style="box-sizing: border-box; color: black;">sum</span><span class="pun" style="box-sizing: border-box; color: black;">(</span><span class="lit" style="box-sizing: border-box; color: maroon;">1</span><span class="pun" style="box-sizing: border-box; color: black;">,</span><span class="lit" style="box-sizing: border-box; color: maroon;">99</span><span class="pun" style="box-sizing: border-box; color: black;">);</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="kwd" style="box-sizing: border-box; color: darkblue;">return</span><span class="pln" style="box-sizing: border-box; color: black;"> </span><span class="lit" style="box-sizing: border-box; color: maroon;">0</span><span class="pun" style="box-sizing: border-box; color: black;">;</span><span class="pln" style="box-sizing: border-box; color: black;">
</span><span class="pun" style="box-sizing: border-box; color: black;">}</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="pun" style="box-sizing: border-box; color: black;">
</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="pun" style="box-sizing: border-box; color: black;">
</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; font-family: consolas, menlo, monaco, "lucida console", "liberation mono", "dejavu sans mono", "bitstream vera sans mono", "courier new", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;">EXAMPE 2:</pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="pun" style="box-sizing: border-box; color: black;">
</span></pre>
<pre class="prettyprint prettyprinted" style="background-color: #eeeeee; box-sizing: border-box; clear: both; color: #222426; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; overflow: auto; padding: 2px;"><span class="pun" style="box-sizing: border-box; color: black;"><pre class="prettyprint notranslate prettyprinted" style="border-radius: 0px; border: 1px solid rgb(214, 214, 214); box-sizing: border-box; color: #313131; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; line-height: 16px; margin-bottom: 10px; margin-top: 15px; overflow: auto; padding: 5px; width: 604px;"><span class="com" style="box-sizing: border-box; color: #880000;">#include</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;"><iostream></span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">using</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">namespace</span><span class="pln" style="box-sizing: border-box;"> std</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="com" style="box-sizing: border-box; color: #880000;">// function declaration</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> max</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> num1</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> num2</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> main </span><span class="pun" style="box-sizing: border-box; color: #666600;">()</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
</span><span class="com" style="box-sizing: border-box; color: #880000;">// local variable declaration:</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> a </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">100</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> b </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">200</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> ret</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="com" style="box-sizing: border-box; color: #880000;">// calling a function to get max value.</span><span class="pln" style="box-sizing: border-box;">
ret </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> max</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box;">a</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> b</span><span class="pun" style="box-sizing: border-box; color: #666600;">);</span><span class="pln" style="box-sizing: border-box;">
cout </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> </span><span class="str" style="box-sizing: border-box; color: #008800;">"Max value is : "</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> ret </span><span class="pun" style="box-sizing: border-box; color: #666600;"><<</span><span class="pln" style="box-sizing: border-box;"> endl</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">return</span><span class="pln" style="box-sizing: border-box;"> </span><span class="lit" style="box-sizing: border-box; color: #006666;">0</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span><span class="pln" style="box-sizing: border-box;">
</span><span class="com" style="box-sizing: border-box; color: #880000;">// function returning the max between two numbers</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> max</span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> num1</span><span class="pun" style="box-sizing: border-box; color: #666600;">,</span><span class="pln" style="box-sizing: border-box;"> </span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> num2</span><span class="pun" style="box-sizing: border-box; color: #666600;">)</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">{</span><span class="pln" style="box-sizing: border-box;">
</span><span class="com" style="box-sizing: border-box; color: #880000;">// local variable declaration</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">int</span><span class="pln" style="box-sizing: border-box;"> result</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">if</span><span class="pln" style="box-sizing: border-box;"> </span><span class="pun" style="box-sizing: border-box; color: #666600;">(</span><span class="pln" style="box-sizing: border-box;">num1 </span><span class="pun" style="box-sizing: border-box; color: #666600;">></span><span class="pln" style="box-sizing: border-box;"> num2</span><span class="pun" style="box-sizing: border-box; color: #666600;">)</span><span class="pln" style="box-sizing: border-box;">
result </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> num1</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">else</span><span class="pln" style="box-sizing: border-box;">
result </span><span class="pun" style="box-sizing: border-box; color: #666600;">=</span><span class="pln" style="box-sizing: border-box;"> num2</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="kwd" style="box-sizing: border-box; color: #000088;">return</span><span class="pln" style="box-sizing: border-box;"> result</span><span class="pun" style="box-sizing: border-box; color: #666600;">;</span><span class="pln" style="box-sizing: border-box;">
</span><span class="pun" style="box-sizing: border-box; color: #666600;">}</span></pre>
</span></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-86958562711085996362019-05-11T00:38:00.002-07:002019-05-11T00:38:44.510-07:00Recursivity function factorial of a number (n!)<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="background-color: white; border-bottom: 1px solid navy; font-family: verdana, arial, helvetica, sans-serif; margin-bottom: 5px;">
Recursivity</h3>
<span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;">Recursivity is the property that functions have to be called by themselves. It is useful for some tasks, such as sorting elements, or calculating the factorial of numbers. For example, in order to obtain the factorial of a number (</span><code style="background-color: white; font-size: 12px;">n!</code><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;">) the mathematical formula would be:</span><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><code style="background-color: white; font-size: 12px;">n! = n * (n-1) * (n-2) * (n-3) ... * 1</code><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;"> </span><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;">More concretely, </span><code style="background-color: white; font-size: 12px;">5!</code><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;"> (factorial of 5) would be:</span><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><code style="background-color: white; font-size: 12px;">5! = 5 * 4 * 3 * 2 * 1 = 120</code><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;"> </span><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;">And a recursive function to calculate this in C++ could be:</span><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><br />
<div class="auto" style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; margin: 0px;">
<table class="split" style="color: black; font-size: 12px; width: 728px;"><tbody>
<tr><td class="rownum" style="color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;"><pre><code>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18</code></pre>
</td><td class="source" style="background: rgb(239, 239, 255); border: 1px solid rgb(192, 192, 208); vertical-align: top; width: 352px;"><pre><code><cite style="color: #007000; font-style: normal;">// factorial calculator</cite>
<dfn style="color: #500070; font-style: normal;">#include <iostream></dfn>
<var style="color: #0000b0; font-style: normal;">using</var> <var style="color: #0000b0; font-style: normal;">namespace</var> std;
<var style="color: #0000b0; font-style: normal;">long</var> factorial (<var style="color: #0000b0; font-style: normal;">long</var> a)
{
<var style="color: #0000b0; font-style: normal;">if</var> (a > 1)
<var style="color: #0000b0; font-style: normal;">return</var> (a * factorial (a-1));
<var style="color: #0000b0; font-style: normal;">else</var>
<var style="color: #0000b0; font-style: normal;">return</var> 1;
}
<var style="color: #0000b0; font-style: normal;">int</var> main ()
{
<var style="color: #0000b0; font-style: normal;">long</var> number = 9;
cout << number << <kbd style="color: #600030;">"! = "</kbd> << factorial (number);
<var style="color: #0000b0; font-style: normal;">return</var> 0;
}</code></pre>
</td><td class="output" style="background: rgb(231, 231, 231); border: 1px solid silver; vertical-align: top; width: 336px;"><pre><samp>9! = 362880</samp></pre>
</td><td class="C_btnholder" style="padding: 0px; vertical-align: top;"><div class="C_shell" style="float: right; height: 0px; left: -2px; margin: 0px; position: relative; top: 0px;">
<div class="inner" style="left: 0px; margin: 0px; position: absolute; top: 0px; width: 200px;">
<div class="btn trans_half" style="border-bottom-right-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(192, 192, 208); height: 16px; margin: 0px; overflow: hidden; transition: all 0.5s ease 0s; width: 16px;">
<a href="http://www.cplusplus.com/doc/tutorial/functions/#" style="color: #000070; text-decoration-line: none;" target="_top" title="Open C++ Shell (in a new window)"><span class="C_ico settings" style="background-image: url("bg.png"); background-position: 0px -48px; background-repeat: no-repeat; display: inline-block; height: 16px; line-height: 16px; margin: 0px; padding: 0px; vertical-align: middle; width: 16px;"></span>Edit & Run</a></div>
</div>
</div>
</td></tr>
</tbody></table>
</div>
<br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><br style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;" /><span style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px;">Notice how in function factorial we included a call to itself, but only if the argument passed was greater than 1, since, otherwise, the function would perform an infinite recursive loop, in which once it arrived to 0, it would continue multiplying by all the negative numbers (probably provoking a stack overflow at some point during runtime).</span></div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-33101432455112025162019-05-10T08:50:00.001-07:002019-05-10T08:50:25.017-07:00test mach <div dir="ltr" style="text-align: left;" trbidi="on">
#include <iostream><br />
using namespace std;<br />
<br />
const int Inng = 2;<br />
const int Player = 11;<br />
<br />
int main()<br />
{int inngtotal=0;<br />
int score[Inng][Player];<br />
<br />
cout << "Enter all score for a Player of first Inng and then second Inng. \n";<br />
<br />
// Inserting the values into the score array<br />
for (int i = 0; i < Inng; ++i)<br />
{<br />
for(int j = 0; j < Player; ++j)<br />
{<br />
cout << "Inng " << i + 1 << ", Player " << j + 1 << " : ";<br />
cin >> score[i][j];<br />
}<br />
}<br />
<br />
cout << "\n\nDisplaying Values:\n";<br />
<br />
// Accessing the values from the score array<br />
for (int i = 0; i < Inng; ++i)<br />
{<br />
inngtotal=0;<br />
<span style="white-space: pre;"> </span>for(int j = 0; j < Player; ++j)<br />
{<br />
cout << "Inng " << i + 1 << ", Player " << j + 1 << " = " << score[i][j] << endl;<br />
inngtotal=inngtotal+score[i][j];<br />
}<br />
cout << "\ninng total ="<< inngtotal;<br />
}<br />
<br />
return 0;<br />
}</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-8042006648465225262019-05-10T08:24:00.001-07:002019-05-10T08:24:49.354-07:00function passing value<div dir="ltr" style="text-align: left;" trbidi="on">
#include <iostream><br />
using namespace std;<br />
int kkk(int a,int b);<br />
int main()<br />
{<br />
int i,j;<br />
i=kkk(99,80);<br />
cout <<"\nvalue of i .................>"<<i;<br />
<br />
<br />
<br />
<br />
<span style="white-space: pre;"> </span>cout << "\n value of iiiiiiiiiiiiii "<< i;<br />
<span style="white-space: pre;"> </span><br />
<span style="white-space: pre;"> </span>return 0;<br />
<br />
<span style="white-space: pre;"> </span><br />
}<br />
int kkk(int a,int b)<br />
{cout <<"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n"<<a<<" value of b "<<b;<br />
<br />
return a+b;<br />
}</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-65131860753364609392019-05-09T09:31:00.002-07:002019-05-09T09:31:23.978-07:00while table program<div dir="ltr" style="text-align: left;" trbidi="on">
#include <iostream><br />
using namespace std;<br />
int main()<br />
{<br />
<span style="white-space: pre;"> </span>int i=1;<br />
<span style="white-space: pre;"> </span>int t=7;<br />
<span style="white-space: pre;"> </span>while(i<10)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span><br />
<span style="white-space: pre;"> </span><br />
<span style="white-space: pre;"> </span>cout<<t<<"*"<<i<<"="<<t*i<<endl;<br />
<span style="white-space: pre;"> </span>i++;<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>return 0;<br />
<span style="white-space: pre;"> </span><br />
}<br />
<div>
while </div>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-29084445933862353202019-05-03T09:53:00.000-07:002019-05-10T08:50:05.227-07:00temperature for a week of first city<div dir="ltr" style="text-align: left;" trbidi="on">
<pre class="prettyprint prettyprinted" style="background: rgb(238, 238, 238); border: 1px solid rgb(234, 234, 236); color: #252830; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, serif; font-size: 15px; line-height: 1.15; margin-bottom: 10px; margin-top: -0.8em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-spacing: 3px;"><code style="font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;"><span class="com" style="color: grey;">#include</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;"><iostream></span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">using</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">namespace</span><span class="pln" style="color: black;"> std</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">const</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> CITY </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">2</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">const</span><span class="pln" style="color: black;"> </span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> WEEK </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">7</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> main</span><span class="pun" style="color: black;">()</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> temperature</span><span class="pun" style="color: black;">[</span><span class="pln" style="color: black;">CITY</span><span class="pun" style="color: black;">][</span><span class="pln" style="color: black;">WEEK</span><span class="pun" style="color: black;">];</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"Enter all temperature for a week of first city and then second city. \n"</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="com" style="color: grey;">// Inserting the values into the temperature array</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">for</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">(</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><</span><span class="pln" style="color: black;"> CITY</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">++</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">)</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">for</span><span class="pun" style="color: black;">(</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> j </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> j </span><span class="pun" style="color: black;"><</span><span class="pln" style="color: black;"> WEEK</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">++</span><span class="pln" style="color: black;">j</span><span class="pun" style="color: black;">)</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"City "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;">+</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">1</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">", Day "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> j </span><span class="pun" style="color: black;">+</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">1</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">" : "</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
cin </span><span class="pun" style="color: black;">>></span><span class="pln" style="color: black;"> temperature</span><span class="pun" style="color: black;">[</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">][</span><span class="pln" style="color: black;">j</span><span class="pun" style="color: black;">];</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"\n\nDisplaying Values:\n"</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="com" style="color: grey;">// Accessing the values from the temperature array</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">for</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">(</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;"><</span><span class="pln" style="color: black;"> CITY</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">++</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">)</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">for</span><span class="pun" style="color: black;">(</span><span class="kwd" style="color: darkblue;">int</span><span class="pln" style="color: black;"> j </span><span class="pun" style="color: black;">=</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> j </span><span class="pun" style="color: black;"><</span><span class="pln" style="color: black;"> WEEK</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;">++</span><span class="pln" style="color: black;">j</span><span class="pun" style="color: black;">)</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">{</span><span class="pln" style="color: black;">
cout </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">"City "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> i </span><span class="pun" style="color: black;">+</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">1</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">", Day "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> j </span><span class="pun" style="color: black;">+</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">1</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> </span><span class="str" style="color: maroon;">" = "</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> temperature</span><span class="pun" style="color: black;">[</span><span class="pln" style="color: black;">i</span><span class="pun" style="color: black;">][</span><span class="pln" style="color: black;">j</span><span class="pun" style="color: black;">]</span><span class="pln" style="color: black;"> </span><span class="pun" style="color: black;"><<</span><span class="pln" style="color: black;"> endl</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span><span class="pln" style="color: black;">
</span><span class="kwd" style="color: darkblue;">return</span><span class="pln" style="color: black;"> </span><span class="lit" style="color: maroon;">0</span><span class="pun" style="color: black;">;</span><span class="pln" style="color: black;">
</span><span class="pun" style="color: black;">}</span></code></pre>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0tag:blogger.com,1999:blog-1033148957699292242.post-35377000571681434752019-04-29T10:31:00.001-07:002019-05-22T09:58:25.137-07:00first program grade<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiORegsqwtbWVsKvT3vN2H73KAd73xqtkmuuDXFGPmHuIpechYTYO_2cj-3RFpyAJlJRsTkD2B-EQDef55gqsDff1iMSJaot1mbsmd0EQvYEL3YOKB9YqkwXM5p-6iMQpZrGXiUrfQLxQw/s1600/c.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="709" data-original-width="712" height="318" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiORegsqwtbWVsKvT3vN2H73KAd73xqtkmuuDXFGPmHuIpechYTYO_2cj-3RFpyAJlJRsTkD2B-EQDef55gqsDff1iMSJaot1mbsmd0EQvYEL3YOKB9YqkwXM5p-6iMQpZrGXiUrfQLxQw/s320/c.jpg" width="320" /></a></div>
<br />
<br />
<table class="split" style="background-color: white; color: black; font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; width: 728px;"><tbody>
<tr><td class="rownum" style="color: #a0a0a0; min-width: 20px; text-align: right; vertical-align: top;"><pre><code>1
2
3
4
5
6
7</code></pre>
</td><td class="source" style="background: rgb(239, 239, 255); border: 1px solid rgb(192, 192, 208); vertical-align: top; width: 347px;"><pre><code><cite style="color: #007000; font-style: normal;">// my first program in C++</cite>
<dfn style="color: #500070; font-style: normal;">#include <iostream></dfn>
<var style="color: #0000b0; font-style: normal;">int</var> main()
{
std::cout << <kbd style="color: #600030;">"Hello World!"</kbd>;
}</code></pre>
<pre><code>
</code></pre>
<pre><code>
</code></pre>
<pre><code>
</code></pre>
</td></tr>
</tbody></table>
<br />
<div>
<br /></div>
<div>
<div>
#include <iostream></div>
<div>
using namespace std;</div>
<div>
int main()</div>
<div>
{</div>
<div>
int i,j;</div>
<div>
cin>>i;</div>
<div>
char k;<span style="white-space: pre;"> </span></div>
<div>
<br /></div>
<div>
if(i<=100 && i>=90)</div>
<div>
k='A';</div>
<div>
if(i<90 && i>=50)</div>
<div>
k='B';</div>
<div>
if(i<50 && i>=30)</div>
<div>
k='C';</div>
<div>
if(i<30)</div>
<div>
k='D';</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<span style="white-space: pre;"> </span>cout << "\nplayer Grade "<< k;</div>
<div>
<span style="white-space: pre;"> </span></div>
<div>
<span style="white-space: pre;"> </span>return 0;</div>
<div>
<br /></div>
<div>
<span style="white-space: pre;"> </span></div>
<div>
}</div>
</div>
</div>
Nadeem Iqbalhttp://www.blogger.com/profile/02932562368362573846noreply@blogger.com0