<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4319573138870071470</id><updated>2024-09-13T06:53:10.210-07:00</updated><category term="C/C++"/><title type='text'>C/C++ Tutorials</title><subtitle type='html'>wlanguages.co.cc HTML ,XHTML Tutorials ,Java Tutorials&#xa;SQL Tutorials ,JavaScript Tutorials ,CSS Tutorials&#xa; ,PHP Tutorials ,ASP.Net Tutorials ,MY SQL Tutorials ,VB.Net Tutorials ,C/C++ Tutorials ,Learn Ruby ,Learn Ruby on Rails ,Ruby on Rails-2.1 ,Learn Python ,Learn Python/DB ,Learn Python/CGI ,Learn Python/XML</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-2222529954967688666</id><published>2010-09-01T04:52:00.001-07:00</published><updated>2011-04-10T04:35:21.983-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>C - Programming HOME</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; line-height: 24px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;middle&quot; width=&quot;100&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #38761d;&quot;&gt;C Introduction&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;img alt=&quot;picture&quot; border=&quot;0&quot; src=&quot;http://www.tutorialspoint.com/images/c.gif&quot; style=&quot;border-bottom-style: solid; border-bottom-width: 0px; border-color: initial; border-color: initial; border-left-style: solid; border-left-width: 0px; border-right-style: solid; border-right-width: 0px; border-style: initial; border-top-style: solid; border-top-width: 0px; border-width: initial; padding-right: 5px;&quot; /&gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;The C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;C is the most widely used computer language.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;This tutorial should be your starting point only.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;This tutorial is a port of the&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;b&gt;C++ tutorial&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;b&gt;but is designed to be a stand-alone introduction to C, even if you&#39;ve never programmed before. Unless you have a particular reason to learn C instead of C++, I recommend starting the C++ tutorial instead. Nevertheless, if you do not desire some of C++&#39;s advanced features or simply wish to start with a slightly less complicated language, then this tutorial is for you!&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: verdana, sans-serif; font-size: 11px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;C is a programming language of many different dialects, similar to the way that each spoken language has many different dialects. In C, dialects don&#39;t exist because the speakers live in the North or South. Instead, they&#39;re there because there are many different compilers that support slightly different features. There are several common compilers: in particular,&amp;nbsp;&lt;/b&gt;&lt;b&gt;Borland C++&lt;/b&gt;&lt;b&gt;,&amp;nbsp;&lt;/b&gt;&lt;b&gt;Microsoft C++&lt;/b&gt;&lt;b&gt;, and&amp;nbsp;&lt;/b&gt;&lt;b&gt;GNU C&lt;/b&gt;&lt;b&gt;. There are also many front-end environments for the different compilers--the most common is&amp;nbsp;&lt;/b&gt;&lt;b&gt;Dev-C++&lt;/b&gt;&lt;b&gt;&amp;nbsp;around GNU&#39;s G++ compiler. Some, such as GCC, are free, while others are not. Please see the&amp;nbsp;&lt;/b&gt;&lt;b&gt;compiler listing&lt;/b&gt;&lt;b&gt;&amp;nbsp;for more information on how to get a compiler and set it up. You should note that if you are programming in C on a C++ compiler, then you will want to make sure that your compiler attempts to compile C instead of C++ to avoid small compatability issues in later tutorials.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/2222529954967688666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/09/c-is-general-purpose-procedural.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/2222529954967688666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/2222529954967688666'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/09/c-is-general-purpose-procedural.html' title='C - Programming HOME'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-7895473619430663460</id><published>2010-08-31T11:26:00.000-07:00</published><updated>2011-04-10T04:35:21.984-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Built-in Functions</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;String Manipulation Functions&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strcpy (char *dest, char *src);&lt;br /&gt;
Copy src string into dest string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strncpy(char *string1, char *string2, int n);&lt;br /&gt;
Copy first n characters of string2 to stringl .&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int strcmp(char *string1, char *string2);&lt;br /&gt;
Compare string1 and string2 to determine alphabetic order.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int strncmp(char *string1, char *string2, int n);&lt;br /&gt;
Compare first n characters of two strings.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int strlen(char *string);&lt;br /&gt;
Determine the length of a string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strcat(char *dest, const char *src);&lt;br /&gt;
Concatenate string src to the string dest.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strncat(char *dest, const char *src, int n);&lt;br /&gt;
Concatenate n chracters from string src to the string dest.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strchr(char *string, int c);&lt;br /&gt;
Find first occurrence of character c in string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strrchr(char *string, int c);&lt;br /&gt;
Find last occurrence of character c in string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strstr(char *string2, char string*1);&lt;br /&gt;
Find first occurrence of string string1 in string2.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strtok(char *s, const char *delim)&amp;nbsp;;&lt;br /&gt;
Parse the string s into tokens using delim as delimiter.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Memory Management Functions&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void *calloc(int num elems, int elem_size);&lt;br /&gt;
Allocate an array and initialise all elements to zero .&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void free(void *mem address);&lt;br /&gt;
Free a block of memory.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void *malloc(int num bytes);&lt;br /&gt;
Allocate a block of memory.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void *realloc(void *mem address, int newsize);&lt;br /&gt;
Reallocate (adjust size) a block of memory.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Buffer Manipulation&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void* memcpy(void* s, const void* ct, int n);&lt;br /&gt;
Copies n characters from ct to s and returns s. s may be corrupted if objects overlap.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int memcmp(const void* cs, const void* ct, int n);&lt;br /&gt;
Compares at most (the first) n characters of cs and ct, returning negative value if cs&amp;lt;ct, zero if cs==ct, positive value if cs&amp;gt;ct.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void* memchr(const void* cs, int c, int n);&lt;br /&gt;
Returns pointer to first occurrence of c in first n characters of cs, or NULL if not found.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void* memset(void* s, int c, int n);&lt;br /&gt;
Replaces each of the first n characters of s by c and returns s.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void* memmove(void* s, const void* ct, int n);&lt;br /&gt;
Copies n characters from ct to s and returns s. s will not be corrupted if objects overlap.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Character Functions&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isalnum(int c);&lt;br /&gt;
The function returns nonzero if c is alphanumeric&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isalpha(int c);&lt;br /&gt;
The function returns nonzero if c is alphabetic only&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int iscntrl(int c);&lt;br /&gt;
The function returns nonzero if c is a control chracter&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isdigit(int c);&lt;br /&gt;
The function returns nonzero if c is a numeric digit&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isgraph(int c);&lt;br /&gt;
The function returns nonzero if c is any character for which either isalnum or ispunct returns nonzero.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int islower(int c);&lt;br /&gt;
The function returns nonzero if c is a lower case character.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;a class=&quot;func&quot; href=&quot;http://www.tutorialspoint.com/ansi_c/c_isprint.htm&quot; style=&quot;background-color: transparent; color: #900b09; text-decoration: none;&quot;&gt;int isprint(int c);&lt;/a&gt;&lt;br /&gt;
The function returns nonzero if c is space or a character for which isgraph returns nonzero.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int ispunct(int c);&lt;br /&gt;
The function returns nonzero if c is punctuation&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isspace(int c);&lt;br /&gt;
The function returns nonzero if c is space character&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isupper(int c);&lt;br /&gt;
The function returns nonzero if c is upper case character&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int isxdigit(int c);&lt;br /&gt;
The function returns nonzero if c is hexa digit&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int tolower(int c);&lt;br /&gt;
The function returns the corresponding lowercase letter if one exists and if isupper(c); otherwise, it returns c.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int toupper(int c);&lt;br /&gt;
The function returns the corresponding uppercase letter if one exists and if islower(c); otherwise, it returns c.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Error Handling Functions&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void perror(const char *s);&lt;br /&gt;
produces a message on standard error output describing the last error encountered.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strerror(int errnum );&lt;br /&gt;
returns a string describing the error code passed in the argument errnum.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/7895473619430663460/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/string-manipulation-functions-char.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7895473619430663460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7895473619430663460'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/string-manipulation-functions-char.html' title='Built-in Functions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-982751183971356112</id><published>2010-08-31T11:23:00.001-07:00</published><updated>2011-04-10T04:35:21.984-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Useful Concepts</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Error Reporting:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Many times it is useful to report errors in a C program. The standard library perror() is an easy to use and convenient function. It is used in conjunction with errno and frequently on encountering an error you may wish to terminate your program early. We will meet these concepts in other parts of the function reference chapter also.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void perror(const char *message)&amp;nbsp;- produces a message on standard error output describing the last error encountered.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;errno:&lt;/b&gt;&amp;nbsp;- is a special system variable that is set if a system call cannot perform its set task. It is defined in #include &amp;lt;errno.h&amp;gt;.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Predefined Streams:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;UNIX defines 3 predefined streams ie. virtual files&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;stdin,  stdout,  stderr 
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;They all use text a the method of I/O. stdin and stdout can be used with files, programs, I/O devices such as keyboard, console, etc.. stderr always goes to the console or screen.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The console is the default for stdout and stderr. The keyboard is the default for stdin.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Dynamic Memory Allocation:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Dynamic allocation is a pretty unique feature to C. It enables us to create data types and structures of any size and length to suit our programs need within the program. We use dynamic memory allocation concept when we don&#39;t know how in advance about memory requirement.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following functions to use for dynamic memory manipulation:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void *calloc(size_t num elems, size_t elem_size)&amp;nbsp;- Allocate an array and initialise all elements to zero .&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void free(void *mem address)&amp;nbsp;- Free a block of memory.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void *malloc(size_t num bytes)&amp;nbsp;- Allocate a block of memory.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;void *realloc(void *mem address, size_t newsize)&amp;nbsp;- Reallocate (adjust size) a block of memory.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Command Line Arguments:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It is possible to pass arguments to C programs when they are executed. The brackets which follow main are used for this purpose. argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument which is passed to&amp;nbsp;&lt;i&gt;main&lt;/i&gt;A simple example follows, which checks to see if a single argument is supplied on the command line when the program is invoked.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.&amp;gt;h
main( int argc, char *argv[] )  
{
   if( argc == 2 )
      printf(&quot;The argument supplied is %s\n&quot;, argv[1]);
   else if( argc &amp;gt; 2 )
      printf(&quot;Too many arguments supplied.\n&quot;);
   else
      printf(&quot;One argument expected.\n&quot;);
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Note that *argv[0] is the name of the program invoked, which means that *argv[1] is a pointer to the first argument supplied, and *argv[n] is the last argument. If no arguments are supplied, argc will be one. Thus for n arguments, argc will be equal to n + 1. The program is called by the command line:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;$myprog  argument1
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;More clearly, Suppose a program is compiled to an executable program myecho and that the program is executed with the following command.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;$myeprog aaa bbb ccc
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When this command is executed, the command interpreter calls the main() function of the myprog program with 4 passed as the argc argument and an array of 4 strings as the argv argument.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;argv[0]         -  &quot;myprog&quot;
argv[1]  -  &quot;aaa&quot;
argv[2]  -  &quot;bbb&quot;
argv[3]  -  &quot;ccc&quot;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Multidimensional Arrays:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The array we used in the last example was a one dimensional array. Arrays can have more than one dimension, these arrays-of-arrays are called multidimensional arrays. They are very similar to standard arrays with the exception that they have multiple sets of square brackets after the array identifier. A two dimensional array can be though of as a grid of rows and columns.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

const int num_rows = 7;
const int num_columns = 5;

int
main()
{
  int box[num_rows][num_columns];
  int row, column;

  for(row = 0; row &amp;lt; num_rows; row++)
    for(column = 0; column &amp;lt; num_columns; column++)
      box[row][column] = column + (row * num_columns);

  for(row = 0; row &amp;lt; num_rows; row++)
    {
      for(column = 0; column &amp;lt; num_columns; column++)
        {
          printf(&quot;%4d&quot;, box[row][column]);
        }
      printf(&quot;\n&quot;);
    }
  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following result:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;0   1   2   3   4
   5   6   7   8   9
  10  11  12  13  14
  15  16  17  18  19
  20  21  22  23  24
  25  26  27  28  29
  30  31  32  33  34
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The above array has two dimensions and can be called a doubly subscripted array. GCC allows arrays of up to 29 dimensions although actually using an array of more than three dimensions is very rare.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/982751183971356112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/error-reporting-many-times-it-is-useful.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/982751183971356112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/982751183971356112'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/error-reporting-many-times-it-is-useful.html' title='Useful Concepts'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-418127322797218251</id><published>2010-08-31T11:22:00.001-07:00</published><updated>2011-04-10T04:35:21.984-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Pre-Processors</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The C Preprocessor is not part of the compiler, but is a separate step in the compilation process. In simplistic terms, a C Preprocessor is just a text substitution tool. We&#39;ll refer to the C Preprocessor as the CPP.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;All preprocessor lines begin with #&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The unconditional directives are:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#include - Inserts a particular header from another file&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#define - Defines a preprocessor macro&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#undef - Undefines a preprocessor macro&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The conditional directives are:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#ifdef - If this macro is defined&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#ifndef - If this macro is not defined&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#if - Test if a compile time condition is true&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#else - The alternative for #if&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#elif - #else an #if in one statement&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;#endif - End preprocessor conditional&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Other directives include:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;# - Stringization, replaces a macro parameter with a string constant&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;## - Token merge, creates a single token from two adjacent ones&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Pre-Processors Examples:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Analyze following examples to understand various directives.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#define MAX_ARRAY_LENGTH 20
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Tells the CPP to replace instances of MAX_ARRAY_LENGTH with 20. Use&amp;nbsp;&lt;i&gt;#define&lt;/i&gt;for constants to increase readability.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
  #include &quot;myheader.h&quot;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Tells the CPP to get stdio.h from&amp;nbsp;&lt;b&gt;System Libraries&lt;/b&gt;&amp;nbsp;and add the text to this file. The next line tells CPP to get myheader.h from the local directory and add the text to the file.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#undef  FILE_SIZE
  #define FILE_SIZE 42
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Tells the CPP to undefine FILE_SIZE and define it for 42.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#ifndef MESSAGE
  #define MESSAGE &quot;You wish!&quot;
  #endif
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Tells the CPP to define MESSAGE only if MESSAGE isn&#39;t defined already.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#ifdef DEBUG
    /* Your debugging statements here */
  #endif
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Tells the CPP to do the following statements if DEBUG is defined. This is useful if you pass the&amp;nbsp;&lt;i&gt;-DDEBUG&lt;/i&gt;&amp;nbsp;flag to gcc. This will define DEBUG, so you can turn debugging on and off on the fly!&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Stringize (#):&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The stringize or number-sign operator (&#39;#&#39;), when used within a macro definition, converts a macro parameter into a string constant. This operator may be used only in a macro that has a specified argument or parameter list.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When the stringize operator immediately precedes the name of one of the macro parameters, the parameter passed to the macro is enclosed within quotation marks and is treated as a string literal. For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

#define   message_for(a, b)  \
          printf(#a &quot; and &quot; #b &quot;: We love you!\n&quot;)

int main(void)
{
   message_for(Carole, Debra);
   return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following result using stringization macro&amp;nbsp;&lt;i&gt;message_for&lt;/i&gt;&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Carole and Debra: We love you!
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Token Pasting (##):&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The token-pasting operator (##) within a macro definition combines two arguments. It permits two separate tokens in the macro definition to be joined into a single token.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If the name of a macro parameter used in the macro definition is immediately preceded or followed by the token-pasting operator, the macro parameter and the token-pasting operator are replaced by the value of the passed parameter.Text that is adjacent to the token-pasting operator that is not the name of a macro parameter is not affected. For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#define tokenpaster(n) printf (&quot;token&quot; #n &quot; = %d&quot;, token##n)

tokenpaster(34);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This example results in the following actual output from the preprocessor:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;printf (&quot;token34 = %d&quot;, token34);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This example shows the concatenation of token##n into token34. Both the stringize and the token-pasting operators are used in this example.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Parameterized Macros:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;One of the powerful functions of the CPP is the ability to simulate functions using parameterized macros. For example, we might have some code to square a number:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int square(int x) {
    return x * x;
  }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;We can instead rewrite this using a macro:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#define square(x) ((x) * (x))
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Macros with arguments must be defined using the #define directive before they can be used. The argument list is enclosed in parentheses and must immediately follow the macro name. Spaces are not allowed between and macro name and open parenthesis. For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#define MAX(x,y) ((x) &amp;gt; (y) ? (x) : (y))
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Macro Caveats:&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Macro definitions are not stored in the object file. They are only active for the duration of a single source file starting when they are defined and ending when they are undefined (using #undef), redefined, or when the end of the source file is found.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Macro definitions you wish to use in multiple source files may be defined in an include file which may be included in each source file where the macros are required.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When a macro with arguments is invoked, the macro processor substitutes the arguments into the macro body and then processes the results again for additional macro calls. This makes it possible, but confusing, to piece together a macro call from the macro body and from the macro arguments.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Most experienced C programmers enclose macro arguments in parentheses when they are used in the macro body. This technique prevents undesired grouping of compound expressions used as arguments and helps avoid operator precedence rules overriding the intended meaning of a macro.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;While a macro may contain references to other macros, references to itself are not expanded. Self-referencing macros are a special feature of ANSI Standard C in that the self-reference is not interpreted as a macro call. This special rule also applies to indirectly self-referencing macros (or macros that reference themselves through another macro).&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/418127322797218251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-preprocessor-is-not-part-of-compiler.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/418127322797218251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/418127322797218251'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-preprocessor-is-not-part-of-compiler.html' title='Pre-Processors'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-2558704090411806325</id><published>2010-08-31T11:21:00.000-07:00</published><updated>2011-04-10T04:35:21.984-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Bits Manipulation</title><content type='html'>&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a byte. C language is very efficient in manipulating bits.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Here are following operators to perform bits manipulation:&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px; text-align: justify;&quot;&gt;Bitwise Operators:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Bitwise operator works on bits and perform bit by bit operation.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Assume if B = 60; and B = 13; Now in binary format they will be as follows:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;A = 0011 1100&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;B = 0000 1101&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;-----------------&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;A&amp;amp;B = 0000 1000&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;A|B = 0011 1101&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;A^B = 0011 0001&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;~A&amp;nbsp; = 1100 0011&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Show Examples&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;There are following Bitwise operators supported by C language&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;10%&quot;&gt;Operator&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;45%&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary AND Operator copies a bit to the result if it exists in both operands.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;amp; B) will give 12 which is 0000 1100&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;|&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary OR Operator copies a bit if it exists in eather operand.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A | B) will give 61 which is 0011 1101&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;^&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary XOR Operator copies the bit if it is set in one operand but not both.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A ^ B) will give 49 which is 0011 0001&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;~&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary Ones Complement Operator is unary and has the efect of &#39;flipping&#39; bits.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(~A ) will give -60 which is 1100 0011&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt;&amp;lt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A &amp;lt;&amp;lt; 2 will give 240 which is 1111 0000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;gt;&amp;gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A &amp;gt;&amp;gt; 2 will give 15 which is 0000 1111&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;The shift operators perform appropriate shift by operator on the right to the operator on the left. The right operator must be positive. The vacated bits are filled with zero.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;For example: x &amp;lt;&amp;lt; 2 shifts the bits in x by 2 places to the left.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;if x = 00000010 (binary) or 2 (decimal)

then: 
x &amp;gt;&amp;gt;= 2 =&amp;gt; x = 00000000 or just 0 (decimal)

Also: if x = 00000010 (binary) or 2 (decimal) 
then
x &amp;lt;&amp;lt;= 2 =&amp;gt; x = 00001000 or 8 (decimal) 
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Therefore a shift left is equivalent to a multiplication by 2. Similarly a shift right is equal to division by 2. Shifting is much faster than actual multiplication (*) or division (/) by 2. So if you want fast multiplications or division by 2 use shifts.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;To illustrate many points of bitwise operators let us write a function, Bitcount, that counts bits set to 1 in an 8 bit number (unsigned char) passed as an argument to the function.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int bitcount(unsigned char x) 
{ 
   int count;
   
   for ( count=0; x != 0; x&amp;gt;&amp;gt;=1);
   {
      if ( x &amp;amp; 01)
         count++;
   }

   return count;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;This function illustrates many C program points:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;for loop not used for simple counting operation.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;x &amp;gt;&amp;gt;= 1 =&amp;gt; x = x&amp;gt;&amp;gt; 1;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;for loop will repeatedly shift right x until x becomes 0&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;use expression evaluation of x &amp;amp; 01 to control if&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;x &amp;amp; 01 masks of 1st bit of x if this is 1 then count++&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px; text-align: justify;&quot;&gt;Bit Fields&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Bit Fields allow the packing of data in a structure. This is especially useful when memory or data storage is at a premium. Typical examples:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;Packing several objects into a machine word. e.g. 1 bit flags can be compacted.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;Reading external file formats -- non-standard file formats could be read in. E.g. 9 bit integers.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;C allows us do this in a structure definition by putting :bit length after the variable.For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;struct packed_struct {
  unsigned int f1:1;
  unsigned int f2:1;
  unsigned int f3:1;
  unsigned int f4:1;
  unsigned int type:4;
  unsigned int my_int:9;
} pack;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Here the packed_struct contains 6 members: Four 1 bit flags f1..f3, a 4 bit type and a 9 bit my_int.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;C automatically packs the above bit fields as compactly as possible, provided that the maximum length of the field is less than or equal to the integer word length of the computer. If this is not the case then some compilers may allow memory overlap for the fields whilst other would store the next field in the next word.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/2558704090411806325/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/bit-manipulation-is-act-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/2558704090411806325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/2558704090411806325'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/bit-manipulation-is-act-of.html' title='Bits Manipulation'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-4878977919899623290</id><published>2010-08-31T11:20:00.000-07:00</published><updated>2011-04-10T04:35:21.985-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Working with Files</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When accessing files through C, the first necessity is to have a way to access the files. For C File I/O you need to use a FILE pointer, which will let the program keep track of the file being accessed. For Example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;FILE *fp;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;To open a file you need to use the&amp;nbsp;&lt;b&gt;fopen&lt;/b&gt;&amp;nbsp;function, which returns a FILE pointer. Once you&#39;ve opened a file, you can use the FILE pointer to let the compiler perform input and output functions on the file.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;FILE *fopen(const char *filename, const char *mode);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here filename is string literal which you will use to name your file and mode can have one of the following values&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;w  - open for writing (file need not exist)
a  - open for appending (file need not exist)
r+ - open for reading and writing, start at beginning
w+ - open for reading and writing (overwrite file)
a+ - open for reading and writing (append if file exists)
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Note that it&#39;s possible for fopen to fail even if your program is perfectly correct: you might try to open a file specified by the user, and that file might not exist (or it might be write-protected). In those cases, fopen will return 0, the NULL pointer.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here&#39;s a simple example of using fopen:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;FILE *fp;

fp=fopen(&quot;/home/tutorialspoint/test.txt&quot;, &quot;r&quot;);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This code will open test.txt for reading in text mode. To open a file in a binary mode you must add a b to the end of the mode string; for example, &quot;rb&quot; (for the reading and writing modes, you can add the b either after the plus sign - &quot;r+b&quot; - or before - &quot;rb+&quot;)&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;To close a function you can use the function:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int fclose(FILE *a_file);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;fclose returns zero if the file is closed successfully.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;An example of fclose is:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;fclose(fp);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;To work with text input and output, you use fprintf and fscanf, both of which are similar to their friends printf and scanf except that you must pass the FILE pointer as first argument.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Try out following example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

main()
{
   FILE *fp;

   fp = fopen(&quot;/tmp/test.txt&quot;, &quot;w&quot;);
   fprintf(fp, &quot;This is testing...\n&quot;);
   fclose(fp;);

}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Thsi will create a file&amp;nbsp;&lt;i&gt;test.txt&lt;/i&gt;&amp;nbsp;in /tmp directory and will write&amp;nbsp;&lt;i&gt;This is testing&lt;/i&gt;&amp;nbsp;in that file.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here is an example which will be used to read lines from a file:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

main()
{
   FILE *fp;
   char buffer[20];

   fp = fopen(&quot;/tmp/test.txt&quot;, &quot;r&quot;);
   fscanf(fp, &quot;%s&quot;, buffer);
   printf(&quot;Read Buffer: %s\n&quot;, %buffer );
   fclose(fp;);

}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It is also possible to read (or write) a single character at a time--this can be useful if you wish to perform character-by-character input. The&amp;nbsp;&lt;i&gt;fgetc&lt;/i&gt;&amp;nbsp;function, which takes a file pointer, and returns an int, will let you read a single character from a file:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int fgetc (FILE *fp);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The&amp;nbsp;&lt;i&gt;fgetc&lt;/i&gt;&amp;nbsp;returns an int. What this actually means is that when it reads a normal character in the file, it will return a value suitable for storing in an unsigned char (basically, a number in the range 0 to 255). On the other hand, when you&#39;re at the very end of the file, you can&#39;t get a character value--in this case, fgetc will return &quot;EOF&quot;, which is a constnat that indicates that you&#39;ve reached the end of the file.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The&amp;nbsp;&lt;i&gt;fputc&lt;/i&gt;&amp;nbsp;function allows you to write a character at a time--you might find this useful if you wanted to copy a file character by character. It looks like this:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int fputc( int c, FILE *fp );
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Note that the first argument should be in the range of an unsigned char so that it is a valid character. The second argument is the file to write to. On success, fputc will return the value c, and on failure, it will return EOF.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Binary I/O&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following two functions which will be used for binary input and output:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;size_t fread(void *ptr, size_t size_of_elements, 
                        size_t number_of_elements, FILE *a_file);
              
size_t fwrite(const void *ptr, size_t size_of_elements, 
                        size_t number_of_elements, FILE *a_file);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Both of these functions deal with blocks of memories - usually arrays. Because they accept pointers, you can also use these functions with other data structures; you can even write structs to a file or a read struct into memory.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/4878977919899623290/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/when-accessing-files-through-c-first.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/4878977919899623290'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/4878977919899623290'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/when-accessing-files-through-c-first.html' title='Working with Files'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-6914719720209832788</id><published>2010-08-31T11:18:00.001-07:00</published><updated>2011-04-10T04:35:21.985-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Str Datatypes</title><content type='html'>&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;A structure in C is a collection of items of different types. You can think of a structure as a &quot;record&quot; is in Pascal or a class in Java without methods.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;Structures, or structs, are very useful in creating data structures larger and more complex than the ones we have discussed so far.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;Simply you can group various built-in data types into a structure.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;Object conepts was derived from Structure concept. You can achieve few object oriented goals using C structure but it is very complex.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Following is the example how to define a structure.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;struct student {
    char firstName[20];
    char lastName[20];
    char SSN[9];
    float gpa;
  };
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Now you have a new datatype called student and you can use this datatype define your variables of&amp;nbsp;&lt;i&gt;student&lt;/i&gt;&amp;nbsp;type:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;struct student student_a, student_b;

or an array of students as

struct student students[50];
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Another way to declare the same thing is:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;struct {
    char firstName[20];
    char lastName[20];
    char SSN[10];
    float gpa;
  } student_a, student_b;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;All the variables inside an structure will be accessed using these values as&lt;i&gt;student_a.firstName&lt;/i&gt;&amp;nbsp;will give value of&amp;nbsp;&lt;i&gt;firstName&lt;/i&gt;&amp;nbsp;variable. Similarly we can aqccess other variables.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px; text-align: justify;&quot;&gt;Structure Example:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Try out following example to understand the concept:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
struct student {
    char firstName[20];
    char lastName[20];
    char SSN[10];
    float gpa;
};

main()
{
  struct student student_a;

  strcpy(student_a.firstName, &quot;Deo&quot;);
  strcpy(student_a.lastName, &quot;Dum&quot;);
  strcpy(student_a.SSN, &quot;2333234&quot; );
  student_a.gpa = 2009.20;

 printf( &quot;First Name: %s\n&quot;, student_a.firstName );
 printf( &quot;Last Name: %s\n&quot;, student_a.lastName );
 printf( &quot;SNN : %s\n&quot;, student_a.SSN );
 printf( &quot;GPA : %f\n&quot;, student_a.gpa );
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;This will produce following results:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;First Name: Deo
Last Name: Dum
SSN : 2333234
GPA : 2009.20
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px; text-align: justify;&quot;&gt;Pointers to Structs:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Sometimes it is useful to assign pointers to structures (this will be evident in the next section with self-referential structures). Declaring pointers to structures is basically the same as declaring a normal pointer:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;struct student *student_a;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;To dereference, you can use the infix operator: -&amp;gt;.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;printf(&quot;%s\n&quot;, student_a-&amp;gt;SSN);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px; text-align: justify;&quot;&gt;typedef Keyword&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;There is an easier way to define structs or you could &quot;alias&quot; types you create. For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;typedef struct{
    char firstName[20];
    char lastName[20];
    char SSN[10];
    float gpa;
  }student;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Now you can use&amp;nbsp;&lt;i&gt;student&lt;/i&gt;&amp;nbsp;directly to define variables of&amp;nbsp;&lt;i&gt;student&lt;/i&gt;&amp;nbsp;type without using struct keyword. Following is the example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;student student_a;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;You can use typedef for non-structs:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;typedef long int *pint32;

pint32 x, y, z;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;x, y and z are all pointers to long ints&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px; text-align: justify;&quot;&gt;Unions Datatype&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Unions are declared in the same fashion as structs, but have a fundamental difference. Only one item within the union can be used at any time, because the memory allocated for each item inside the union is in a shared memory location.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;Here is how we define a Union&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; text-align: justify; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;union Shape {
      int circle;
      int triangle;
      int ovel;
};
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; text-align: justify;&quot;&gt;We use union in such case where only one condition will be applied and only one variable will be used.&lt;/div&gt;&lt;hr style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px; height: 1px; text-align: justify;&quot; /&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px; text-align: justify;&quot;&gt;Conclusion:&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;You can create arrays of structs.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Structs can be copied or assigned.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;The &amp;amp; operator may be used with structs to show addresses.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Structs can be passed into functions. Structs can also be returned from functions.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Structs&amp;nbsp;&lt;b&gt;cannot&lt;/b&gt;&amp;nbsp;be compared!&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Structures can store non-homogenous data types into a single collection, much like an array does for common data (except it isn&#39;t accessed in the same manner).&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Pointers to structs have a special infix operator:&amp;nbsp;&lt;b&gt;-&amp;gt;&lt;/b&gt;&amp;nbsp;for dereferencing the pointer.&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;typedef can help you clear your code up and can help save some keystrokes.&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/6914719720209832788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/structure-in-c-is-collection-of-items.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/6914719720209832788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/6914719720209832788'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/structure-in-c-is-collection-of-items.html' title='Str Datatypes'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-5496677459584604381</id><published>2010-08-31T11:17:00.001-07:00</published><updated>2011-04-10T04:35:21.985-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Play with Strings</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;In C language Strings are defined as an array of characters or a pointer to a portion of memory containing ASCII characters. A string in C is a sequence of zero or more characters followed by a NULL &#39;\0&#39; character:&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It is important to preserve the NULL terminating character as it is how C defines and manages variable length strings. All the C standard library functions require this for successful operation.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;All the string handling functions are prototyped in: string.h or stdio.h standard header file. So while using any string related function, don&#39;t forget to include either stdio.h or string.h. May be your compiler differes so please check before going ahead.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If you were to have an array of characters WITHOUT the null character as the last element, you&#39;d have an ordinary character array, rather than a string constant.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;String constants have double quote marks around them, and can be assigned to char pointers as shown below. Alternatively, you can assign a string constant to a char array - either with no size specified, or you can specify a size, but don&#39;t forget to leave a space for the null character!&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;char *string_1 = &quot;Hello&quot;;
char string_2[] = &quot;Hello&quot;;
char string_3[6] = &quot;Hello&quot;;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Reading and Writing Strings:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;One possible way to read in a string is by using&amp;nbsp;&lt;i&gt;scanf&lt;/i&gt;. However, the problem with this, is that if you were to enter a string which contains one or more spaces, scanf would finish reading when it reaches a space, or if return is pressed. As a result, the string would get cut off. So we could use the&amp;nbsp;&lt;i&gt;gets&lt;/i&gt;&amp;nbsp;function&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A&amp;nbsp;&lt;i&gt;gets&lt;/i&gt;&amp;nbsp;takes just one argument - a char pointer, or the name of a char array, but don&#39;t forget to declare the array / pointer variable first! What&#39;s more, is that it automatically prints out a newline character, making the output a little neater.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A&amp;nbsp;&lt;i&gt;puts&lt;/i&gt;&amp;nbsp;function is similar to&amp;nbsp;&lt;i&gt;gets&lt;/i&gt;&amp;nbsp;function in the way that it takes one argument - a char pointer. This also automatically adds a newline character after printing out the string. Sometimes this can be a disadvantage, so&amp;nbsp;&lt;i&gt;printf&lt;/i&gt;&amp;nbsp;could be used instead.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
  char array1[50];
  char *array2;

  printf(&quot;Now enter another string less than 50&quot;);
  printf(&quot; characters with spaces: \n&quot;);
  gets(array1);

  printf(&quot;\nYou entered: &quot;);
  puts(array1);

  printf(&quot;\nTry entering a string less than 50&quot;);
  printf(&quot; characters, with spaces: \n&quot;);
  scanf(&quot;%s&quot;, array2);

  printf(&quot;\nYou entered: %s\n&quot;, array2);

  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following result:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Now enter another string less than 50 characters with spaces:
hello world

You entered: hello world

Try entering a string less than 50 characters, with spaces:
hello world

You entered: hello 
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;String Manipulation Functions&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strcpy (char *dest, char *src)&amp;nbsp;- Copy src string string into dest string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strncpy(char *string1, char *string2, int n)&amp;nbsp;- Copy first n characters of string2 to stringl .&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int strcmp(char *string1, char *string2)&amp;nbsp;- Compare string1 and string2 to determine alphabetic order.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int strncmp(char *string1, char *string2, int n)&amp;nbsp;- Compare first n characters of two strings.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int strlen(char *string)&amp;nbsp;- Determine the length of a string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strcat(char *dest, const char *src);&amp;nbsp;- Concatenate string src to the string dest.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strncat(char *dest, const char *src, int n);&amp;nbsp;- Concatenate n chracters from string src to the string dest.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strchr(char *string, int c)&amp;nbsp;- Find first occurrence of character c in string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strrchr(char *string, int c)&amp;nbsp;- Find last occurrence of character c in string.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strstr(char *string2, char string*1)&amp;nbsp;- Find first occurrence of string string1 in string2.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char *strtok(char *s, const char *delim)&amp;nbsp;- Parse the string s into tokens using delim as delimiter.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/5496677459584604381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/in-c-language-strings-are-defined-as.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/5496677459584604381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/5496677459584604381'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/in-c-language-strings-are-defined-as.html' title='Play with Strings'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-7143893793833390446</id><published>2010-08-31T11:16:00.001-07:00</published><updated>2011-04-10T04:35:21.985-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Using Functions</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A function is a module or block of program code which deals with a particular task. Making functions is a way of isolating one block of code from other independent blocks of code.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Functions serve two purposes.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;They allow a programmer to say: `this piece of code does a specific job which stands by itself and should not be mixed up with anyting else&#39;,&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Second they make a block of code reusable since a function can be reused in many different contexts without repeating parts of the program text.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A function can take a number of parameters, do required processing and then return a value. There may be a function which does not return any value.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You already have seen couple of built-in functions like printf(); Similar way you can define your own functions in C language.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Consider the following chunk of code&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int total = 10;
   printf(&quot;Hello World&quot;);
   total = total + l;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;To turn it into a function you simply wrap the code in a pair of curly brackets to convert it into a single compound statement and write the name that you want to give it in front of the brackets:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Demo()
{
   int total = 10;
   printf(&quot;Hello World&quot;);
   total = total + l;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;curved brackets after the function&#39;s name are required. You can pass one or more paramenters to a function as follows:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Demo( int par1, int par2)
{
   int total = 10;
   printf(&quot;Hello World&quot;);
   total = total + l;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;By default function does not return anything. But you can make a function to return any value as follows:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int Demo( int par1, int par2)
{
   int total = 10;
   printf(&quot;Hello World&quot;);
   total = total + l;

   return total;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A&amp;nbsp;&lt;i&gt;return&lt;/i&gt;&amp;nbsp;keyword is used to return a value and datatype of the returned value is specified before the name of function. In this case function returns&amp;nbsp;&lt;i&gt;total&lt;/i&gt;&amp;nbsp;which is&amp;nbsp;&lt;i&gt;int&lt;/i&gt;type. If a function does not return a value then&amp;nbsp;&lt;i&gt;void&lt;/i&gt;&amp;nbsp;keyword can be used as return value.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Once you have defined your function you can use it within a program:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;main()
{
  Demo();
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Functions and Variables:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Each function behaves the same way as C language standard function&amp;nbsp;&lt;i&gt;main()&lt;/i&gt;. So a function will have its own local variables defined. In the above example&amp;nbsp;&lt;i&gt;total&lt;/i&gt;&amp;nbsp;variable is local to the function Demo.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A global variable can be accessed in any function in similar way it is accessed in&amp;nbsp;&lt;i&gt;main()&lt;/i&gt;function.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Declaration and Definition&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When a function is defined at any place in the program then it is called function definition. At the time of definition of a function actual logic is implemented with-in the function.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A function declaration does not have any body and they just have their interfaces.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A function declaration is usually declared at the top of a C source file, or in a separate header file.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A function declaration is sometime called function prototype or function signature. For the above&amp;nbsp;&lt;i&gt;Demo()&lt;/i&gt;&amp;nbsp;function which returns an integer, and takes two parameters a function declaration will be as follows:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int Demo( int par1, int par2);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Passing Parameters to a Function&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are two ways to pass parameters to a function:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Pass by Value:&lt;/b&gt;&amp;nbsp;mechanism is used when you don&#39;t want to change the value of passed paramters. When parameters are passed by value then functions in C create copies of the passed in variables and do required processing on these copied variables.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Pass by Reference&lt;/b&gt;&amp;nbsp;mechanism is used when you want a function to do the changes in passed parameters and reflect those changes back to the calling function. In this case only addresses of the variables are passed to a function so that function can work directly over the addresses.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here are two programs to understand the difference: First example is for&amp;nbsp;&lt;i&gt;Pass by value:&lt;/i&gt;&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

/* function declaration goes here.*/
void swap( int p1, int p2 );

int main()
{
   int a = 10;
   int b = 20;

   printf(&quot;Before: Value of a = %d and value of b = %d\n&quot;, a, b );
   swap( a, b );
   printf(&quot;After: Value of a = %d and value of b = %d\n&quot;, a, b );
}

void swap( int p1, int p2 )
{
    int t;

    t = p2;
    p2 = p1;
    p1 = t;
   printf(&quot;Value of a (p1) = %d and value of b(p2) = %d\n&quot;, p1, p2 );
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here is the result produced by the above example. Here the values of a and b remain unchanged before calling&amp;nbsp;&lt;i&gt;swap&lt;/i&gt;&amp;nbsp;function and after calling&amp;nbsp;&lt;i&gt;swap&lt;/i&gt;&amp;nbsp;function.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Before: Value of a = 10 and value of b = 20
Value of a (p1) = 20 and value of b(p2) = 10
After: Value of a = 10 and value of b = 20
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Following is the example which demonstrate the concept of pass by reference&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

/* function declaration goes here.*/
void swap( int *p1, int *p2 );

int main()
{
   int a = 10;
   int b = 20;

   printf(&quot;Before: Value of a = %d and value of b = %d\n&quot;, a, b );
   swap( &amp;amp;a, &amp;amp;b );
   printf(&quot;After: Value of a = %d and value of b = %d\n&quot;, a, b );
}

void swap( int *p1, int *p2 )
{
    int t;

    t = *p2;
    *p2 = *p1;
    *p1 = t;
   printf(&quot;Value of a (p1) = %d and value of b(p2) = %d\n&quot;, *p1, *p2 );
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here is the result produced by the above example. Here the values of a and b are changes after calling&amp;nbsp;&lt;i&gt;swap&lt;/i&gt;&amp;nbsp;function.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 503px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Before: Value of a = 10 and value of b = 20
Value of a (p1) = 20 and value of b(p2) = 10
After: Value of a = 20 and value of b = 10
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/7143893793833390446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/function-is-module-or-block-of-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7143893793833390446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7143893793833390446'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/function-is-module-or-block-of-program.html' title='Using Functions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-3817817873140488342</id><published>2010-08-31T11:15:00.000-07:00</published><updated>2011-04-10T04:35:21.986-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Pointing to Data</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk &#39;*&#39; in front of the variables identifier.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are two new operators you will need to know to work with pointers. The &quot;address of&quot; operator &#39;&amp;amp;&#39; and the &quot;dereferencing&quot; operator &#39;*&#39;. Both are prefix unary operators.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When you place an ampersand in front of a variable you will get it&#39;s address, this can be stored in a pointer vairable.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When you place an asterisk in front of a pointer you will get the value at the memory address pointed to.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here is an example to understand what I have stated above.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
  int my_variable = 6, other_variable = 10;
  int *my_pointer;

  printf(&quot;the address of my_variable is    : %p\n&quot;, &amp;amp;my_variable);
  printf(&quot;the address of other_variable is : %p\n&quot;, &amp;amp;other_variable);

  my_pointer = &amp;amp;my_variable;

  printf(&quot;\nafter \&quot;my_pointer = &amp;amp;my_variable\&quot;:\n&quot;);
  printf(&quot;\tthe value of my_pointer is %p\n&quot;, my_pointer);
  printf(&quot;\tthe value at that address is %d\n&quot;, *my_pointer);

  my_pointer = &amp;amp;other_variable;

  printf(&quot;\nafter \&quot;my_pointer = &amp;amp;other_variable\&quot;:\n&quot;);
  printf(&quot;\tthe value of my_pointer is %p\n&quot;, my_pointer);
  printf(&quot;\tthe value at that address is %d\n&quot;, *my_pointer);

  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following result.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;the address of my_variable is    : 0xbfffdac4
the address of other_variable is : 0xbfffdac0

after &quot;my_pointer = &amp;amp;my_variable&quot;:
        the value of my_pointer is 0xbfffdac4
        the value at that address is 6

after &quot;my_pointer = &amp;amp;other_variable&quot;:
        the value of my_pointer is 0xbfffdac0
        the value at that address is 10
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Pointers and Arrays&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The most frequent use of pointers in C is for walking efficiently along arrays. In fact, in the implementation of an array, the array name represents the address of the zeroth element of the array, so you can&#39;t use it on the left side of an expression. For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;char *y;
   char x[100];
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;y is of type pointer to character (although it doesn&#39;t yet point anywhere). We can make y point to an element of x by either of&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;y = &amp;amp;x[0];
   y = x;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Since x is the address of x[0] this is legal and consistent. Now `*y&#39; gives x[0]. More importantly notice the following:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;*(y+1)  gives x[1]
   *(y+i)  gives x[i]

and the sequence

   y = &amp;amp;x[0];
   y++;

leaves y pointing at x[1].

&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Pointer Arithmetic:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C is one of the few languages that allows pointer arithmetic. In other words, you actually move the pointer reference by an arithmetic operation. For example:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int x = 5, *ip = &amp;amp;x;

  ip++;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;On a typical 32-bit machine, *ip would be pointing to 5 after initialization. But ip++; increments the pointer 32-bits or 4-bytes. So whatever was in the next 4-bytes, *ip would be pointing at it.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Pointer arithmetic is very useful when dealing with arrays, because arrays and pointers share a special relationship in C.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Using Pointer Arithmetic With Arrays:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Arrays occupy consecutive memory slots in the computer&#39;s memory. This is where pointer arithmetic comes in handy - if you create a pointer to the first element, incrementing it one step will make it point to the next element.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
  int *ptr;
  int arrayInts[10] = {1,2,3,4,5,6,7,8,9,10};

  ptr = arrayInts; &lt;i&gt;/* ptr = &amp;amp;arrayInts[0]; is also fine */&lt;/i&gt;

  printf(&quot;The pointer is pointing to the first &quot;);
  printf(&quot;array element, which is %d.\n&quot;, *ptr);
  printf(&quot;Let&#39;s increment it.....\n&quot;);

  ptr++;

  printf(&quot;Now it should point to the next element,&quot;);
  printf(&quot; which is %d.\n&quot;, *ptr);
  printf(&quot;But suppose we point to the 3rd and 4th: %d %d.\n&quot;, 
          *(ptr+1),*(ptr+2));

  ptr+=2;

  printf(&quot;Now skip the next 4 to point to the 8th: %d.\n&quot;, 
          *(ptr+=4));

  ptr--;

  printf(&quot;Did I miss out my lucky number %d?!\n&quot;, *(ptr++));
  printf(&quot;Back to the 8th it is then..... %d.\n&quot;, *ptr);

  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following result:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;The pointer is pointing to the first array element, which is 1.
Let&#39;s increment it.....
Now it should point to the next element, which is 2.
But suppose we point to the 3rd and 4th: 3 4.
Now skip the next 4 to point to the 8th: 8.
Did I miss out my lucky number 7?!
Back to the 8th it is then..... 8. 
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;See more examples on&amp;nbsp;&lt;a href=&quot;http://www.tutorialspoint.com/ansi_c/c_array_pointers_examples.htm&quot; style=&quot;background-color: transparent; color: #900b09;&quot;&gt;Pointers and Array&lt;/a&gt;&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Pointers and const Type Qualifier:&lt;/h1&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;The&amp;nbsp;&lt;b&gt;const&lt;/b&gt;&amp;nbsp;type qualifier can make things a little confusing when it is used with pointer declarations.&lt;/li&gt;
&lt;li&gt;The below example:&lt;/li&gt;
&lt;/ul&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;const int * const ip;  /* The pointer *ip is const
                            and it points at is also cont */
        int * const ip;  /* The pointer *ip is const              */
  const int *       ip;  /* What *ip is pointing at is const      */
        int *       ip;  /* Nothing is const                      */
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;As you can see, you must be careful when specifying the&amp;nbsp;&lt;b&gt;const qualifier&lt;/b&gt;&amp;nbsp;when using pointers.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Modifying Variables Using Pointers:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You know how to access the value pointed to using the dereference operator, but you can also modify the content of variables. To achieve this, put the dereferenced pointer on the left of the assignment operator, as shown in this example, which uses an array:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
  char *ptr;
  char arrayChars[8] = {&#39;F&#39;,&#39;r&#39;,&#39;i&#39;,&#39;e&#39;,&#39;n&#39;,&#39;d&#39;,&#39;s&#39;,&#39;\0&#39;};

  ptr = arrayChars;

  printf(&quot;The array reads %s.\n&quot;, arrayChars);
  printf(&quot;Let&#39;s change it..... &quot;);

  *ptr = &#39;f&#39;; &lt;i&gt;/* ptr points to the first element */&lt;/i&gt;

  printf(&quot; now it reads %s.\n&quot;, arrayChars);
  printf(&quot;The 3rd character of the array is %c.\n&quot;, 
          *(ptr+=2));
  printf(&quot;Let&#39;s change it again..... &quot;);

  *(ptr - 1) = &#39; &#39;;

  printf(&quot;Now it reads %s.\n&quot;, arrayChars);
  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following result:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;The array reads Friends.
Let&#39;s change it..... now it reads friends.
The 3rd character of the array is i.
Let&#39;s change it again..... Now it reads f iends. 
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Generic Pointers: ( void Pointer )&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When a variable is declared as being a pointer to type void it is known as a generic pointer. Since you cannot have a variable of type void, the pointer will not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just have to cast it to another kind of pointer first. Hence the term Generic pointer. This is very useful when you want a pointer to point to data of different types at different times.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Try the following code to understand Generic Pointers.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
  int i;
  char c;
  void *the_data;

  i = 6;
  c = &#39;a&#39;;

  the_data = &amp;amp;i;
  printf(&quot;the_data points to the integer value %d\n&quot;, 
                         *(int*) the_data);

  the_data = &amp;amp;c;
  printf(&quot;the_data now points to the character %c\n&quot;, 
                         *(char*) the_data);

  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;NOTE-1 :&lt;/b&gt;&amp;nbsp;Here in first print statement, the_data is prefixed by&amp;nbsp;&lt;b&gt;*(int*)&lt;/b&gt;. This is called type casting in C language.Type is used to caste a variable from one data type to another datatype to make it compatible to the lvalue.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;NOTE-2 :&lt;/b&gt;&amp;nbsp;lvalue is something which is used to left side of a statement and in which we can assign some value. A constant can&#39;t be an lvalue because we can not assign any value in contact. For example x = y, here x is lvalue and y is rvalue.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;However, above example will produce following result:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 489px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;the_data points to the integer value 6
the_data now points to the character a
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/3817817873140488342/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/pointer-is-special-kind-of-variable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/3817817873140488342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/3817817873140488342'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/pointer-is-special-kind-of-variable.html' title='Pointing to Data'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-3558155439403464285</id><published>2010-08-31T11:13:00.001-07:00</published><updated>2011-04-10T04:35:21.986-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Input and Output</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Input :&lt;/b&gt;&amp;nbsp;In any programming language input means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Output :&lt;/b&gt;&amp;nbsp;In any programming language output means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output required data.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here we will discuss only one input function and one putput function just to understand the meaning of input and output. Rest of the functions are given intoC - Built-in Functions&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;printf() function&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This is one of the most frequently used functions in C for output. ( we will discuss what is function in subsequent chapter. ).&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Try following program to understand&amp;nbsp;&lt;b&gt;printf()&lt;/b&gt;&amp;nbsp;function.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

main()
{
  int dec = 5;
  char str[] = &quot;abc&quot;;
  char ch = &#39;s&#39;;
  float pi = 3.14;

  printf(&quot;%d %s %f %c\n&quot;, dec, str, pi,  ch);
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The output of the above would be:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;5 abc 3.140000 c
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here %d is being used to print an integer, %s is being usedto print a string, %f is being used to print a float and %c is being used to print a character.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A complete syntax of printf() function is given in&amp;nbsp;C - Built-in Functions&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;scanf() function&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This is the function which can be used to to read an input from the command line.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Try following program to understand&amp;nbsp;&lt;b&gt;scanf()&lt;/b&gt;&amp;nbsp;function.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

main()
{
  int x;
  int args;

  printf(&quot;Enter an integer: &quot;);
  if (( args = scanf(&quot;%d&quot;, &amp;amp;x)) == 0) {
      printf(&quot;Error: not an integer\n&quot;);
  } else {
      printf(&quot;Read in %d\n&quot;, x);
  }
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here %d is being used to read an integer value and we are passing &amp;amp;x to store the vale read input. Here &amp;amp;indicates the address of variavle x.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This program will prompt you to enter a value. Whatever value you will enter at command prompt that will be output at the screen using printf() function. If you eneter a non-integer value then it will display an error message.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Enter an integer: 20
Read in 20
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A complete set of input output functions is given in&amp;nbsp;C - Built-in Functions&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/3558155439403464285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/input-any-programming-language-input.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/3558155439403464285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/3558155439403464285'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/input-any-programming-language-input.html' title='Input and Output'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-355812408477480387</id><published>2010-08-31T11:12:00.001-07:00</published><updated>2011-04-10T04:35:21.986-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Control Statements</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C provides two sytles of flow control:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Branching&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Looping&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Branching is deciding what actions to take and looping is deciding how many times to take a certain action.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Branching:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Branching is so called because the program chooses to follow one branch or another.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;if statement&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This is the most simple form of the branching statements.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It takes an expression in parenthesis and an statement or block of statements. if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&amp;nbsp;Expression will be assumed to be true if its evaulated values is non-zero.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&amp;nbsp;statements take the following form:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;if (expression)
  statement;

or

if (expression)
  {
    Block of statements;
  }

or

if (expression)
  {
    Block of statements;
  }
else
  {
    Block of statements;
  }

or

if (expression)
  {
    Block of statements;
  }
else if(expression)
  {
    Block of statements;
  }
else
  {
    Block of statements;
  }

&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;? : Operator&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The ? : operator is just like an if ... else statement except that because it is an operator you can use it within expressions.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;? :&lt;/b&gt;&amp;nbsp;is a ternary operator in that it takes three values, this is the only ternary operator C has.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;? :&lt;/b&gt;&amp;nbsp;takes the following form:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;if condition is true ? then X return value : otherwise Y value;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;switch statement:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The switch statement is much like a nested if .. else statement. Its mostly a matter of preference which you use, switch statement can be slightly more efficient and easier to read.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;switch( expression )
     {
        case constant-expression1: statements1;
        [case constant-expression2: statements2;]    
        [case constant-expression3: statements3;]
        [default : statements4;]
     }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Using break keyword:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement. This is achieved by using&amp;nbsp;&lt;i&gt;break&lt;/i&gt;&amp;nbsp;keyword.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;What is default condition:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If none of the listed conditions is met then default condition executed.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;hr style=&quot;background-color: transparent; color: black; height: 1px;&quot; /&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Looping&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;while loop&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The most basic loop in C is the while loop.A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statments get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again.This cycle repeats until the test condition evaluates to false.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Basic syntax of while loop is as follows:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;while ( expression )
{
   Single statement 
   or
   Block of statements;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;for loop&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;for&lt;/b&gt;&amp;nbsp;loop is similar to while, it&#39;s just written differently. for statements are often used to proccess lists such a range of numbers:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Basic syntax of for loop is as follows:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;for( expression1; expression2; expression3)
{
   Single statement
   or
   Block of statements;
}

&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;In the above syntax:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;expression1 - Initialisese variables.&lt;/li&gt;
&lt;li&gt;expression2 - Condtional expression, as long as this condition is true, loop will keep executing.&lt;/li&gt;
&lt;li&gt;expression3 - expression3 is the modifier which may be simple increment of a variable.&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;do...while loop&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;do ... while&lt;/b&gt;&amp;nbsp;is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Basic syntax of do...while loop is as follows:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;do
{
   Single statement
   or
   Block of statements;
}while(expression);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;break and continue statements&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C provides two commands to control how we loop:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;break -- exit form loop or switch.&lt;/li&gt;
&lt;li&gt;continue -- skip 1 iteration of loop.&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You already have seen example of using break statement. Here is an example showing usage of&amp;nbsp;&lt;b&gt;continue&lt;/b&gt;&amp;nbsp;statement.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &lt;stdio.h&gt;

main()
{
    int i;
    int j = 10;

    for( i = 0; i &amp;lt;= j; i ++ )
    {
       if( i == 5 )
       {
          continue;
       }
       printf(&quot;Hello %d\n&quot;, i );
    }
}
&lt;/stdio.h&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce following output:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 6
Hello 7
Hello 8
Hello 9
Hello 10
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/355812408477480387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-provides-two-sytles-of-flow-control.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/355812408477480387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/355812408477480387'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-provides-two-sytles-of-flow-control.html' title='Control Statements'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-3108530673538306156</id><published>2010-08-31T11:11:00.000-07:00</published><updated>2011-04-10T04:35:21.986-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Operator Types</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;What is Operator?&lt;/b&gt;&amp;nbsp;Simple answer can be given using expression&amp;nbsp;&lt;i&gt;4 + 5 is equal to 9&lt;/i&gt;. Here 4 and 5 are called operands and + is called operator. C language supports following type of operators.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Arithmetic Operators&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Logical (or Relational) Operators&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Bitwise Operators&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Assignment Operators&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Misc Operators&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Lets have a look on all operators one by one.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Arithmetic Operators:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following arithmetic operators supported by C language:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Assume variable A holds 10 and variable holds 20 then:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.tutorialspoint.com/ansi_c/arithmatic_operators_examples.htm&quot; style=&quot;background-color: transparent; color: #900b09;&quot;&gt;Show Examples&lt;/a&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;10%&quot;&gt;Operator&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;45%&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;+&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Adds two operands&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A + B will give 30&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;-&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Subtracts second operand from the first&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A - B will give -10&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;*&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Multiply both operands&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A * B will give 200&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;/&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Divide numerator by denumerator&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;B / A will give 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;%&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Modulus Operator and remainder of after an integer division&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;B % A will give 0&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;++&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Increment operator, increases integer value by one&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A++ will give 11&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;--&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Decrement operator, decreases integer value by one&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A-- will give 9&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Logical (or Relational) Operators:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following logical operators supported by C language&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Assume variable A holds 10 and variable holds 20 then:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.tutorialspoint.com/ansi_c/logical_operators_examples.htm&quot; style=&quot;background-color: transparent; color: #900b09;&quot;&gt;Show Examples&lt;/a&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;10%&quot;&gt;Operator&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;45%&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;==&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Checks if the value of two operands is equal or not, if yes then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A == B) is not true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;!=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A != B) is true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;gt; B) is not true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;lt; B) is true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;gt;=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;gt;= B) is not true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt;=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;lt;= B) is true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;&amp;amp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Called Logical AND operator. If both the operands are non zero then then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;amp;&amp;amp; B) is true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;||&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Called Logical OR Operator. If any of the two operands is non zero then then condition becomes true.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A || B) is true.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;!&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;!(A &amp;amp;&amp;amp; B) is false.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Bitwise Operators:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Bitwise operator works on bits and perform bit by bit operation.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Assume if A = 60; and B = 13; Now in binary format they will be as follows:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A = 0011 1100&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;B = 0000 1101&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;-----------------&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A&amp;amp;B = 0000 1000&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A|B = 0011 1101&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A^B = 0011 0001&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;~A&amp;nbsp; = 1100 0011&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.tutorialspoint.com/ansi_c/bitwise_operators_examples.htm&quot; style=&quot;background-color: transparent; color: #900b09;&quot;&gt;Show Examples&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following Bitwise operators supported by C language&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;10%&quot;&gt;Operator&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;45%&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary AND Operator copies a bit to the result if it exists in both operands.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A &amp;amp; B) will give 12 which is 0000 1100&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;|&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary OR Operator copies a bit if it exists in eather operand.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A | B) will give 61 which is 0011 1101&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;^&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary XOR Operator copies the bit if it is set in one operand but not both.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(A ^ B) will give 49 which is 0011 0001&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;~&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary Ones Complement Operator is unary and has the efect of &#39;flipping&#39; bits.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;(~A ) will give -60 which is 1100 0011&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt;&amp;lt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A &amp;lt;&amp;lt; 2 will give 240 which is 1111 0000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;gt;&amp;gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;A &amp;gt;&amp;gt; 2 will give 15 which is 0000 1111&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Assignment Operators:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following assignment operators supported by C language:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.tutorialspoint.com/ansi_c/assignment_operators_examples.htm&quot; style=&quot;background-color: transparent; color: #900b09;&quot;&gt;Show Examples&lt;/a&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;10%&quot;&gt;Operator&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;40%&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Simple assignment operator, Assigns values from right side operands to left side operand&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C = A + B will assigne value of A + B into C&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;+=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C += A is equivalent to C = C + A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;-=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C -= A is equivalent to C = C - A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;*=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C *= A is equivalent to C = C * A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;/=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C /= A is equivalent to C = C / A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;%=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C %= A is equivalent to C = C % A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt;&amp;lt;=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left shift AND assignment operator&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C &amp;lt;&amp;lt;= 2 is same as C = C &amp;lt;&amp;lt; 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;gt;&amp;gt;=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Right shift AND assignment operator&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C &amp;gt;&amp;gt;= 2 is same as C = C &amp;gt;&amp;gt; 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Bitwise AND assignment operator&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C &amp;amp;= 2 is same as C = C &amp;amp; 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;^=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;bitwise exclusive OR and assignment operator&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C ^= 2 is same as C = C ^ 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;|=&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;bitwise inclusive OR and assignment operator&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;C |= 2 is same as C = C | 2&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Short Notes on L-VALUE and R-VALUE:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;x = 1; takes the value on the right (e.g. 1) and puts it in the memory referenced by x. Here x and 1 are known as L-VALUES and R-VALUES respectively L-values can be on either side of the assignment operator where as R-values only appear on the right.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;So x is an L-value because it can appear on the left as we&#39;ve just seen, or on the right like this: y = x; However, constants like 1 are R-values because 1 could appear on the right, but 1 = x; is invalid.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Misc Operators&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are few other operators supported by C Language.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.tutorialspoint.com/ansi_c/misc_operators_examples.htm&quot; style=&quot;background-color: transparent; color: #900b09;&quot;&gt;Show Examples&lt;/a&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;10%&quot;&gt;Operator&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot; width=&quot;40%&quot;&gt;Description&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;sizeof()&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Returns the size of an variable.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;sizeof(a), where a is interger, will return 4.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Returns the address of an variable.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;a; will give actaul address of the variable.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;*&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Pointer to a variable.&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;*a; will pointer to a variable.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;? :&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Conditional Expression&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;If Condition is true ? Then value X : Otherwise value Y&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Operators Categories:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;All the operators we have discussed above can be categorised into following categories:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Postfix operators, which follow a single operand.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Unary prefix operators, which precede a single operand.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Binary operators, which take two operands and perform a variety of arithmetic and logical operations.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The conditional operator (a ternary operator), which takes three operands and evaluates either the second or third expression, depending on the evaluation of the first expression.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Assignment operators, which assign a value to a variable.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The comma operator, which guarantees left-to-right evaluation of comma-separated expressions.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Precedence of C Operators:&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;For example x = 7 + 3 * 2; Here x is assigned 13, not 20 because operator * has higher precedenace than + so it first get multiplied with 3*2 and then adds into 7.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedenace operators will be evaluated first.&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Category&amp;nbsp;&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Operator&amp;nbsp;&lt;/th&gt;&lt;th style=&quot;background-color: #cdcdcd; font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Associativity&amp;nbsp;&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Postfix&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;() [] -&amp;gt; . ++ - - &amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Unary&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;+ - ! ~ ++ - - (type) * &amp;amp; sizeof&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Right to left&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Multiplicative &amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;* / %&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Additive &amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;+ -&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Shift &amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt;&amp;lt; &amp;gt;&amp;gt;&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Relational &amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;lt; &amp;lt;= &amp;gt; &amp;gt;=&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Equality &amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;== !=&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Bitwise AND&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Bitwise XOR&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;^&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Bitwise OR&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;|&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Logical AND&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&amp;amp;&amp;amp;&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Logical OR&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;||&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Conditional&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;?:&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Right to left&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Assignment&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;= += -= *= /= %= &amp;gt;&amp;gt;= &amp;lt;&amp;lt;= &amp;amp;= ^= |=&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Right to left&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Comma&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;,&amp;nbsp;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;Left to right&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/3108530673538306156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/what-is-operator-answer-can-be-given.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/3108530673538306156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/3108530673538306156'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/what-is-operator-answer-can-be-given.html' title='Operator Types'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-622260809554954178</id><published>2010-08-31T11:09:00.003-07:00</published><updated>2011-04-10T04:35:21.986-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Using Constants</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A C constant is usually just the written version of a number. For example 1, 0, 5.73, 12.5e9. We can specify our constants in octal or hexadecimal, or force them to be treated as long integers.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;Octal constants are written with a leading zero - 015.&lt;/li&gt;
&lt;li&gt;Hexadecimal constants are written with a leading 0x - 0x1ae.&lt;/li&gt;
&lt;li&gt;Long constants are written with a trailing L - 890L.&lt;/li&gt;
&lt;/ul&gt;Character constants are usually just the character enclosed in single quotes; &#39;a&#39;, &#39;b&#39;, &#39;c&#39;. Some characters can&#39;t be represented in this way, so we use a 2 character sequence as follows.&lt;br /&gt;
&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;&#39;\n&#39; newline
&#39;\t&#39; tab
&#39;\\&#39; backslash
&#39;\&#39;&#39; single quote
&#39;\0&#39; null ( Usedautomatically to terminate character string )
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;In addition, a required bit pattern can be specified using its octal equivalent.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&#39;\044&#39; produces bit pattern 00100100.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Character constants are rarely used, since string constants are more convenient. A string constant is surrounded by double quotes eg &quot;Brian and Dennis&quot;. The string is actually stored as an array of characters. The null character &#39;\0&#39; is automatically placed at the end of such a string to act as a string terminator.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A character is a different type to a single character string. This is important poing to note.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Defining Constants&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;ANSI C allows you to declare&amp;nbsp;&lt;em&gt;constants&lt;/em&gt;. When you declare a constant it is a bit like a variable declaration except the value cannot be changed.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The&amp;nbsp;&lt;i&gt;const&lt;/i&gt;&amp;nbsp;keyword is to declare a constant, as shown below:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int const a = 1;
const int a =2;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;You can declare the&amp;nbsp;&lt;i&gt;const&lt;/i&gt;&amp;nbsp;before or after the type. Choose one an stick to it.&lt;/li&gt;
&lt;li&gt;It is usual to initialise a&amp;nbsp;&lt;i&gt;const&lt;/i&gt;&amp;nbsp;with a value as it cannot get a value&amp;nbsp;&lt;em&gt;any other way&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The preprocessor&amp;nbsp;&lt;i&gt;#define&lt;/i&gt;&amp;nbsp;is another more flexible (see Preprocessor Chapters) method to define&amp;nbsp;&lt;em&gt;constants&lt;/em&gt;&amp;nbsp;in a program.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#define TRUE  1
#define FALSE  0
#define NAME_SIZE 20
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here TRUE, FALSE and NAME_SIZE are constant&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You frequently see const declaration in function parameters. This says simply that the function is&amp;nbsp;&lt;b&gt;not&lt;/b&gt;&amp;nbsp;going to change the value of the parameter.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The following function definition used concepts we have not met (see chapters on functions, strings, pointers, and standard libraries) but for completenes of this section it is is included here:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;void strcpy(char *buffer, char const *string)
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;The enum Data type&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;i&gt;enum&lt;/i&gt;&amp;nbsp;is the abbreviation for ENUMERATE, and we can use this keyword to declare and initialize a sequence of integer constants. Here&#39;s an example:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;enum colors {RED, YELLOW, GREEN, BLUE};
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;I&#39;ve made the constant names uppercase, but you can name them which ever way you want.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here,&amp;nbsp;&lt;i&gt;colors&lt;/i&gt;&amp;nbsp;is the name given to the set of constants - the name is optional. Now, if you don&#39;t assign a value to a constant, the default value for the first one in the list -&amp;nbsp;&lt;i&gt;RED&lt;/i&gt;&amp;nbsp;in our case, has the value of&amp;nbsp;&lt;i&gt;0&lt;/i&gt;. The rest of the undefined constants have a value 1 more than the one before, so in our case,&amp;nbsp;&lt;i&gt;YELLOW&lt;/i&gt;&amp;nbsp;is&amp;nbsp;&lt;i&gt;1&lt;/i&gt;,&lt;i&gt;GREEN&lt;/i&gt;&amp;nbsp;is&amp;nbsp;&lt;i&gt;2&lt;/i&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;BLUE&lt;/i&gt;&amp;nbsp;is&amp;nbsp;&lt;i&gt;3&lt;/i&gt;.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;But you can assign values if you wanted to:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;enum colors {RED=1, YELLOW, GREEN=6, BLUE };
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Now RED=1, YELLOW=2, GREEN=6 and BLUE=7.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The main advantage of&amp;nbsp;&lt;i&gt;enum&lt;/i&gt;&amp;nbsp;is that if you don&#39;t initialize your constants, each one would have a unique value. The first would be zero and the rest would then count upwards.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You can name your constants in a weird order if you really wanted...&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
  enum {RED=5, YELLOW, GREEN=4, BLUE};

  printf(&quot;RED = %d\n&quot;, RED);
  printf(&quot;YELLOW = %d\n&quot;, YELLOW);
  printf(&quot;GREEN = %d\n&quot;, GREEN);
  printf(&quot;BLUE = %d\n&quot;, BLUE);
  return 0;
}

This will produce following results

  RED = 5
  YELLOW = 6
  GREEN = 4
  BLUE = 5
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/622260809554954178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-constant-is-usually-just-written.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/622260809554954178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/622260809554954178'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-constant-is-usually-just-written.html' title='Using Constants'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-4457032378486601719</id><published>2010-08-31T11:08:00.001-07:00</published><updated>2011-04-10T04:35:21.987-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Storage Classes</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There are following storage classes which can be used in a C Program&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;auto&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;register&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;static&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;extern&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;auto - Storage Class&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;auto&lt;/b&gt;&amp;nbsp;is the default storage class for all local variables.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;{
            int Count;
            auto int Month;
 }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The example above defines two variables with the same storage class. auto can only be used within functions, i.e. local variables.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;register - Storage Class&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;register&lt;/b&gt;&amp;nbsp;is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and cant have the unary &#39;&amp;amp;&#39; operator applied to it (as it does not have a memory location).&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;{
            register int  Miles;
 }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Register should only be used for variables that require quick access - such as counters. It should also be noted that defining &#39;register&#39; goes not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register - depending on hardware and implimentation restrictions.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;static - Storage Class&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;static&lt;/b&gt;&amp;nbsp;is the default storage class for global variables. The two variables below (count and road) both have a static storage class.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;static int Count;
        int Road;

        {
            printf(&quot;%d\n&quot;, Road);
        }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;static variables can be &#39;seen&#39; within all functions in this source file. At link time, the static variables defined here will not be seen by the object modules that are brought in.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;static can also be defined within a function. If this is done the variable is initalised at run time but is not reinitalized when the function is called. This inside a function static variable retains its value during vairous calls.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;void func(void);
   
   static count=10; /* Global variable - static is the default */
   
   main()
   {
     while (count--) 
     {
         func();
     }
   
   }
   
   void func( void )
   {
     static i = 5;
     i++;
     printf(&quot;i is %d and count is %d\n&quot;, i, count);
   }
   
   This will produce following result
   
   i is 6 and count is 9
   i is 7 and count is 8
   i is 8 and count is 7
   i is 9 and count is 6
   i is 10 and count is 5
   i is 11 and count is 4
   i is 12 and count is 3
   i is 13 and count is 2
   i is 14 and count is 1
   i is 15 and count is 0

&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;NOTE :&lt;/b&gt;&amp;nbsp;Here keyword&amp;nbsp;&lt;i&gt;void&lt;/i&gt;&amp;nbsp;means function does not return anything and it does not take any parameter. You can memoriese void as nothing. static variables are initialized to 0 automatically.&lt;/div&gt;&lt;div class=&quot;alignment&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;&lt;b&gt;Definition vs Declaration :&lt;/b&gt;&amp;nbsp;Before proceeding, let us understand the difference between&amp;nbsp;&lt;i&gt;defintion&lt;/i&gt;&amp;nbsp;and&amp;nbsp;&lt;i&gt;declaration&lt;/i&gt;&amp;nbsp;of a variable or function. Definition means where a variable or function is defined in realityand actual memory is allocated for variable or function. Declaration means just giving a reference of a variable and function. Through declaration we assure to the complier that this variable or function has been defined somewhere else in the program and will be provided at the time of linking. In the above examples&amp;nbsp;&lt;i&gt;char *func(void)&lt;/i&gt;&amp;nbsp;has been put at the top which is a declaration of this function where as this function has been defined below to&amp;nbsp;&lt;i&gt;main()&lt;/i&gt;&amp;nbsp;function.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;There is one more very important use for &#39;static&#39;. Consider this bit of code.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;char *func(void);

   main()
   {
      char *Text1;
      Text1 = func();
   }

   char *func(void)
   {
      char Text2[10]=&quot;martin&quot;;
      return(Text2);
   }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Now, &#39;func&#39; returns a pointer to the memory location where &#39;text2&#39; starts BUT text2 has a storage class of &#39;auto&#39; and will disappear when we exit the function and could be overwritten but something else. The answer is to specify&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;static char Text[10]=&quot;martin&quot;;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The storage assigned to &#39;text2&#39; will remain reserved for the duration if the program.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;extern - Storage Class&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;extern&lt;/b&gt;&amp;nbsp;is used to give a reference of a global variable that is visible to ALL the program files. When you use &#39;extern&#39; the variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When you have multiple files and you define a global variable or function which will be used in other files also, then&amp;nbsp;&lt;i&gt;extern&amp;nbsp;&lt;/i&gt;will be used in another file to give reference of defined variable or function. Just for understanding&amp;nbsp;&lt;i&gt;extern&amp;nbsp;&lt;/i&gt;is used to decalre a global variable or function in another files.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;File 1: main.c&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int count=5;

   main()
   {
     write_extern();
   }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;File 2: write.c&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;void write_extern(void);

   extern int count;

   void write_extern(void)
   {
     printf(&quot;count is %i\n&quot;, count);
   }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here&amp;nbsp;&lt;i&gt;extern&lt;/i&gt;&amp;nbsp;keyword is being used to declare count in another file.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Now compile these two files as follows&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;gcc main.c write.c -o write
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This fill produce&amp;nbsp;&lt;i&gt;write&lt;/i&gt;&amp;nbsp;program which can be executed to produce result.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Count in &#39;main.c&#39; will have a value of 5. If main.c changes the value of count - write.c will see the new value&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 9.16667px;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/4457032378486601719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/storage-class-defines-scope-visibility.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/4457032378486601719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/4457032378486601719'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/storage-class-defines-scope-visibility.html' title='Storage Classes'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-5021358869085517561</id><published>2010-08-31T11:07:00.001-07:00</published><updated>2011-04-10T04:35:21.987-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Variable Types</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A variable is just a named area of storage that can hold a single value (numeric or character). The C language demands that you declare the name of each variable that you are going to use and its type, or class, before you actually try to do anything with it.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The Programming language C has two main variable types&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Local Variables&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Global Variables&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Local Variables&lt;/h2&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Local variables scope is confined within the block or function where it is defined. Local variables must always be defined at the top of a block.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When a local variable is defined - it is not initalised by the system, you must initalise it yourself.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;When execution of the block starts the variable is available, and when the block ends the variable &#39;dies&#39;.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Check following example&#39;s output&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;main()
   {
      int i=4;
      int j=10;
   
      i++;
   
      if (j &amp;gt; 0)
      { 
         /* i defined in &#39;main&#39; can be seen */
         printf(&quot;i is %d\n&quot;,i); 
      }
   
      if (j &amp;gt; 0)
      {
         /* &#39;i&#39; is defined and so local to this block */
         int i=100; 
         printf(&quot;i is %d\n&quot;,i);      
      }/* &#39;i&#39; (value 100) dies here */
   
      printf(&quot;i is %d\n&quot;,i); /* &#39;i&#39; (value 5) is now visable.*/
   }
   
   This will generate following output
   i is 5
   i is 100
   i is 5
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here&amp;nbsp;&lt;b&gt;++&lt;/b&gt;&amp;nbsp;is called incremental operator and it increase the value of any integer variable by 1. Thus&amp;nbsp;&lt;b&gt;i++&lt;/b&gt;&amp;nbsp;is equivalent to&amp;nbsp;&lt;i&gt;i = i + 1;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You will see&amp;nbsp;&lt;b&gt;--&lt;/b&gt;&amp;nbsp;operator also which is called decremental operator and it idecrease the value of any integer variable by 1. Thus&amp;nbsp;&lt;b&gt;i--&lt;/b&gt;&amp;nbsp;is equivalent to&amp;nbsp;&lt;i&gt;i = i - 1;&lt;/i&gt;&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Global Variables&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Global variable is defined at the top of the program file and it can be visible and modified by any function that may reference it.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Global variables are initalised automatically by the system when you define them!&lt;/div&gt;&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;table style=&quot;border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(238, 238, 238); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(238, 238, 238); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(238, 238, 238); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot;&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;b&gt;Data Type&lt;/b&gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;b&gt;Initialser&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr align=&quot;center&quot;&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;int&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr align=&quot;center&quot;&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;char&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&#39;\0&#39;&lt;/td&gt;&lt;/tr&gt;
&lt;tr align=&quot;center&quot;&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;float&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;0&lt;/td&gt;&lt;/tr&gt;
&lt;tr align=&quot;center&quot;&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;pointer&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;NULL&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/center&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If same variable name is being used for global and local variable then local variable takes preference in its scope. But it is not a good practice to use global variables and local variables with the same name.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int i=4;          /* Global definition   */
   
   main()
   {
       i++;          /* Global variable     */
       func();
       printf( &quot;Value of i = %d -- main function\n&quot;, i );
   }

   func()
   {
       int i=10;     /* Local definition */
       i++;          /* Local variable    */
       printf( &quot;Value of i = %d -- func() function\n&quot;, i );
   }

   This will produce following result
   Value of i = 11 -- func() function
   Value of i = 5 -- main function
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;i&lt;/b&gt;&amp;nbsp;in&amp;nbsp;&lt;b&gt;main&lt;/b&gt;&amp;nbsp;function is global and will be incremented to 5.&amp;nbsp;&lt;b&gt;i&lt;/b&gt;&amp;nbsp;in&amp;nbsp;&lt;b&gt;func&lt;/b&gt;&amp;nbsp;is internal and will be incremented to 11. When control returns to&amp;nbsp;&lt;b&gt;main&lt;/b&gt;&amp;nbsp;the internal variable will die and and any reference to&amp;nbsp;&lt;b&gt;i&lt;/b&gt;&amp;nbsp;will be to the global.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/5021358869085517561/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/variable-is-just-named-area-of-storage.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/5021358869085517561'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/5021358869085517561'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/variable-is-just-named-area-of-storage.html' title='Variable Types'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-8368376802341649981</id><published>2010-08-31T11:06:00.001-07:00</published><updated>2011-04-10T04:35:21.987-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Basic Datatypes</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C has a concept of &#39;data types&#39; which are used to define a variable before its use. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The value of a variable can be changed any time.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C has the following basic built-in datatypes.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;int&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;float&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;double&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;char&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Please note that there is not a boolean data type. C does not have the traditional view about logical comparison, but thats another story.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;int - data type&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&amp;nbsp;is used to define integer numbers.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;{
        int Count;
        Count = 5;
    }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;float - data type&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;float&lt;/b&gt;&amp;nbsp;is used to define floating point numbers.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;{
        float Miles;
        Miles = 5.6;
    }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;double - data type&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;double&lt;/b&gt;&amp;nbsp;is used to define BIG floating point numbers. It reserves twice the storage for the number. On PCs this is likely to be 8 bytes.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;{
        double Atoms;
        Atoms = 2500000;
    }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;char - data type&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;char&lt;/b&gt;&amp;nbsp;defines characters.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;{
        char Letter;
        Letter = &#39;x&#39;;
    }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Modifiers&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The data types explained above have the following modifiers.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;short&lt;/li&gt;
&lt;li&gt;long&lt;/li&gt;
&lt;li&gt;signed&lt;/li&gt;
&lt;li&gt;unsigned&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The modifiers define the amount of storage allocated to the variable. The amount of storage allocated is not cast in stone. ANSI has the following rules:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;short int &amp;lt;=    int &amp;lt;= long int
            float &amp;lt;= double &amp;lt;= long double

&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;What this means is that a &#39;short int&#39; should assign less than or the same amount of storage as an &#39;int&#39; and the &#39;int&#39; should be less or the same bytes than a &#39;long int&#39;. What this means in the real world is:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;&lt;b&gt;Type Bytes             Range&lt;/b&gt;
---------------------------------------------------------------------
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;short int  2          -32,768 -&amp;gt; +32,767          (32kb)
   unsigned short int  2                0 -&amp;gt; +65,535          (64Kb)
         unsigned int  4                0 -&amp;gt; +4,294,967,295   ( 4Gb)
                  int  4   -2,147,483,648 -&amp;gt; +2,147,483,647   ( 2Gb)
             long int  4   -2,147,483,648 -&amp;gt; +2,147,483,647   ( 2Gb)
          signed char  1             -128 -&amp;gt; +127
        unsigned char  1                0 -&amp;gt; +255
                float  4 
               double  8  
          long double 12 
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;These figures only apply to todays generation of PCs. Mainframes and midrange machines could use different figures, but would still comply with the rule above.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You can find out how much storage is allocated to a data type by using the&amp;nbsp;&lt;b&gt;sizeof&lt;/b&gt;operator discussed in&amp;nbsp;Operator Types&amp;nbsp;Session.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here is an example to check size of memory taken by various datatypes.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int
main()
{
  printf(&quot;sizeof(char) == %d\n&quot;, sizeof(char));
  printf(&quot;sizeof(short) == %d\n&quot;, sizeof(short));
  printf(&quot;sizeof(int) == %d\n&quot;, sizeof(int));
  printf(&quot;sizeof(long) == %d\n&quot;, sizeof(long));
  printf(&quot;sizeof(float) == %d\n&quot;, sizeof(float));
  printf(&quot;sizeof(double) == %d\n&quot;, sizeof(double));
  printf(&quot;sizeof(long double) == %d\n&quot;, sizeof(long double));
  printf(&quot;sizeof(long long) == %d\n&quot;, sizeof(long long));

  return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;Qualifiers&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A type qualifier is used to refine the declaration of a variable, a function, and parameters, by specifying whether:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;The value of a variable can be changed.&lt;/li&gt;
&lt;li&gt;The value of a variable must always be read from memory rather than from a register&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Standard C language recognizes the following two qualifiers:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;const&lt;/li&gt;
&lt;li&gt;volatile&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The&amp;nbsp;&lt;i&gt;const&lt;/i&gt;&amp;nbsp;qualifier is used to tell C that the variable value can not change after initialisation.&lt;/div&gt;const float pi=3.14159;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Now&amp;nbsp;&lt;i&gt;pi&lt;/i&gt;&amp;nbsp;cannot be changed at a later time within the program.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Another way to define constants is with the&amp;nbsp;&lt;i&gt;#define&lt;/i&gt;&amp;nbsp;preprocessor which has the advantage that it does not use any storage&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The volatile qualifier declares a data type that can have its value changed in ways outside the control or detection of the compiler (such as a variable updated by the system clock or by another program). This prevents the compiler from optimizing code referring to the object by storing the object&#39;s value in a register and re-reading it from there, rather than from memory, where it may have changed. You will use this qualifier once you will become expert in &quot;C&quot;. So for now just proceed.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;What are Arrays:&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;We have seen all baisc data types. In C language it is possible to make arrays whose elements are basic types. Thus we can make an array of 10 integers with the declaration.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int x[10];
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The square brackets mean subscripting; parentheses are used only for function references. Array indexes begin at zero, so the elements of x are:&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Thus Array are special type of variables which can be used to store multiple values of same data type. Those values are stored and accessed using subscript or index.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Arrays occupy consecutive memory slots in the computer&#39;s memory.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;x[0], x[1], x[2], ..., x[9]
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If an array has n elements, the largest subscript is n-1.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Multiple-dimension arrays are provided. The declaration and use look like:&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int name[10] [20];
      n = name[i+j] [1] + name[k] [2];
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Subscripts can be arbitrary integer expressions. Multi-dimension arrays are stored by row so the rightmost subscript varies fastest. In above example&lt;b&gt;&amp;nbsp;name&lt;/b&gt;&amp;nbsp;has 10 rows and 20 columns.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Same way, arrays can be defined for any data type. Text is usually kept as an array of characters. By convention in C, the last character in a character array should be a `\0&#39; because most programs that manipulate character arrays expect it. For example, printf uses the `\0&#39; to detect the end of a character array when printing it out with a `%s&#39;.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Here is a program which reads a line, stores it in a buffer, and prints its length (excluding the newline at the end).&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;main( ) {
               int n, c;
               char line[100];
               n = 0;
               while( (c=getchar( )) != &#39;\n&#39; ) {
                       if( n &amp;lt; 100 )
                               line[n] = c;
                       n++;
               }
               printf(&quot;length = %d\n&quot;, n);
       }
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Array Initialization&lt;/h2&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;As with other declarations, array declarations can include an optional initialization&lt;/li&gt;
&lt;li&gt;Scalar variables are initialized with a single value&lt;/li&gt;
&lt;li&gt;Arrays are initialized with a list of values&lt;/li&gt;
&lt;li&gt;The list is enclosed in curly braces&lt;/li&gt;
&lt;/ul&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int array [8] = {2, 4, 6, 8, 10, 12, 14, 16};
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The number of initializers cannot be more than the number of elements in the array but it can be less in which case, the remaining elements are initialized to 0.if you like, the array size can be inferred from the number of initializers by leaving the square brackets empty so these are identical declarations:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;int array1 [8] = {2, 4, 6, 8, 10, 12, 14, 16};
int array2 [] = {2, 4, 6, 8, 10, 12, 14, 16};
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;An array of characters ie string can be initialized as follows:&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 481px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;char string[10] = &quot;Hello&quot;;
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/8368376802341649981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-has-concept-of-data-types-which-are.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/8368376802341649981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/8368376802341649981'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-has-concept-of-data-types-which-are.html' title='Basic Datatypes'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-7932796502461885021</id><published>2010-08-31T11:05:00.001-07:00</published><updated>2011-04-10T04:35:21.987-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Reserved Keywords</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The following names are reserved by the C language. Their meaning is already defined, and they cannot be re-defined to mean anything else.&lt;/div&gt;&lt;table cellpadding=&quot;5&quot; style=&quot;border-bottom-color: rgb(238, 238, 238); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(238, 238, 238); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(238, 238, 238); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(238, 238, 238); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody valign=&quot;top&quot;&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot; width=&quot;25%&quot;&gt;auto&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot; width=&quot;25%&quot;&gt;else&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot; width=&quot;25%&quot;&gt;long&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot; width=&quot;25%&quot;&gt;switch&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;break&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;enum&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;register&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;typedef&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;case&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;extern&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;return&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;union&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;char&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;float&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;short&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;unsigned&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;const&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;for&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;signed&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;void&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;continue&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;goto&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;sizeof&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;volatile&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;default&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;if&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;static&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;while&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;do&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;int&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;struct&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;_Packed&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;double&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;While naming your functions and variables, other than these names, you can choose any names of reasonable length for variables, functions etc.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/7932796502461885021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/following-names-are-reserved-by-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7932796502461885021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7932796502461885021'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/following-names-are-reserved-by-c.html' title='Reserved Keywords'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-7773790439966745709</id><published>2010-08-31T11:04:00.000-07:00</published><updated>2011-04-10T04:35:21.988-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Program Structure</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;A C program basically has the following form:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Preprocessor Commands&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Functions&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Variables&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Statements &amp;amp; Expressions&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Comments&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The following program is written in the C programming language. Open a text file&lt;b&gt;&lt;i&gt;hello.c&lt;/i&gt;&lt;/b&gt;&amp;nbsp;using vi editor and put the following lines inside that file.&lt;/div&gt;&lt;table cellpadding=&quot;10&quot; class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
   /* My first program */
   printf(&quot;Hello, World! \n&quot;);
   
   return 0;
}
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Preprocessor Commands:&lt;/b&gt;&amp;nbsp;These commands tells the compiler to do preprocessing before doing actual compilation. Like&amp;nbsp;&lt;i&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/i&gt;&amp;nbsp;is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. You will learn more about C Preprocessors in&amp;nbsp;C Preprocessors&amp;nbsp;session.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Functions:&amp;nbsp;&lt;/b&gt;are main building blocks of any C Program. Every C Program will have one or more functions and there is one mandatory function which is called&lt;i&gt;main()&lt;/i&gt;&amp;nbsp;function. This function is prefixed with keyword&amp;nbsp;&lt;i&gt;int&lt;/i&gt;&amp;nbsp;which means this function returns an integer value when it exits. This integer value is retured using&lt;i&gt;return&lt;/i&gt;&amp;nbsp;statement.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The C Programming language provides a set of built-in functions. In the above example&amp;nbsp;&lt;i&gt;printf()&lt;/i&gt;&amp;nbsp;is a C built-in function which is used to print anything on the screen. Check&amp;nbsp;Builtin function&amp;nbsp;section for more detail.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;You will learn how to write your own functions and use them in&amp;nbsp;Using Functionsession.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Variables:&lt;/b&gt;&amp;nbsp;are used to hold numbers, strings and complex data for manipulation. You will learn in detail about variables in&amp;nbsp;C Variable Types.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Statements &amp;amp; Expressions :&amp;nbsp;&lt;/b&gt;Expressions combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;Comments:&lt;/b&gt;&amp;nbsp;are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/ as given in the example above. A comment can span through multiple lines.&lt;/div&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Note the followings&lt;/h2&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C is a case sensitive programming language. It means in C&amp;nbsp;&lt;i&gt;printf&lt;/i&gt;&amp;nbsp;and&lt;i&gt;Printf&lt;/i&gt;&amp;nbsp;will have different meanings.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C has a free-form line structure. End of each C statement must be marked with a semicolon.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Multiple statements can be one the same line.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;White Spaces (ie tab space and space bar ) are ignored.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Statements can continue over multiple lines.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;C Program Compilation&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;To compile a C program you would have to Compiler name and program files name. Assuming your compiler&#39;s name is cc and program file name is hello.c, give following command at Unix prompt.&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;$cc hello.c
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This will produce a binary file called&amp;nbsp;&lt;i&gt;a.out&lt;/i&gt;&amp;nbsp;and an object file hello.o in your current directory. Here a.out is your first program which you will run at Unix prompt like any other system program. If you don&#39;t like the name&amp;nbsp;&lt;i&gt;a.out&lt;/i&gt;&amp;nbsp;then you can produce a binary file with your own name by using -o option while compiling C program. See an example below&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;$cc -o hello hello.c
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Now you will get a binary with name&amp;nbsp;&lt;i&gt;hello&lt;/i&gt;. Execute this program at Unix prompt but before executing / running this program make sure that it has execute permission set. If you don&#39;t know what is execute permission then just follow these two steps&lt;/div&gt;&lt;table class=&quot;src&quot; style=&quot;background-color: #f1f1f1; border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-bottom-width: 1px; border-collapse: collapse; border-left-color: rgb(170, 170, 170); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(170, 170, 170); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(170, 170, 170); border-top-style: solid; border-top-width: 1px; font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; padding-left: 5px; width: 462px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot;&gt;&lt;pre style=&quot;font-family: &#39;Courier New&#39;, monospace; font-size: 12px; margin-bottom: 0px; margin-left: 0px;&quot;&gt;$chmod 755 hello
$./hello

This will produce following result
Hello, World
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Congratulations!! you have written your first program in &quot;C&quot;. Now believe me its not difficult to learn &quot;C&quot;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/7773790439966745709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-program-basically-has-following-form.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7773790439966745709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/7773790439966745709'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-program-basically-has-following-form.html' title='Program Structure'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-1833345213519982829</id><published>2010-08-31T11:02:00.001-07:00</published><updated>2011-04-10T04:35:21.988-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>Basic Introduction</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px; text-align: justify;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Eqquipment Corporation PDP-11 computer in 1972.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The Unix operating system and virtually all Unix applications are written in the C language. C has now become a widely used professional language for various reasons.&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Easy to learn&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Structured language&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It produces efficient programs.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It can handle low-level activities.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;It can be compiled on a variety of computers.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Facts about C&lt;/h2&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C was invented to write an operating system called UNIX.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C is a successor of B language which was introduced around 1970&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;The language was formalized in 1988 by the American National Standard Institue (ANSI).&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;By 1973 UNIX OS almost totally written in C.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Today C is the most widely used System Programming Language.&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;Most of the state of the art software have been implemented using C&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;h2 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 13px; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Why to use C ?&lt;/h2&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;C was initially used for system development work, in particular the programs that make-up the operating system. C was adoped as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be:&lt;/div&gt;&lt;ul style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;li&gt;Operating Systems&lt;/li&gt;
&lt;li&gt;Language Compilers&lt;/li&gt;
&lt;li&gt;Assemblers&lt;/li&gt;
&lt;li&gt;Text Editors&lt;/li&gt;
&lt;li&gt;Print Spoolers&lt;/li&gt;
&lt;li&gt;Network Drivers&lt;/li&gt;
&lt;li&gt;Modern Programs&lt;/li&gt;
&lt;li&gt;Data Bases&lt;/li&gt;
&lt;li&gt;Language Interpreters&lt;/li&gt;
&lt;li&gt;Utilities&lt;/li&gt;
&lt;/ul&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;C Program File&lt;/h1&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;All the C programs are writen into text files with extension &quot;.c&quot; for example&lt;b&gt;&lt;i&gt;hello.c&lt;/i&gt;&lt;/b&gt;. You can use &quot;vi&quot; editor to write your C program into a file.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;This tutorial assumes that you know how to edit a text file and how to write programming insturctions inside a program file.&lt;/div&gt;&lt;h1 style=&quot;background-color: transparent; color: black; font-family: verdana, helvetica, arial, sans-serif; font-size: 18px;&quot;&gt;C Compilers&lt;/h1&gt;&lt;div class=&quot;alignment&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;When you write any program in C language then to run that program you need to compile that program using a C Compiler which converts your program into a language understandable by a computer. This is called machine language (ie. binary format). So before proceeding, make sure you have C Compiler available at your computer. It comes alongwith all flavors of Unix and Linux.&lt;/div&gt;&lt;div class=&quot;alignment&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: justify;&quot;&gt;If you are working over Unix or Linux then you can type&amp;nbsp;&lt;i&gt;gcc -v&lt;/i&gt;&amp;nbsp;or&amp;nbsp;&lt;i&gt;cc -v&lt;/i&gt;&amp;nbsp;and check the result. You can ask your system administrator or you can take help from anyone to identify an available C Compiler at your computer.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;If you don&#39;t have C compiler installed at your computer then you can use below given link to download a GNU C Compiler and use it.&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/1833345213519982829/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-is-general-purpose-high-level.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/1833345213519982829'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/1833345213519982829'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-is-general-purpose-high-level.html' title='Basic Introduction'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4319573138870071470.post-8800845075661252220</id><published>2010-08-31T11:01:00.001-07:00</published><updated>2011-04-10T04:35:21.988-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>C - Programming HOME</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: verdana, helvetica, arial, sans-serif; font-size: 11px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;middle&quot; width=&quot;100&quot;&gt;&lt;img alt=&quot;picture&quot; border=&quot;0&quot; src=&quot;http://www.tutorialspoint.com/images/c.gif&quot; style=&quot;border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px;&quot; /&gt;&lt;/td&gt;&lt;td style=&quot;font-family: verdana, helvetica, arial, sans-serif; text-align: left;&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;The C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;C is the most widely used computer language.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: verdana, helvetica, arial, sans-serif;&quot;&gt;&lt;b&gt;This tutorial should be your starting point only.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages18.blogspot.com/feeds/8800845075661252220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-is-general-purpose-procedural.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/8800845075661252220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4319573138870071470/posts/default/8800845075661252220'/><link rel='alternate' type='text/html' href='http://wlanguages18.blogspot.com/2010/08/c-is-general-purpose-procedural.html' title='C - Programming HOME'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>