<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Aditech &#187; Lesser Known Facts</title>
	<atom:link href="http://blog.aditech.info/category/lesser-known-facts/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.aditech.info</link>
	<description>There is something for everyone !!</description>
	<lastBuildDate>Mon, 16 Nov 2009 13:16:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>ASCII Chart</title>
		<link>http://blog.aditech.info/ascii-chart.html</link>
		<comments>http://blog.aditech.info/ascii-chart.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 12:29:10 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[ASCII]]></category>
		<category><![CDATA[ASCII chart]]></category>
		<category><![CDATA[use ASCII characters in C programs]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/ascii-chart/</guid>
		<description><![CDATA[After seeing this chart if you want to print say square root symbol all you have to do is specify the ASCII value for %c in printf i.e to print square root.. printf(&#8220;%c Hi! %c&#8221;,251,251); and to print heart symbol printf(&#8220;%c Hi! %c&#8221;,3,3); You may also likeWordpress 2.6 -A complete review and GuideThe mistake in [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><a href="http://farm3.static.flickr.com/2392/2085714247_6abe4b8d2b_o.jpg" rel="shadowbox[post-14];player=img;"><img src="http://farm3.static.flickr.com/2392/2085714247_6abe4b8d2b_o.jpg" alt="ASCII chart" height="410" width="495" /></a></p>
<p> After seeing this chart if you want to print say square root symbol all you have to do is specify the ASCII value for %c in printf<br />
i.e to print square root..</p>
<blockquote><p><font color="#0000ff">printf(&#8220;%c Hi! %c&#8221;,251,251);</font></p></blockquote>
<p>and to print heart symbol</p>
<blockquote><p><font color="#0000ff">printf(&#8220;%c Hi! %c&#8221;,3,3);</font></p></blockquote>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-3.html" title="SEO for wordpress blogs-Part 3/5">SEO for wordpress blogs-Part 3/5</a></li><li><a href="http://blog.aditech.info/google-can-read-flash.html" title="Google can read Flash">Google can read Flash</a></li><li><a href="http://blog.aditech.info/enum-data-type.html" title="enum data type">enum data type</a></li><li><a href="http://blog.aditech.info/random-post-option-in-wordpress.html" title="Random post option in wordpress&#8230;">Random post option in wordpress&#8230;</a></li><li><a href="http://blog.aditech.info/presenmaker-10.html" title="Presenmaker 1.0">Presenmaker 1.0</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-4.html" title="SEO for wordpress blogs-Part 4/5">SEO for wordpress blogs-Part 4/5</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/ascii-chart.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>atoi,atol and atof functions</title>
		<link>http://blog.aditech.info/atoiatol-and-atof-functions.html</link>
		<comments>http://blog.aditech.info/atoiatol-and-atof-functions.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 12:18:42 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[atof]]></category>
		<category><![CDATA[atoi]]></category>
		<category><![CDATA[atol]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/atoiatol-and-atof-functions/</guid>
		<description><![CDATA[These functions are available under stdlib.h .These are very unknown functions.Lets see what these do.. atol() atol returns the value in terms of long datatype of the string containing numbers.the syntax is atol(stringvariable) ex: consider the following program #include #include void main() char a[10],b[10]; puts("Enter the value of a"); gets(a); puts("Enter the value of b"); [...]]]></description>
			<content:encoded><![CDATA[<p>These functions are available under stdlib.h .These are very unknown functions.Lets see what these do..</p>
<p><strong>atol()</strong><br />
atol returns the value in terms of long datatype of the string containing numbers.the syntax is</p>
<blockquote><p><font color="#0000ff">atol(stringvariable)</font></p></blockquote>
<p>ex: consider the following program<br />
<span id="more-13"></span></p>
<pre lang="C" line="1">
#include<stdio.h>
#include<stdlib.h>
void main()

char a[10],b[10];
puts("Enter the value of a");
gets(a);
puts("Enter the value of b");
gets(b);
printf("%s+%s=%ld and %s-%s=%ld",a,b,(atol(a)+atol(b)),a,b,(atol(a)-atol(b)));
getch();
}
</pre>
<p>and similarly there is <strong>atof()</strong> which returns the float value of the string containing numbers and <strong>atoi()</strong> which returns integer value.</p>
<p>now to see the difference between the 3 look at this program</p>
<pre lang="C" line="1">
#include<stdio.h>
#include<stdlib.h>
main()
{
char a[]={"2545.965"};
printf("atol=%ld\t atof=%f\t atoi=%d\t\n",atol(a),atof(a),atoi(a));
}
</pre>
<p>the output will be</p>
<blockquote><p><font color="#ff6600">atol=2545                                atof=2545.965000                                    atoi=2545</font></p></blockquote>
<blockquote></blockquote>
<p><em>T</em><em>he output of atoi() and atol() functions will be same but atof() function may give different output depending upon the compiler.That is,in some compiler the output may be like this atof=2545.96498 or something.The above output is extarcted from red hat</em></p>
<blockquote></blockquote>
<p>let&#8217;s look what happens when the string does not contain numeric value.change this statement in the above program</p>
<blockquote><p><font color="#0000ff">char a[]={&#8220;adithya&#8221;};</font></p></blockquote>
<p>now when you run the program the following will be the output</p>
<blockquote><p><font color="#ff9900">atol=0                               atof=0                               atoi=0</font></p></blockquote>
<p>that means the string should contain numeric value<br />
now modify this program as</p>
<blockquote><p><font color="#0000ff">char a[]={&#8220;007adi&#8221;};</font></p></blockquote>
<p>the output in this case(tested in Red hat) will be</p>
<blockquote><p><font color="#0000ff">atol=7                           atof=7.000000                              atoi=7<br />
</font></p></blockquote>
<p>so the functions has taken 007 only not the remaining part<br />
<strong>However note that this depends upon compiler.Some will take ,while some will give output as 0.</strong></p>
<p>Now consider this</p>
<blockquote><p><font color="#0000ff">char a[]={&#8220;adi007&#8243;};</font></p></blockquote>
<p>the output of the program will be</p>
<blockquote><p><font color="#0000ff">atol=0           atof=0.000000           atoi=0</font></p></blockquote>
<p><font color="#000000">I&#8217;m not sure of this but the following is the point that i noticed<br />
now consider this</font></p>
<blockquote><p><font color="#0000ff">char a[]={&#8220;0XA&#8221;};</font></p></blockquote>
<p><font color="#000000">what do you think the output is???<br />
As you can see 0XA is a hexadecimal number(hexadecimal number in C is written by writing 0X(zero X) folowed by hex number).It&#8217;s decimal equivalent is 10.The following is the output i got in Red hat</font></p>
<blockquote><p><font color="Blue">atol=0                        atof=10.000000        atoi=0</font></p></blockquote>
<p><font color="#000000">Now the question is why atol and atoi couldn&#8217;t understand this while atof took the number as hex number?????  <img src="http://www.thinkdigit.com/forum/images/smilies/confused.gif" title="Confused" class="inlineimg" border="0" height="21" width="16" /><img src="http://www.thinkdigit.com/forum/images/smilies/confused.gif" title="Confused" class="inlineimg" border="0" /><img src="http://www.thinkdigit.com/forum/images/smilies/confused.gif" title="Confused" class="inlineimg" border="0" /></font></p>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/google-can-read-flash.html" title="Google can read Flash">Google can read Flash</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-4.html" title="SEO for wordpress blogs-Part 4/5">SEO for wordpress blogs-Part 4/5</a></li><li><a href="http://blog.aditech.info/wordpress-2_6-a-complete-review-and-guide.html" title="Wordpress 2.6 -A complete review and Guide">Wordpress 2.6 -A complete review and Guide</a></li><li><a href="http://blog.aditech.info/important-instructions-for-programs-using-mathh-library-function.html" title="Important instructions for programs using math.h library function">Important instructions for programs using math.h library function</a></li><li><a href="http://blog.aditech.info/advantages-of-running-c-in-linuxunix-1.html" title="Advantages of running c in Linux/Unix-1">Advantages of running c in Linux/Unix-1</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-3.html" title="SEO for wordpress blogs-Part 3/5">SEO for wordpress blogs-Part 3/5</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/atoiatol-and-atof-functions.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Saving the output in a text file</title>
		<link>http://blog.aditech.info/saving-the-output-in-a-text-file.html</link>
		<comments>http://blog.aditech.info/saving-the-output-in-a-text-file.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 08:54:54 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[output redirection]]></category>
		<category><![CDATA[Saving the output in a text file]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/saving-the-output-in-a-text-file/</guid>
		<description><![CDATA[consider the following c program #include&#60;stdio.h&#62; #include&#60;conio.h&#62; main() { int i,n; clrscr(); printf(&#8220;Enter limit\n&#8221;); scanf(&#8220;%d&#8221;,&#38;n); printf(&#8220;I will print %d times\n&#8221;,n); for(i=0;i&#60;n;i++) printf(&#8220;I luv C\n&#8221;); } the output will be Enter limit 4 I will print 4 times I luv C I luv C I luv C I luv C &#160; This is a simple program [...]]]></description>
			<content:encoded><![CDATA[<p>consider the following c program</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;<br />
#include&lt;conio.h&gt;</font><br />
<font color="#0000ff">main()</font><br />
<font color="#0000ff">{</font><br />
<font color="#0000ff">int i,n;</font><br />
<font color="#0000ff">clrscr();</font><br />
<font color="#0000ff">printf(&#8220;Enter limit\n&#8221;);</font><br />
<font color="#0000ff">scanf(&#8220;%d&#8221;,&amp;n);</font><br />
<font color="#0000ff">printf(&#8220;I will print %d times\n&#8221;,n);</font><br />
<font color="#0000ff">for(i=0;i&lt;n;i++)</font><br />
<font color="#0000ff">        printf(&#8220;I luv C\n&#8221;);</font><br />
<font color="#0000ff">}</font></p></blockquote>
<p>the output will be<br />
<span id="more-12"></span></p>
<blockquote><p><font color="#ff6600">Enter limit</font><br />
<font color="#ff6600">4</font><br />
<font color="#ff6600">I will print 4 times</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font></p></blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p>This is a simple program which will print &#8220;I luv C&#8221; n times<br />
Now i want to save the output to a text file without copy pasting the output.<br />
Well,in that case, first compile the saved C file[{ALT} {F9}]<br />
Now go to file menu and click DOS SHELL or DOS PROMPT in Turbo C</p>
<p>You are in DOS now.Lets assume the filename of the above program be some output.c.Then issue command</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">C:\TC\BIN\output.exe &gt;&gt; output.txt</font></p></blockquote>
<p>In general,the command is</p>
<blockquote><p><font color="#0000ff">filename.exe &gt;&gt; textfile.txt</font></p></blockquote>
<p>As soon as you press enter, you will be presented a black screen and you see no message.Now enter 5 and press enter.You will again see DOS prompt.Now open the text file(text file will be in same director(C:\TC\BIN)),the following will be it&#8217;s content</p>
<blockquote><p><font color="#ff6600"> Enter limit<br />
I will print 5 times<br />
I luv C<br />
I luv C<br />
I luv C<br />
I luv C<br />
I luv C</font></p></blockquote>
<blockquote>
<blockquote></blockquote>
</blockquote>
<p>When you direct the output to a text file,2 things are important</p>
<blockquote>
<blockquote><p><font color="Blue"><em>1.Only scanning takes place in DOS.Means no output will be there.You have to remember the sequence in which you should enter values.</em></font><br />
<font color="Blue"><em> 2.Your input is not saved in the text file as you can see ,the file contains &#8220;Enter limit&#8221; but doesn&#8217;t contain what i inputted.</em></font></p></blockquote>
</blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p class="smallfont" style="margin-bottom: 2px"> <strong>Note:</strong></p>
<p>1.If the text file already exists,then the output will be appended(added) to the existing contents<br />
2.This is a general procedure assuming that you have saved your c file in C:\TC\BIN\ directory.If you have saved somewhere else say C:\Pro\ then you should first navigate to that directory by using &#8216;cd&#8217; command i.e, cd C:\Pro\ and then the remaining procedures are same<br />
3.The text file is saved under the same directory.If you want to store it some other place then give the path<br />
ex:</p>
<blockquote><p><font color="#0000ff">C:\TC\BIN\output.exe &gt;&gt; C:\output.txt</font></p></blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p>will save the output to a text file named output.txt saved in C:\<br />
4.Do not forget to compile the file before saving it&#8217;s output in a text file<br />
5.If you use getch(); at the end ,remember to press a key.<br />
6.In case of above program,blank screen is presented because we have used clrscr();if it&#8217;s not used then you will not see a blank screen.But you see a no prompt.This is the indication that the program is running<br />
7.Save the file before compilation.<br />
8.The compiled file is always having the same name as the saved c file but having extension &#8216;.exe&#8217;</p>
<p><em><strong>Tip:<br />
</strong>if you want the contents of the textfile to be of natural output ,then after every scanf() statement issue appropriate printf() statement of the value you scanned.<br />
Ex:if you want to make the directed output file of the above program match exatly with real output then make this change</em></p>
<blockquote><p><font color="#0000ff">printf(&#8220;Enter limit\n&#8221;);</font><br />
<font color="#0000ff">scanf(&#8220;%d&#8221;,&amp;n);</font><br />
<font color="#0000ff">printf(&#8220;%d\n&#8221;,n);</font></p></blockquote>
<p>now the contents of the text file will be like this</p>
<blockquote><p><font color="#ff6600">Enter limit</font><br />
<font color="#ff6600">5</font><br />
<font color="#ff6600">I will print 5 times</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font><br />
<font color="#ff6600">I luv C</font></p></blockquote>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/twitter-exposed.html" title="Twitter Exposed">Twitter Exposed</a></li><li><a href="http://blog.aditech.info/save-as-pdf-option-in-your-website-or-blog.html" title="Save as pdf option in your website or blog">Save as pdf option in your website or blog</a></li><li><a href="http://blog.aditech.info/important-instructions-for-programs-using-mathh-library-function.html" title="Important instructions for programs using math.h library function">Important instructions for programs using math.h library function</a></li><li><a href="http://blog.aditech.info/how-c-compiler-decides-the-garbage-values-in-case-of-data-overflow.html" title="How C Compiler decides the Garbage values in case of data overflow">How C Compiler decides the Garbage values in case of data overflow</a></li><li><a href="http://blog.aditech.info/enum-data-type.html" title="enum data type">enum data type</a></li><li><a href="http://blog.aditech.info/create-you-own-custom-firefox-search-plugin-in-seconds.html" title="Create you own custom Firefox search plugin in seconds">Create you own custom Firefox search plugin in seconds</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/saving-the-output-in-a-text-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How C Compiler decides the Garbage values in case of data overflow</title>
		<link>http://blog.aditech.info/how-c-compiler-decides-the-garbage-values-in-case-of-data-overflow.html</link>
		<comments>http://blog.aditech.info/how-c-compiler-decides-the-garbage-values-in-case-of-data-overflow.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 08:43:45 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[dataoverflow]]></category>
		<category><![CDATA[garbage value]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/how-c-compiler-decides-the-garbage-values-in-case-of-data-overflow/</guid>
		<description><![CDATA[Garbage value in case of data overflow I did some intense R&#38;D for garbage values and found these facts.After understanding these concepts u can tell what will be the garbage value to be stored in a variable in case of dataoverflow. Here are some of the basic facts required to proceed In case of windows(TC), [...]]]></description>
			<content:encoded><![CDATA[<h1 align="center"><font size="4">Garbage value in case of data overflow</font></h1>
<p>I did some intense R&amp;D for garbage values and found these facts.After understanding these concepts u can tell what will be the garbage value to be stored in a variable in case of dataoverflow.</p>
<p>Here are some of the basic facts required to proceed</p>
<p><font color="#00ffff"><strong><font color="#993300">I</font><font color="#993300">n case of windows(TC),</font></strong></font></p>
<p><font color="#993300"><em> The space allocated for a variable of int datatype is 16 bits.</em></font></p>
<p><font color="#993300"><em> That means the maximum negative value that can be stored by the variable of int datatype is 2^15=-32768.</em></font></p>
<p><font color="#993300"><em> You may ask why 2^15 not 2^16.This is because one bit is reserved for sign(+ or -)</em></font></p>
<p><font color="#993300"><em> simlarly the maximum +ve value that a variable of int datatype can store is 2^15-1=32767.Hang on!!</em></font></p>
<p><font color="#993300"><em> Why -1.Because 0 is also counted in case of +ve values. </em></font></p>
<p><font color="#993300"><em>Now lets come to long datatype.<br />
The space allocated for a variable of long datatype is 32 bits.<br />
Maximum negative value= 2^31=-2147483648<br />
Maximum +ve value= 2^31-1=2147483647<br />
</em></font></p>
<p><font color="#993300"><strong>In case of linux(32 bit),</strong><br />
<em><br />
The space allocated for a variable of int datatype is 32 bits.<br />
Maximum negative value= 2^31=-2147483648<br />
Maximum +ve value= 2^31-1=2147483647</em></font></p>
<p><font color="#993300"><em>Now lets come to long datatype.<br />
The space allocated for a variable of long datatype is 64 bits.<br />
Maximum negative value= 2^63=-9.22337e+18<br />
Maximum +ve value= (2^63)-1=9.22337e+18<br />
</em></font></p>
<p><font color="#993300">Since long in linux can store a huge amount of value.let&#8217;s not consider it.<br />
Let&#8217;s take int and long in case of windows and only long in case of linux</font></p>
<p>That&#8217;s basic stuffs<br />
Now, consider this program</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;</font><br />
<font color="#0000ff">#include&lt;conio.h&gt;</font><br />
<font color="#0000ff">void main()</font><br />
<font color="#0000ff">{</font><br />
<font color="#0000ff">int a;</font><br />
<font color="#0000ff">long int b;</font><br />
<font color="#0000ff">clrscr();</font><br />
<font color="#0000ff">a=45000;</font><br />
<font color="#0000ff">b=4000000000;</font><br />
<font color="#0000ff">printf(&#8220;%d\t%ld\n&#8221;,a,b);</font><br />
<font color="#0000ff">getch();</font><br />
<font color="#0000ff">}</font></p></blockquote>
<p>Since both variables a and b are assigned a value greater than their limits,when you run this program some garbage value will be the output.But, the question is how c decides the garbage value??Can we predict the garbage value without running the program.</p>
<p>Sure,We can.C compiler calculates the garbage value by using the formula<br />
<strong><br />
garbage value=overflow value-reference value.<br />
</strong></p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote>
<blockquote><p> <em><font color="blue">Overflow value is nothing but the value stored in the variable.Now what&#8217;s is the reference value??<br />
reference value is the value such that it is greater than the overflow value(neglecting the sign)obtained by the multiplication of the basic reference value by 2 until the value is greater than the overflow value(neglecting the sign) The sign of the reference value is same as that of overflow value Basic reference value is 2^n where n represents the number of bits allocated.</font></em></p>
<p><em><font color="blue">That means Basic reference value in case of int is 2^15=32768 and in case of long,it is  2^31=2147483648<br />
The garbage value thus calculated is checked whether it can fit the variable or not.If not the steps are repeated again.</font></em></p></blockquote>
</blockquote>
<p>Ok thats sounds confusing <img src="http://www.thinkdigit.com/forum/images/smilies/confused.gif" title="Confused" class="inlineimg" border="0" height="21" width="16" /><img src="http://www.thinkdigit.com/forum/images/smilies/confused.gif" title="Confused" class="inlineimg" border="0" /> lets take an example</p>
<p>ex1:</p>
<blockquote>
<blockquote><p><font color="#0000ff">a=45000;</font></p></blockquote>
</blockquote>
<blockquote><p><em>overflow value=45000<br />
Basic reference value=32768<br />
since the reference value is less than the overflow value ,we have to multiply it by 2<br />
i.e,32768*2=65536<br />
65536 is greater than the 45000.That means reference value(RV)=65536.SInce RV must be of same sign,RV=+65536<br />
now apply formula<br />
garbage value=overflow value-reference value.<br />
garbage value=45000-(+65536)<br />
garbage value=-20536<br />
-20536 comes within the limits of int datatype.</em></p></blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p class="smallfont" style="margin-bottom: 2px">&nbsp;</p>
<p>ex2:</p>
<blockquote><p><font color="#0000ff">b=4000000000;</font></p></blockquote>
<blockquote>
<blockquote><p>overflow value(OV)=4000000000<br />
SInce &#8216;b&#8217; is of long type Basic reference value=2147483648<br />
since the reference value is less than the overflow value ,we have to multiply it by 2<br />
i.e,2147483648*2=4294967296<br />
4294967296 is greater than the 4000000000.That means reference value(RV)=4294967296.SInce RV must be of same sign,RV=+4294967296<br />
now apply formula<br />
garbage value=overflow value-reference value.<br />
garbage value=4000000000-(+4294967296)<br />
garbage value=-294967296<br />
-294967296 comes within the limits of long datatype.</p>
<p>So the output of the program will be<br />
<font color="#ff6600">-20536                            -294967296</font></p></blockquote>
</blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote></blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote></blockquote>
<p>Now, run the program and see whether the output is same as calculated or not.</p>
<p>Modify the above program</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">a=-40000;</font><br />
<font color="#0000ff">b=-4500000000;</font></p></blockquote>
<p>now , do not run the program.</p>
<p>ex3:</p>
<blockquote><p><font color="#0000ff">a=-40000;</font></p></blockquote>
<blockquote>
<blockquote><p>OV=-40000<br />
discard the sign take 40000.Basic reference value=32768<br />
since the reference value is less than the overflow value ,we have to multiply it by 2<br />
i.e,32768*2=65536<br />
65536 is greater than the 40000.That means reference value(RV)=65536.SInce RV must be of same sign as OV,RV=-65536<br />
Now apply the formula<br />
garbage value=overflow value-reference value.<br />
garbage value=-40000-(-65536)<br />
garbage value=-40000+65536<br />
garbage value=25536<br />
25536 comes within the limits of int datatype.</p></blockquote>
</blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p>ex4:</p>
<p class="smallfont" style="margin-bottom: 2px">Code:</p>
<blockquote><p><font color="#0000ff">b=-45000000000;</font></p></blockquote>
<blockquote>
<blockquote><p>overflow value(OV)=-4500000000<br />
SInce &#8216;b&#8217; is of long type Basic reference value=2147483648<br />
discard the sign take 4500000000.<br />
since the reference value is less than the overflow value ,we have to multiply it by 2<br />
i.e,2147483648*2=4294967296 is less than 4500000000.<br />
therefore 4294967296*2=8589934592<br />
8589934592 is greater than the 4500000000.That means reference value(RV)=8589934592.SInce RV must be of same sign,RV=-8589934592<br />
now apply formula<br />
garbage value=overflow value-reference value.<br />
garbage value=-4500000000-(-8589934592)<br />
garbage value=-4500000000+8589934592)<br />
garbage value=4089934592<br />
<strong>4089934592 does not come within the limits of long datatype.</strong></p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p>The process is repeated again<br />
overflow value(OV)=4089934592<br />
RV=+4294967296<br />
garbage value=4089934592-(+4294967296)=-205032704<br />
-205032704 comes within the limits of long datatype.<br />
That means final garbage value is -205032704</p>
<p>So the output will be<br />
<font color="#ff6600">25536                      -205032704</font></p></blockquote>
</blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote></blockquote>
<p><em>Now run the program.Is your output matching with mine??</em></p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote>
<blockquote><p><strong><font color="#993366"><em>Some special cases:</em></font></strong></p>
<p><font color="#993366"><em>There is a special overflow value which will return the same overflow value but opposite in sign. The values are 32768 in case of int and 2147483648 in case of long datatype.The garbage value will be -32768 and -2147483648 respectively.<br />
Lets understand what happens.</em></font></p>
<p><font color="#993366"><em>As i already explained ,the maximum +ve value that can be stored by int datatype variable is 32767 not 32768<br />
That means.OV=32768 Basic RV=32768. RV must be greater than OV.Therfore RV=32768*2=65536<br />
Now, garbage value(GV)=OV-RV=32768-65536=-32768</em></font></p>
<p><font color="#993366"><em>Similarly apply this to 2147483648 you will get</em></font><br />
<font color="#993366"><em> GV=2147483648-4294967296</em></font><br />
<font color="#993366"><em> GV=-2147483648</em></font><br />
<font color="#993366"><em> Quite fascinating.Isn&#8217;t it??</em></font></p></blockquote>
</blockquote>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/save-as-pdf-option-in-your-website-or-blog.html" title="Save as pdf option in your website or blog">Save as pdf option in your website or blog</a></li><li><a href="http://blog.aditech.info/saving-the-output-of-a-c-program-in-a-text-filelinuxunix.html" title="Saving the output of a C program in a text file(Linux/Unix)">Saving the output of a C program in a text file(Linux/Unix)</a></li><li><a href="http://blog.aditech.info/dynamic-output-in-c.html" title="Dynamic Output in C">Dynamic Output in C</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-5.html" title="SEO for wordpress blogs-Part 5/5">SEO for wordpress blogs-Part 5/5</a></li><li><a href="http://blog.aditech.info/wordpress-2_6-a-complete-review-and-guide.html" title="Wordpress 2.6 -A complete review and Guide">Wordpress 2.6 -A complete review and Guide</a></li><li><a href="http://blog.aditech.info/saving-the-output-in-a-text-file.html" title="Saving the output in a text file">Saving the output in a text file</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/how-c-compiler-decides-the-garbage-values-in-case-of-data-overflow.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamic Output in C</title>
		<link>http://blog.aditech.info/dynamic-output-in-c.html</link>
		<comments>http://blog.aditech.info/dynamic-output-in-c.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 08:22:54 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[dynamic output]]></category>
		<category><![CDATA[justification]]></category>
		<category><![CDATA[precision in output]]></category>
		<category><![CDATA[printing n number characters in the string]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/dynamic-output-in-c/</guid>
		<description><![CDATA[Dynamic output consider the following program &#160; &#160; #include&#60;stdio.h&#62; int main() { long double a=3.14159265; printf(&#8220;Value of pi=%.4Lf&#8221;,a); return(1); } the output of the program will be &#160; Value of pi=3.1416 wouldn&#8217;t it be nice if we allow the user to choose how the precession of the answer would be?? that is the output should [...]]]></description>
			<content:encoded><![CDATA[<h1 align="center"><font color="#000000">Dynamic output</font></h1>
<p>consider the following program</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p class="smallfont" style="margin-bottom: 2px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;<br />
int main()<br />
{<br />
long double a=3.14159265;<br />
printf(&#8220;Value of pi=%.4Lf&#8221;,a);<br />
return(1);<br />
}</font></p></blockquote>
<p>the output of the program will be</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#ff6600">Value of pi=3.1416</font></p></blockquote>
<p>wouldn&#8217;t it be nice if we allow the user to choose how the precession of the answer would be??<br />
that is the output should be like this</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#ff6600">Enter</font><font color="#ff9900"> <font color="#ff6600">precision</font></font><br />
<font color="#ff6600">6</font><br />
<font color="#ff6600">The value of pi precised to 6 decimal number is 3.141593</font></p></blockquote>
<p>Well in that case the program will be like this</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;</font><br />
<font color="#0000ff">int main()</font><br />
<font color="#0000ff">{</font><br />
<font color="#0000ff">long double a=3.14159265;</font><br />
<font color="#0000ff">int pre;</font><br />
<font color="#0000ff">printf(&#8220;Enter </font><font color="#0000ff">precision</font><font color="#0000ff">\n&#8221;);</font><br />
<font color="#0000ff">scanf(&#8220;%d&#8221;,&amp;pre);</font><br />
<font color="#0000ff">printf(&#8220;The value of pi precised to %d decimal number is %.*Lf&#8221;,pre,pre,a);</font><br />
<font color="#0000ff">return(1);</font><br />
<font color="#0000ff">}</font></p></blockquote>
<p><em>see the difference,it is upto the user to decide how the output will be.<strong>The value of pi will be rounded off to fit the</strong></em><font color="#ff9900"><font color="#ff6600"> <strong><font color="#000000"><em>precision</em></font></strong> </font></font><em><strong>.</strong>Such an output is called dynamic output.</em></p>
<p>This is the part of the program which is important</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">printf(&#8220;The value of pi precised to %d decimal number is %.*Lf&#8221;,pre,pre,a);</font></p></blockquote>
<blockquote>
<blockquote><p><em><strong> you can create a dynamic output by just specifing * before control string and specifying the variable having precesion in the arguments list.As you can see i have specified pre twice because one to print the The value of pi precesiced to__ and the other to suggest the compiler to fill the * with the value of pre.</strong></em></p></blockquote>
</blockquote>
<p>This  fact can not only be used to specify the precision of the decimal number but also for various other things.Some of them are</p>
<p><strong>1.Printing first n characters of the given string </strong></p>
<p>consider</p>
<blockquote>
<p style="margin: 5px 20px 20px"><font color="#0000ff">printf(&#8220;The Output is %.*s&#8221;,pre,str);</font></p>
</blockquote>
<p>suppose the string variable str has a string of &#8220;adithya&#8221; and the value of int datatype variable pre is 3 then the output will</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">The Output is adi</font></p></blockquote>
<p>2.<strong>Justification</strong><br />
consider</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff"> printf(&#8220;The Output is %*.*f.Bye!&#8221;,just,pre,num);</font></p></blockquote>
<p>suppose num(float)=1983.78<br />
pre(int datatype variable)=2<br />
just(int datatype variable)=25</p>
<p>then the output will be in the form of right justification i.e,</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">The Output is                                     1983.78.Bye!</font></p></blockquote>
<p>suppose you want the output to be left justified then either you can specify &#8216;-*.*f&#8217; or give a negative value to the variable &#8216;just&#8217;<br />
suppose for the above example just=-25 then the output will be</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p class="smallfont" style="margin-bottom: 2px">Code:</p>
<blockquote><p><font color="#0000ff">The Output is 1983.78                                   .Bye!</font></p></blockquote>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/how-to-organize-your-firefox-web-history-just-like-opera.html" title="How to Organize your Firefox Web History just like Opera">How to Organize your Firefox Web History just like Opera</a></li><li><a href="http://blog.aditech.info/edit-set.html" title="Edit Set">Edit Set</a></li><li><a href="http://blog.aditech.info/how-to-refresh-or-flush-domain-name-systemdns-cache-in-windows.html" title="How to refresh or flush Domain Name System(DNS) Cache in windows">How to refresh or flush Domain Name System(DNS) Cache in windows</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-4.html" title="SEO for wordpress blogs-Part 4/5">SEO for wordpress blogs-Part 4/5</a></li><li><a href="http://blog.aditech.info/how-c-compiler-decides-the-garbage-values-in-case-of-data-overflow.html" title="How C Compiler decides the Garbage values in case of data overflow">How C Compiler decides the Garbage values in case of data overflow</a></li><li><a href="http://blog.aditech.info/important-instructions-for-programs-using-mathh-library-function.html" title="Important instructions for programs using math.h library function">Important instructions for programs using math.h library function</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/dynamic-output-in-c.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>floor and ceil</title>
		<link>http://blog.aditech.info/floor-and-ceil.html</link>
		<comments>http://blog.aditech.info/floor-and-ceil.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 08:09:38 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[ceil]]></category>
		<category><![CDATA[floor]]></category>
		<category><![CDATA[math.h]]></category>
		<category><![CDATA[round down the number]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/floor-and-ceil/</guid>
		<description><![CDATA[&#160; floor and ceil floor and ceil functions comes under math.h header file. floor is used to round down the value of the decimal number and ceil is used to round up the value of the decimal number. consider the following c program #include&#60;stdio.h&#62; #include&#60;math.h&#62; #include&#60;conio.h&#62; { float a; clrscr(); printf(&#8220;Enter any decimal number\n&#8221;); scanf(&#8220;%f&#8221;,&#38;a); [...]]]></description>
			<content:encoded><![CDATA[<p align="center">&nbsp;</p>
<h1><strong>floor and ceil</strong></h1>
<p>floor and ceil functions comes under math.h header file.<br />
floor is used to round down the value of the decimal number and ceil is used to round up the value of the decimal number.</p>
<p>consider the following c program</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;</font><br />
<font color="#0000ff">#include&lt;math.h&gt;</font><br />
<font color="#0000ff">#include&lt;conio.h&gt;</font><br />
<font color="#0000ff">{</font><br />
<font color="#0000ff">float a;</font><br />
<font color="#0000ff">clrscr();</font><br />
<font color="#0000ff">printf(&#8220;Enter any decimal number\n&#8221;);</font><br />
<font color="#0000ff">scanf(&#8220;%f&#8221;,&amp;a);</font><br />
<font color="#0000ff">printf(&#8220;Using floor the value is %d and using ceil it is %d\n&#8221;,floor(a),ceil(a));</font><br />
<font color="#0000ff">getch();</font><br />
<font color="#0000ff">}</font></p></blockquote>
<p><em>Output:</em><br />
<font color="#ff6600">Enter any decimal number<br />
5656.98<br />
Using floor the value is 5656 and using ceil it is 5657</font></p>
<blockquote>
<blockquote><p><em>In otherwords floor will neglect the decimal part while ceil will add 1 to the mantissa part.Hence we can say that floor is similar to casting.That means floor(a) is equivalent to (int)a or (long)a</em></p>
<p><em>These 2 functions do not depend upon the  value after decimal point that means if the program is run with the value 5656.01 then the output will be same.</em></p></blockquote>
</blockquote>
<p>Similarly there is floorl and also ceill which returns long type integers</p>
<blockquote></blockquote>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p class="smallfont" style="margin-bottom: 2px">&nbsp;</p>
<blockquote></blockquote>
<blockquote></blockquote>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/how-to-organize-your-firefox-web-history-just-like-opera.html" title="How to Organize your Firefox Web History just like Opera">How to Organize your Firefox Web History just like Opera</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-3.html" title="SEO for wordpress blogs-Part 3/5">SEO for wordpress blogs-Part 3/5</a></li><li><a href="http://blog.aditech.info/c-in-linuxunix-first-step.html" title="C in linux/unix-First step">C in linux/unix-First step</a></li><li><a href="http://blog.aditech.info/create-you-own-custom-firefox-search-plugin-in-seconds.html" title="Create you own custom Firefox search plugin in seconds">Create you own custom Firefox search plugin in seconds</a></li><li><a href="http://blog.aditech.info/the-mistake-in-made-with-my-rss-feeds.html" title="The mistake in made with my RSS feeds&#8230;">The mistake in made with my RSS feeds&#8230;</a></li><li><a href="http://blog.aditech.info/advantages-of-running-c-in-linuxunix-1.html" title="Advantages of running c in Linux/Unix-1">Advantages of running c in Linux/Unix-1</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/floor-and-ceil.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Const data type</title>
		<link>http://blog.aditech.info/const-data-type.html</link>
		<comments>http://blog.aditech.info/const-data-type.html#comments</comments>
		<pubDate>Wed, 20 Feb 2008 08:00:34 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[#define]]></category>
		<category><![CDATA[const data type]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/20/const-data-type/</guid>
		<description><![CDATA[&#160; const data type This lesser known data type is used to declare constants.The syntax is const type name=value; ex: const int a=10; is equivalent to &#160; #define a 10 now consider this program &#160; &#160; #include&#60;stdio.h&#62; void main() { const int a=10; printf(&#8220;%d&#8221;,a); a=14; printf(&#8220;%d&#8221;,a); } what do you think the ouput will be??? [...]]]></description>
			<content:encoded><![CDATA[<p align="center">&nbsp;</p>
<h1 align="center"><strong>const data type</strong></h1>
<p>This lesser known data type is used to declare constants.The syntax is<br />
<em>const type name=value;</em><br />
ex:</p>
<blockquote><p><font color="#0000ff">const int a=10;</font></p></blockquote>
<p>is equivalent to</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#define a 10</font></p></blockquote>
<p>now consider this program</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p class="smallfont" style="margin-bottom: 2px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;<br />
</font> <font color="#0000ff">void main()<br />
</font> <font color="#0000ff">{<br />
</font> <font color="#0000ff">const int a=10;<br />
</font> <font color="#0000ff">printf(&#8220;%d&#8221;,a);<br />
</font> <font color="#0000ff">a=14;<br />
</font> <font color="#0000ff">printf(&#8220;%d&#8221;,a);<br />
</font> <font color="#0000ff">}</font></p></blockquote>
<p>what do you think the ouput will be???<br />
First off all the program will not compile itself because it is not allowed to change the value of &#8216;a&#8217; <strong>statically</strong>(within the program)<br />
now change the program as</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;<br />
</font> <font color="#0000ff">void main()<br />
</font> <font color="#0000ff">{<br />
</font> <font color="#0000ff">const int a=10;<br />
</font> <font color="#0000ff">printf(&#8220;%d&#8221;,a);<br />
</font> <font color="#0000ff">printf(&#8220;Enter new value\n&#8221;);<br />
</font> <font color="#0000ff">scanf(&#8220;%d&#8221;,&amp;a);<br />
</font> <font color="#0000ff">printf(&#8220;The value is now %d&#8221;,a);<br />
</font> <font color="#0000ff">}</font></p></blockquote>
<p>will change the value of a</p>
<p><strong>That means we can change the value of the constant declared by using const in run time mode(Dynamically) but not Statically(within the program)</strong>.</p>
<p>now consider this program</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">#include&lt;stdio.h&gt;<br />
</font> <font color="#0000ff">#define a 10<br />
</font> <font color="#0000ff">void main()<br />
</font> <font color="#0000ff">{<br />
</font> <font color="#0000ff">printf(&#8220;%d&#8221;,a);<br />
</font> <font color="#0000ff">printf(&#8220;Enter new value\n&#8221;);<br />
</font> <font color="#0000ff">scanf(&#8220;%d&#8221;,&amp;a);<br />
</font> <font color="#0000ff">printf(&#8220;The value is now %d&#8221;,a);<br />
</font> <font color="#0000ff">}</font></p></blockquote>
<p>what do you think the output will be???<br />
the program will not be compiled,that means that we can access the value of &#8216;a&#8217; but not able to use scanf.</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<table border="0" cellpadding="6" cellspacing="0" width="100%">
<tr>
<td class="alt2" style="border: 1px inset ">So, the difference between const and #define is that we can change the value of the constant during runtime execution if we use const where as we are unable to do so if we use #define.</td>
</tr>
</table>
<p>The use of const is not restricted to int only.</p>
<p>ex:</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">const char a=&#8217;y';/*char*/<br />
</font> <font color="#0000ff">const char a[10]={&#8220;adithya&#8221;};/*String*/<br />
</font> <font color="#0000ff">const float a=4.67;/*float*/<br />
</font> <font color="#0000ff">const long double a=9.78843434;/*long double*/</font></p></blockquote>
<p>now you can say that all these can be done using #define also.</p>
<p>But there are several things for which we cannot use #define<br />
The excellent example is array.</p>
<p>Can anyone tell me how to declare an static constant array using #define???</p>
<p>But i can tell you how to do so using const</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<blockquote><p><font color="#0000ff">const float a[10]={1,3,5};</font></p></blockquote>
<p><em><strong>Note:</strong><br />
1.I have tested these in Turbo C for windows.Earlier versions of C will not support this datatype.<br />
2.The constants created by using const is called as static constant.If you want your constant to be both dynamic as well as static,the only way is to use #define</em></p>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/atoiatol-and-atof-functions.html" title="atoi,atol and atof functions">atoi,atol and atof functions</a></li><li><a href="http://blog.aditech.info/saving-the-output-in-a-text-file.html" title="Saving the output in a text file">Saving the output in a text file</a></li><li><a href="http://blog.aditech.info/c-in-linuxunix-first-step.html" title="C in linux/unix-First step">C in linux/unix-First step</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-5.html" title="SEO for wordpress blogs-Part 5/5">SEO for wordpress blogs-Part 5/5</a></li><li><a href="http://blog.aditech.info/random-post-option-in-wordpress.html" title="Random post option in wordpress&#8230;">Random post option in wordpress&#8230;</a></li><li><a href="http://blog.aditech.info/bulid-your-own-open-suse-distro-using-open-studio.html" title="Bulid Your Own Open Suse Distro Using Open Studio">Bulid Your Own Open Suse Distro Using Open Studio</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/const-data-type.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>enum data type</title>
		<link>http://blog.aditech.info/enum-data-type.html</link>
		<comments>http://blog.aditech.info/enum-data-type.html#comments</comments>
		<pubDate>Sat, 16 Feb 2008 12:00:28 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[enum]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/16/enum-data-type/</guid>
		<description><![CDATA[enum data type: it means enumerated type. It&#8217;s a user defined datatype.It&#8217;s syntax is enum name{value1,value2,&#8230;..valuen); ex:enum week{sunday,monday,tuesday,wednesday,thursday,friday,saturday} and afterwards to declare variables of enum type &#8216;name&#8217; enum name variables; ex:enum week a; now after doing this we can directly assign the value of a as ex:a=friday; the value of a will be 4.Because the [...]]]></description>
			<content:encoded><![CDATA[<h2>enum data type:</h2>
<p>it means enumerated type.<br />
It&#8217;s a user defined datatype.It&#8217;s syntax is</p>
<p><font color="#000080"><font color="#ff00ff">enum name{value1,value2,&#8230;..valuen);</font><br />
</font><br />
ex:<font color="#000080">enum week{sunday,monday,tuesday,wednesday,thursday,friday,saturday}</font></p>
<p>and afterwards to declare variables of enum type &#8216;name&#8217;</p>
<p><font color="#ff00ff">enum name variables;<br />
</font><br />
ex:<font color="#000080">enum week a;</font></p>
<p>now after doing this we can directly assign the value of a as</p>
<p>ex:<font color="#000080">a=friday;</font></p>
<p>the value of a will be 4.Because the compiler will automatically assign the value 0 to sunday,1 to monday and so on..<br />
if we want to change the sequence we can specify as</p>
<p><font color="#000080">enum week{sunday=1,monday,tuesday,wednesday,thursday,friday,saturday};</font></p>
<p>now the compiler will start assigning value to names from 1<br />
that means<br />
if we specify</p>
<p><font color="#000080">a=friday;<br />
printf(%d&#8221;,a);</font></p>
<p>then 6 will be the output.</p>
<p>we can also specify random values to names like</p>
<p><font color="#000080">enum week{sunday=4,monday=5,tuesday=1,wednesday=3,thursday=7,friday=2,sat=6};</font></p>
<p>and corresponding values of the name will be printed.<br />
let&#8217;s come to the defenition of enum datatype..<br />
if you refer some books it states as</p>
<p><font color="#ff00ff"><em>An enumerated type is an abstract data type used to model an attribute that has a specific number of options (or identifiers)</em></font></p>
<p><font color="#ff00ff"></font><br />
That means we cannot specify the value other than the specified names declared.<br />
But consider the following program<br />
<font color="#000080">#include&lt;stdio.h&gt;<br />
#include&lt;conio.h&gt;<br />
{<br />
enum week{sun=4,mon=5,tues=1,wednes=3,thurs=7,friday=2,sat=6};<br />
enum week a;<br />
a=25;<br />
printf(%d&#8221;,a);<br />
getche()<br />
}</font></p>
<p>will print 25 itself.I don&#8217;t know whether i am correct or not</p>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/reg-jump-jump-into-the-registry.html" title="Reg Jump: Jump into the registry">Reg Jump: Jump into the registry</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-4.html" title="SEO for wordpress blogs-Part 4/5">SEO for wordpress blogs-Part 4/5</a></li><li><a href="http://blog.aditech.info/create-you-own-custom-firefox-search-plugin-in-seconds.html" title="Create you own custom Firefox search plugin in seconds">Create you own custom Firefox search plugin in seconds</a></li><li><a href="http://blog.aditech.info/important-instructions-for-programs-using-mathh-library-function.html" title="Important instructions for programs using math.h library function">Important instructions for programs using math.h library function</a></li><li><a href="http://blog.aditech.info/twitter-exposed.html" title="Twitter Exposed">Twitter Exposed</a></li><li><a href="http://blog.aditech.info/changing-cd-dvdfloppy-drives-label-and-icon.html" title="Changing CD/DVD/Floppy Drive(s) label and icon">Changing CD/DVD/Floppy Drive(s) label and icon</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/enum-data-type.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Edit Set</title>
		<link>http://blog.aditech.info/edit-set.html</link>
		<comments>http://blog.aditech.info/edit-set.html#comments</comments>
		<pubDate>Sat, 16 Feb 2008 11:45:42 +0000</pubDate>
		<dc:creator>adithya</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Lesser Known Facts]]></category>
		<category><![CDATA[edit set]]></category>
		<category><![CDATA[exclude set]]></category>
		<category><![CDATA[include set]]></category>

		<guid isPermaLink="false">http://blog.aditech.info/2008/02/16/edit-set/</guid>
		<description><![CDATA[EditSet: This will be great useful in strings.You can specify the characters you want to include or exclude in C.This will work with scanf. Include set: Ex:scanf(&#8220;%[a-z]&#8220;,a); means it will read all the characters between a to z and if other character in encountered, it will stop reading the variable. Ex:if the input is adithyaU, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>EditSet:</strong></p>
<p>This will be great useful in strings.You can specify the characters you want to include or exclude in C.This will work with scanf.<br />
<strong>Include set:</strong></p>
<p><em> Ex:</em><font color="#0000ff">scanf(&#8220;%[a-z]&#8220;,a);</font><br />
means it will read all the characters between a to z and if other character in encountered, it will stop reading the variable.<br />
Ex:if the input is adithyaU, then the value of string variable &#8216;a&#8217; will be adithya only.</p>
<p>You can specify the individual chars also<br />
<em> Ex:</em><font color="#0000ff">scanf(&#8220;%[a,d,i]&#8220;,a);</font><br />
will read only the chars a,d,i<br />
if input adithya then the value of &#8216;a&#8217; will be adi only.</p>
<p>Special characters and white spaces may also be included in the edit set</p>
<p><em> Ex:</em><font color="#0000ff">scanf(&#8220;%[*],a); </font><br />
will read only chars *</p>
<p><strong>Exclude set</strong></p>
<p><em> ex:</em><font color="#0000ff">scanf(&#8220;%[^t]&#8220;,a);</font><br />
means it wil read all the characters until t is encountered</p>
<p><strong>Here all the chars means special chars and white space chars are also included.That means draw back of </strong><strong>scanf over gets can be overcome by using exclude set</strong></p>
<p>if i input adithya then the value of &#8216;a&#8217; will be adi</p>
<p>ex:<font color="#0000ff">scanf(&#8220;%[^A-Z]&#8220;,a);</font><br />
means no Capital&#8217;s are allowed</p>
<p>ex:<font color="#0000ff">scanf(&#8220;%[^\n]&#8220;,a);</font><br />
read <strong>ALL</strong> chars until enter key is encountered(Function as gets())</p>
<p>The use of edit set is illustrated in the following program:</p>
<p>Write a c program which makes scanf to accept the special as well as white space chars</p>
<p style="margin: 5px 20px 20px">&nbsp;</p>
<p> Example Program:</p>
<p><font color="#0000ff">#include&lt;stdio.h&gt;<br />
void main()<br />
{<br />
char str[100];<br />
printf(&#8220;Enter any string\n&#8221;);<br />
scanf(&#8220;%[^\n]s&#8221;,str); //&lt;&#8212;&#8211; Imp step&#8212;&#8212;&#8211;<br />
printf(&#8220;\n You entered string %s \n&#8221;,str);<br />
} </font></p>
<h3  class="related_post_title"><hr>You may also like</h3><ul class="related_post"><li><a href="http://blog.aditech.info/ascii-chart.html" title="ASCII Chart">ASCII Chart</a></li><li><a href="http://blog.aditech.info/how-to-refresh-or-flush-domain-name-systemdns-cache-in-windows.html" title="How to refresh or flush Domain Name System(DNS) Cache in windows">How to refresh or flush Domain Name System(DNS) Cache in windows</a></li><li><a href="http://blog.aditech.info/saving-the-output-in-a-text-file.html" title="Saving the output in a text file">Saving the output in a text file</a></li><li><a href="http://blog.aditech.info/const-data-type.html" title="Const data type">Const data type</a></li><li><a href="http://blog.aditech.info/seo-for-wordpress-blogs-part-3.html" title="SEO for wordpress blogs-Part 3/5">SEO for wordpress blogs-Part 3/5</a></li><li><a href="http://blog.aditech.info/how-to-organize-your-firefox-web-history-just-like-opera.html" title="How to Organize your Firefox Web History just like Opera">How to Organize your Firefox Web History just like Opera</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://blog.aditech.info/edit-set.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
