<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;A0MFRH8yfip7ImA9WhRRFE4.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813</id><updated>2011-11-28T05:46:55.196+05:30</updated><category term="LINUX SHELL" /><category term="INTERESTING C PROGRAMS" /><category term="SORTING ALGORITHMS" /><title>Interesting C Programs</title><subtitle type="html">A Collection Of Weird and Interesting C Programs by Balaji</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://interestingcprograms.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>31</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/bdfew" /><feedburner:info uri="blogspot/bdfew" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;DUABQ30_eSp7ImA9WxFbFUg.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-6252314187024839303</id><published>2010-07-08T08:20:00.003+05:30</published><updated>2010-07-08T08:25:52.341+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-08T08:25:52.341+05:30</app:edited><title>Understanding Filesystems Part-1</title><content type="html">For the past few days, I am trying to understand the memory fundamentals behind the Filesystems.  I will not say it a complete description of filesystems, but my worth notable observations on my current filesystem.&lt;br /&gt;Experimental Setup: &lt;br /&gt;Hardware:&lt;br /&gt;1. A PC running both Windows and Linux [Fedora13].&lt;br /&gt;2. An Experimental Pendrive. Please dont have any valuable information in it. We are going to format it.&lt;br /&gt;3. Another pendrive to transfer data between Linux and Windows. I did not find a safe and better way to do this, since I am still a newbie to linux.&lt;br /&gt;Software Tools:&lt;br /&gt;1. HexEdit [http://www.physics.ohio-state.edu/~prewett/hexedit/]. A tool to display the raw data.&lt;br /&gt;2. dd Utility for Windows [http://www.chrysocome.net/download]. Utility to take image of source to destination. I use to call it a "PHOTOGRAPH TOOL" ;).&lt;br /&gt;&lt;br /&gt;Though Windows is a sophisticated operating system, it hides all the micro level details from the users. So user may not be aware of what exactly is happening inside the Computer box. So take an Operating System like linux, that will open up things if demanded by the user. &lt;br /&gt;Now lets start our experiment.&lt;br /&gt;Let us understand how my computer interprets a pendrive memory. &lt;br /&gt;I booted into Linux. Pendrive got automounted. Following are commands to be executed and their responses.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;[root@localhost ~]# cat /proc/partitions &lt;br /&gt;major minor  #blocks  name&lt;br /&gt;&lt;br /&gt;   8        0   20971520 sda&lt;br /&gt;   8        1   19921920 sda1&lt;br /&gt;   8        2    1048576 sda2&lt;br /&gt;   8       16    7831552 sdb&lt;br /&gt;   8       17    7825423 sdb1&lt;br /&gt;   8       32  976762584 sdc&lt;br /&gt;   8       33  976762552 sdc1&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;In the above response, /dev/sdb is Experimental Pendrive and /dev/sdc is Data Transfer Pendrive.&lt;br /&gt;Now issue the following command in the terminal. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;[root@localhost ~]# fdisk /dev/sdb&lt;br /&gt;&lt;br /&gt;WARNING: DOS-compatible mode is deprecated. It's strongly recommended to&lt;br /&gt;         switch off the mode (command 'c') and change display units to&lt;br /&gt;         sectors (command 'u').&lt;br /&gt;&lt;br /&gt;Command (m for help): p&lt;br /&gt;&lt;br /&gt;Disk /dev/sdb: 8019 MB, 8019509248 bytes&lt;br /&gt;247 heads, 62 sectors/track, 1022 cylinders&lt;br /&gt;Units = cylinders of 15314 * 512 = 7840768 bytes&lt;br /&gt;Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;Disk identifier: 0xc3072e18&lt;br /&gt;&lt;br /&gt;   Device Boot      Start         End      Blocks   Id  System&lt;br /&gt;/dev/sdb1               1        1022     7825423   83  Linux&lt;br /&gt;&lt;br /&gt;Command (m for help): q&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;In this post, I am going to dissect the above response that I got from my linux machine. &lt;br /&gt;When I give a &lt;code&gt;fdisk /dev/sdb&lt;/code&gt;, it entered a command response mode. &lt;br /&gt;I gave the command 'p'. It returned me the partition details in CHS [Cylinder Head Sector] format [which is conventional in case of harddisks]. Lets take some observations.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Disk /dev/sdb: 8019 MB, 8019509248 bytes&lt;br /&gt;247 heads, 62 sectors/track, 1022 cylinders&lt;br /&gt;Units = cylinders of 15314 * 512 = 7840768 bytes&lt;br /&gt;Sector size (logical/physical): 512 bytes / 512 bytes&lt;br /&gt;I/O size (minimum/optimal): 512 bytes / 512 bytes&lt;br /&gt;Disk identifier: 0xc3072e18&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Observation-1: Disk is detected as /dev/sdb.&lt;br /&gt;Observation-2: Size of disk is 8019MB = 8019*1024*1024 Bytes = 8019509248 bytes. Yes its an 8GB Pendrive.&lt;br /&gt;Observation-3: How is it interpreted in the system? What is this "247 heads, 62 sectors/track, 1022 cylinders"?&lt;br /&gt;Head: Data is written to read from a device called "Platter". A Platter comprises of two heads one on each side. &lt;br /&gt;Track: The track is a thin concentric circular strip on a Platter surface which actually contain the magnetic regions of data written to a disk drive.&lt;br /&gt;Cylinders: A set of tracks with same track no (ie. on the same platter surface) are called Cylinders.&lt;br /&gt;Sector : A track is divided into 512 byte segment called Sectors.&lt;br /&gt;&lt;br /&gt;Now lets do the calculation. &lt;br /&gt;247 heads, 62 sectors/track, 1022 cylinders&lt;br /&gt;&lt;br /&gt;means there are 247 heads to read the tracks.&lt;br /&gt;There are 62 sectors per track. Seems like only one track per cylinder.&lt;br /&gt;There are 1022 such cylinders are available in my pendrive.&lt;br /&gt;&lt;br /&gt;Total Size of Pendrive (in Bytes) = No. of Heads * No of Sectors/track * No. of Cylinders * 512 Bytes.&lt;br /&gt;Total Size of Pendrive (in Bytes) = 247 * 62 * 1022 * 512 Bytes&lt;br /&gt;Total Size of Pendrive (in Bytes) = 8013264896 bytes&lt;br /&gt;Total Size of Pendrive (in Bytes) = 8013264896 / (1024 * 1024 *1024) Gigabytes&lt;br /&gt;Total Size of Pendrive (in Bytes) = 7.4629344940185546875 Gigabytes&lt;br /&gt;&lt;br /&gt;This is how the calculation goes.&lt;br /&gt;&lt;br /&gt;In my next post, let us see what exactly a "formatting of Pendrive" means and use the tools above.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-6252314187024839303?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/rYIOJbA1CFZ-cuHpspDzCOil_x0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rYIOJbA1CFZ-cuHpspDzCOil_x0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/rYIOJbA1CFZ-cuHpspDzCOil_x0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/rYIOJbA1CFZ-cuHpspDzCOil_x0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/vs_bpoJ_xrE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/6252314187024839303/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=6252314187024839303&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6252314187024839303?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6252314187024839303?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/vs_bpoJ_xrE/understanding-filesystems-part-1.html" title="Understanding Filesystems Part-1" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2010/07/understanding-filesystems-part-1.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUDQ3szeSp7ImA9WxFXEE4.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-6202815712818197082</id><published>2010-05-16T22:30:00.003+05:30</published><updated>2010-05-16T23:54:32.581+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-16T23:54:32.581+05:30</app:edited><title>Secrets of STATIC variable</title><content type="html">STATIC Variable&lt;br /&gt;Wiki Says - &lt;br /&gt;&lt;I&gt;"In computer programming, a static variable is a variable that has been allocated statically — whose lifetime extends across the entire run of the program." &lt;/I&gt;&lt;br /&gt;&lt;br /&gt;Lets demonstrate this definition before going any further.&lt;br /&gt;Have a look at the following program&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;void func1(void);&lt;br /&gt;int gv; //Global Variable&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; printf("%u\n",&amp;gv); //Print the Address of Global Variable&lt;br /&gt; func1();&lt;br /&gt; func1();&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void func1(void)&lt;br /&gt;{&lt;br /&gt; int rlv = 0; //Declare and Initialize a local Variable&lt;br /&gt; static int slv; // Declare a local variable&lt;br /&gt; printf("%d\n",rlv); //Print the content of local variable&lt;br /&gt; rlv++; //Increment the local variable&lt;br /&gt; printf("%d\n",rlv); //Print the content of local variable&lt;br /&gt; printf("%u\n",&amp;rlv); //Print the address of local variable&lt;br /&gt;&lt;br /&gt; printf("%d\n",slv); //Print the content of static local variable&lt;br /&gt; slv++; //Increment the static local variable&lt;br /&gt; printf("%d\n",slv); //Print the content of incremented static local variable&lt;br /&gt; printf("%u\n",&amp;slv); //Print the address of static local variable&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Output:&lt;br /&gt;4210808&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2293588&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;4210696&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;2293588&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;4210696&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Some Observation from the above code:&lt;br /&gt;Observation-1: A static variable need not be initialized. It will be initialized to zero by the system.&lt;br /&gt;Observation-2: A global variable need not be initialized. It will be initialized to zero by the system.&lt;br /&gt;Observation-3: A regular local variable has to be initialized by the user. Otherwise junk will be stored.&lt;br /&gt;Observation-4: The value of a static variable is retained/is preserved for future use even when the control leaves the function, whereas the value of a local variable will not be retained as the control leaves the function. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next lets look at the following program:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;void func1(void);&lt;br /&gt;void func2(void);&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; func1();&lt;br /&gt; func2();&lt;br /&gt; func1();&lt;br /&gt; func2();&lt;br /&gt;}&lt;br /&gt;void func1(void)&lt;br /&gt;{&lt;br /&gt; static int x;&lt;br /&gt; printf("%u\n",&amp;x);&lt;br /&gt; printf("%d\n",x++);&lt;br /&gt;}&lt;br /&gt;void func2(void)&lt;br /&gt;{&lt;br /&gt; static int x;&lt;br /&gt; printf("%u\n",&amp;x);&lt;br /&gt; printf("%d\n",x+=2);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Let me explain the problem. From the program discussed previously, we learnt that the value of the static variable is preserved. ie. the static local variable though the scope is local to a function, has a lifetime till the program ends. That being the case if we give same name for two static variables in two functions how are they handled? Is it correct to give same name to two static varibles in two functions?&lt;br /&gt;Now Can you guess its output?&lt;br /&gt;May be by fluke some of you have answered it correct. Ok the answer is&lt;br /&gt;&lt;code&gt;&lt;br /&gt;4210712&lt;br /&gt;0&lt;br /&gt;4210696&lt;br /&gt;2&lt;br /&gt;4210712&lt;br /&gt;1&lt;br /&gt;4210696&lt;br /&gt;4&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Let me explain the output.&lt;br /&gt;Just execute the following line before I explain:&lt;br /&gt;nm &lt;Filename.o&gt;&lt;br /&gt;The symbol table looks something like this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;C:\Documents and Settings\Balaji\Desktop&gt;nm tst.o&lt;br /&gt;00000000 b .bss&lt;br /&gt;00000000 d .data&lt;br /&gt;00000000 r .rdata&lt;br /&gt;00000000 t .text&lt;br /&gt;         U ___main&lt;br /&gt;         U __alloca&lt;br /&gt;00000045 T _func1&lt;br /&gt;0000007c T _func2&lt;br /&gt;000000b4 T _func3&lt;br /&gt;00000000 T _main&lt;br /&gt;         U _printf&lt;br /&gt;00000000 b x.0&lt;br /&gt;00000010 b x.1&lt;br /&gt;00000020 b x.2&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Hope you understood the reason for the output.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-6202815712818197082?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9h8lDvEKRZl-7B89GCwBTxiRN0k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9h8lDvEKRZl-7B89GCwBTxiRN0k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9h8lDvEKRZl-7B89GCwBTxiRN0k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9h8lDvEKRZl-7B89GCwBTxiRN0k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/_tYONhyuJqo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/6202815712818197082/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=6202815712818197082&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6202815712818197082?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6202815712818197082?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/_tYONhyuJqo/secrets-of-static-variable.html" title="Secrets of STATIC variable" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2010/05/secrets-of-static-variable.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkYGSXs4cCp7ImA9WxJXEU8.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-4431533622007486153</id><published>2009-06-03T22:05:00.023+05:30</published><updated>2009-06-04T19:32:08.538+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-04T19:32:08.538+05:30</app:edited><title>Cracking the Myths Behind the Microcontroller Clock</title><content type="html">Hi,&lt;br /&gt;     I being a embedded engineer, would like to discuss something interesting with respect to a controller. Every microcontroller will have its operational frequency. This frequency is provided by a Clock Source. This can be an internal or external. Though I was working on Micro controllers for a long time, I have to admit that clocks were a big black box for me. So I decided to break all the mystery behind Clocks. This understanding is the first step to optimize your code. This is the point where hardware and firmware meet eachother. For an embedded engineer, who is doing his development in C, need to take these things into consideration.&lt;br /&gt;&lt;br /&gt;Now that its high time to understand what a clock meant to a Microcontroller. I had a small experimental setup. This consists of my custom ATMega128L board, a tektronics oscilloscope and a multimeter. I program in AVRStudio, which uses WinAVR to compile the code and generate hex file. This ATMega128L can run at a max frequency of 8MHz and can operate at 3.3V. I used an internal RC Oscillator @8MHz. &lt;br /&gt;&lt;br /&gt;Now lets get into some analysis.&lt;br /&gt;What is this 8MHz mean? This is the speed at which our internal RC Oscillator oscillates. That is the clock oscillates 8000000 times every second, which means that it takes 125nanoseconds(=1/8000000) for one oscillation. ATMega128L being a RISC Processor, each of its instruction is executed in one clock cycle. So one instruction is executed per cycle. Fine, if this is going to be the case, then how fast can I toggle a General Purpose Input Output Pin (GPIO Pin)? This is the place where our coding style comes into picture. In the later part of the article, I am going to explain how Coding Style affects the speed. At the end of this article you will understand how the clock affects the speed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Example-1:&lt;br /&gt;#include "avr/io.h"        //Controller Specific Header File.&lt;br /&gt;//Start of Main - Entry into the program.&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;     DDRD = 0x01;          //Direction of the PORTD0 Pin is set as Output.&lt;br /&gt;     while(1)&lt;br /&gt;     {&lt;br /&gt;          PORTD |= 0x01;   //Make PortD0 high,keeping all other pins as it is.&lt;br /&gt;          PORTD &amp;= 0xFE;   //Make PortD0 low,keeping all other pins as it is.&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The following is the waveform that I got when I executed this code. &lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_9ZzqbeS_y-o/Sie_GzLQrqI/AAAAAAAAANM/tF-EDli6Gxc/s1600-h/F0004TEK.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_9ZzqbeS_y-o/Sie_GzLQrqI/AAAAAAAAANM/tF-EDli6Gxc/s320/F0004TEK.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343449606435942050" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This program produces a square waveform, and does nothing. Guess what is the frequency of the square waveform I got. It is hardly around 1.316MHz. Are you surprised to see a 8 MHz clock to ~1.3 MHz.&lt;br /&gt;&lt;br /&gt;This result provoked me for further experimentations. I tried to use some directives that I got with AVRlib. Following is the code that I tried.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Example-2:&lt;br /&gt;#include "avr/io.h"        //Controller Specific Header File.&lt;br /&gt;//Start of Main - Entry into the program.&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;     DDRD = 0x01;          //Direction of the PORTD0 Pin is set as Output.&lt;br /&gt;     while(1)&lt;br /&gt;     {&lt;br /&gt;          sbi(PORTD,0);   //Make PortD0 high,keeping all other pins as it is.&lt;br /&gt;          cbi(PORTD,0);   //Make PortD0 low,keeping all other pins as it is.&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I ended up with the same result. The waveforms looked alike. Following is the waveform I got.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_9ZzqbeS_y-o/SifAffXn7LI/AAAAAAAAANc/Pc5fTsn2yTw/s1600-h/F0003TEK.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_9ZzqbeS_y-o/SifAffXn7LI/AAAAAAAAANc/Pc5fTsn2yTw/s320/F0003TEK.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343451130127445170" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;My next attempt was a bit logical. I used EXOR operation, thinking that each EXOR operation will be completed in one cycle. Following is the code outcome of this experiment. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Example-3:&lt;br /&gt;#include "avr/io.h"        //Controller Specific Header File.&lt;br /&gt;//Start of Main - Entry into the program.&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;     DDRD = 0x01;          //Direction of the PORTD0 Pin is set as Output.&lt;br /&gt;     while(1)&lt;br /&gt;     {&lt;br /&gt;          PORTD^=0x01;   //Make PortD0 high,keeping all other pins as it is.&lt;br /&gt;          PORTD^=0x01;   //Make PortD0 low,keeping all other pins as it is.&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;But this infact increased the clock time period. Following is the output waveform.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_9ZzqbeS_y-o/SifBlSwNvPI/AAAAAAAAANk/gAn__7DSPMc/s1600-h/F0002TEK.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_9ZzqbeS_y-o/SifBlSwNvPI/AAAAAAAAANk/gAn__7DSPMc/s320/F0002TEK.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343452329331768562" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This time I wanted to try something simple. So I wrote a program like this. Some may think that it is foolishness. But it really worked. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Example-4:&lt;br /&gt;#include "avr/io.h"        //Controller Specific Header File.&lt;br /&gt;//Start of Main - Entry into the program.&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;     DDRD = 0xFF;          //Direction of the PORTD0 Pin is set as Output.&lt;br /&gt;     PORTD = 0x01;&lt;br /&gt;     PORTD = 0x00;&lt;br /&gt;     PORTD = 0x01;&lt;br /&gt;     PORTD = 0x00;&lt;br /&gt;     PORTD = 0x01;&lt;br /&gt;     PORTD = 0x00;&lt;br /&gt;     PORTD = 0x01;&lt;br /&gt;     PORTD = 0x00;&lt;br /&gt;     PORTD = 0x01;&lt;br /&gt;     PORTD = 0x00;&lt;br /&gt;     PORTD = 0x01;&lt;br /&gt;     PORTD = 0x00;&lt;br /&gt;     return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I was amazed to see the waveform!!! Following is the waveform.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_9ZzqbeS_y-o/SifF_BqIb7I/AAAAAAAAANs/uYf9hNW12fw/s1600-h/F0001TEK.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://2.bp.blogspot.com/_9ZzqbeS_y-o/SifF_BqIb7I/AAAAAAAAANs/uYf9hNW12fw/s320/F0001TEK.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343457169465962418" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;There are two things that I changed in the Example-4 compared to other examples. They are&lt;br /&gt;1. I removed the while command.&lt;br /&gt;2. I removed the logical operation on the ports.&lt;br /&gt;&lt;br /&gt;Let us understand which instruction gulped how many instruction cycles. So I tried the following code. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;//Example-5:&lt;br /&gt;#include "avr/io.h"        //Controller Specific Header File.&lt;br /&gt;//Start of Main - Entry into the program.&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;     DDRD = 0xFF;          //Direction of the PORTD0 Pin is set as Output.&lt;br /&gt;     while(1){&lt;br /&gt;          PORTD = 0x01;&lt;br /&gt;          PORTD = 0x00;&lt;br /&gt;          PORTD = 0x01;&lt;br /&gt;          PORTD = 0x00;&lt;br /&gt;     }&lt;br /&gt;     return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Following are the Output waveforms.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_9ZzqbeS_y-o/SifH89jQGdI/AAAAAAAAAOM/Zu658PBGEug/s1600-h/F0000TEK.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_9ZzqbeS_y-o/SifH89jQGdI/AAAAAAAAAOM/Zu658PBGEug/s320/F0000TEK.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343459333026879954" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_9ZzqbeS_y-o/SifIElrZjUI/AAAAAAAAAOU/ZlOQnjM_l8Q/s1600-h/F0008TEK.JPG"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_9ZzqbeS_y-o/SifIElrZjUI/AAAAAAAAAOU/ZlOQnjM_l8Q/s320/F0008TEK.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5343459464057556290" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Everything looks fine. An Article needs conclusion. It took me a long time to wrap things up. Here is the conclusion and reasoning of what every Example code meant. &lt;br /&gt;&lt;br /&gt;The controller is running at 8MHz. This means that each instruction takes 125 nanoseconds. &lt;br /&gt;&lt;br /&gt;Example-1:&lt;br /&gt;     In this code, we used a while loop, one OR operation, one AND operation and two assignment operations. A while loop takes two cycles, OR, AND and Assignment operation will take one cycle each. So totally there are 6 clock cycles used (2 for while loop + 1 for OR operation + 1 for AND operation + 2 for two Assignment Operation). Time taken would be 125 nanoseconds*6 = 750 nanoseconds. We are getting approximately 770 nanoseconds. Thus justified.&lt;br /&gt;Example-2:&lt;br /&gt;     In this code, we tried using a directive that came with AVRlib. Surprisingly the &lt;code&gt;sbi(), cbi()&lt;/code&gt; were also been implemented in the same way as previous one. Since they are &lt;code&gt;#define&lt;/code&gt; 's, they are being handled at the preprocessor level itself. Thus 770 nanoseconds. &lt;br /&gt;Example-3:&lt;br /&gt;     In this code, when we see from outside, it seems to be simple logical EXOR operations. But when we see this code carefully, it is different. Each logical EXOR will take two clock cycles. So to execute each while loop in this code, the controller will take 8 Clock Cycles (2 for while loop, 2 for each EXOR. So 4 Cycles and 2 Assignment). So 125 ns * 8 = 1000ns (~1.030 microSeconds).&lt;br /&gt;Example-4:&lt;br /&gt;     In this code, one assignment operation for making the GPIO logical one and one assignment operation for making the GPIO logical zero. So only two clock cycles are used. This leads to a maximum frequency which is 4MHz. Time taken will be 125ns*2=250ns (~256 ns). Thus justified.&lt;br /&gt;Example-5:&lt;br /&gt;     In this code, in addition to assignment operations, a while loop is also added. So time should be for this two pulses, it should take 256ns and for while loop, it will take two clock cycles (which is 512 ns).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you like this article and be able to appreciate this, dont forget to mail me your comments. my email id is "vbalaji[dot]acs[at]gmail[dot]com". Thanks for your patience.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-4431533622007486153?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ItKinCGcnrrf0YYx_9MPX8Q1tSc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ItKinCGcnrrf0YYx_9MPX8Q1tSc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ItKinCGcnrrf0YYx_9MPX8Q1tSc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ItKinCGcnrrf0YYx_9MPX8Q1tSc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/keFkIwBbY9s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/4431533622007486153/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=4431533622007486153&amp;isPopup=true" title="9 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4431533622007486153?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4431533622007486153?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/keFkIwBbY9s/cracking-myths-behind-microcontroller.html" title="Cracking the Myths Behind the Microcontroller Clock" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_9ZzqbeS_y-o/Sie_GzLQrqI/AAAAAAAAANM/tF-EDli6Gxc/s72-c/F0004TEK.JPG" height="72" width="72" /><thr:total>9</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2009/06/cracking-myths-behind-microcontroller.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUDRXY7eCp7ImA9WxVQF0k.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-2349015890794212513</id><published>2009-02-04T15:13:00.003+05:30</published><updated>2009-02-04T15:57:54.800+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-04T15:57:54.800+05:30</app:edited><title>Interesting C Program - 25</title><content type="html">Hi all,&lt;br /&gt;     I am here with a really interesting c program that I have developed today. It is a text based paint program. It uses ncurses library. Here goes the program.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/*&lt;br /&gt;------------TEXT BASED PAINT PROGRAM--------------&lt;br /&gt;*/&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#include "stdlib.h"&lt;br /&gt;#include "curses.h"&lt;br /&gt;int rmax,cmax;&lt;br /&gt;int crow,ccol;&lt;br /&gt;char drawchar = ' ';&lt;br /&gt;void moveup(void);&lt;br /&gt;void movedown(void);&lt;br /&gt;void moveleft(void);&lt;br /&gt;void moveright(void);&lt;br /&gt;void delcurrent(void);&lt;br /&gt;void bckspace(void);&lt;br /&gt;void delup(void);&lt;br /&gt;void toggledraw(void);&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; WINDOW *scrn;&lt;br /&gt; char key;&lt;br /&gt; //----------------------------------------&lt;br /&gt; printf("\n-----------------------------\n");&lt;br /&gt; printf("\n   Welcome to TextPaint\n");&lt;br /&gt; printf("\n       w - move up\n");&lt;br /&gt; printf("\n       a - move left\n");&lt;br /&gt; printf("\n       s - move down\n");&lt;br /&gt; printf("\n       d - move right\n");&lt;br /&gt; printf("\n       r - remove current character\n");&lt;br /&gt; printf("\n       b - remove character in the left\n");&lt;br /&gt; printf("\n       v - remove character in the top\n");&lt;br /&gt; printf("\n       t - toggle between moving and drawing\n");&lt;br /&gt; printf("\n-----------------------------\n");&lt;br /&gt; printf("\n Press ENTER Key to Continue\n");&lt;br /&gt; getchar();&lt;br /&gt; scrn = initscr();&lt;br /&gt; cbreak();&lt;br /&gt; noecho();&lt;br /&gt; getmaxyx(scrn,rmax,cmax);&lt;br /&gt; clear();&lt;br /&gt; refresh();&lt;br /&gt; crow = 0;&lt;br /&gt; ccol = 0;&lt;br /&gt; //----------------------------------------&lt;br /&gt; while(1)&lt;br /&gt; {&lt;br /&gt;  key = getch();&lt;br /&gt;  switch(key)&lt;br /&gt;  {&lt;br /&gt;   case 'w':&lt;br /&gt;    moveup(); &lt;br /&gt;   break;&lt;br /&gt;   case 'a':&lt;br /&gt;    moveleft();&lt;br /&gt;   break;&lt;br /&gt;   case 's':&lt;br /&gt;    movedown();&lt;br /&gt;   break;&lt;br /&gt;   case 'd':&lt;br /&gt;    moveright();&lt;br /&gt;   break;&lt;br /&gt;   case 'r':&lt;br /&gt;    delcurrent();&lt;br /&gt;   break;&lt;br /&gt;   case 'b':&lt;br /&gt;    bckspace(); &lt;br /&gt;   break;&lt;br /&gt;   case 'v':&lt;br /&gt;    delup();&lt;br /&gt;   break;&lt;br /&gt;   case 't':&lt;br /&gt;    toggledraw();&lt;br /&gt;   break;&lt;br /&gt;   default:&lt;br /&gt;    endwin();&lt;br /&gt;    printf("!!!You Have Come out of TextPaint!!!\n");&lt;br /&gt;    return 0;&lt;br /&gt;   break;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; endwin();&lt;br /&gt;&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void moveup(void)&lt;br /&gt;{&lt;br /&gt; crow--;&lt;br /&gt; if(crow&lt;0) &lt;br /&gt; {&lt;br /&gt;  crow = rmax;&lt;br /&gt; }&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; insch(drawchar);&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void movedown(void)&lt;br /&gt;{&lt;br /&gt; crow++;&lt;br /&gt; if(crow&gt;rmax)&lt;br /&gt;  crow = 0;&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; insch(drawchar);&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void moveleft(void)&lt;br /&gt;{&lt;br /&gt; ccol--;&lt;br /&gt; if(ccol&lt;0)&lt;br /&gt;  ccol = cmax;&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; insch(drawchar);&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void moveright(void)&lt;br /&gt;{&lt;br /&gt; ccol++;&lt;br /&gt; if(ccol&gt;cmax)&lt;br /&gt;  ccol = 0;&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; insch(drawchar);&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void delcurrent(void)&lt;br /&gt;{&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; //insch(' ');&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void bckspace(void)&lt;br /&gt;{&lt;br /&gt; ccol--;&lt;br /&gt; if(ccol&lt;0)&lt;br /&gt;  ccol = cmax;&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void delup(void)&lt;br /&gt;{&lt;br /&gt; crow--;&lt;br /&gt; if(crow&lt;0)&lt;br /&gt;  crow = rmax;&lt;br /&gt; move(crow,ccol);&lt;br /&gt; delch();&lt;br /&gt; refresh();&lt;br /&gt;}&lt;br /&gt;void toggledraw(void)&lt;br /&gt;{ &lt;br /&gt; static int i;&lt;br /&gt; i++;&lt;br /&gt; if(i%2)&lt;br /&gt;  drawchar = '-';&lt;br /&gt; else&lt;br /&gt;  drawchar = ' ';&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-2349015890794212513?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mmrrd0Gl4c-qTxJaxX9syKPgIh4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mmrrd0Gl4c-qTxJaxX9syKPgIh4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mmrrd0Gl4c-qTxJaxX9syKPgIh4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mmrrd0Gl4c-qTxJaxX9syKPgIh4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/JyhLvcnJ3kk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/2349015890794212513/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=2349015890794212513&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/2349015890794212513?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/2349015890794212513?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/JyhLvcnJ3kk/interesting-c-program-25.html" title="Interesting C Program - 25" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2009/02/interesting-c-program-25.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0YNRnc7fSp7ImA9WxVRE0o.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-4374188181356115827</id><published>2009-01-19T10:56:00.006+05:30</published><updated>2009-01-19T18:49:57.905+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-01-19T18:49:57.905+05:30</app:edited><title>Interesting Articles-1 Linux Filetypes</title><content type="html">Hi Readers,&lt;br /&gt;    This time we will understand the File types in Linux.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Linux File Types:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Regular files:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;As the name implies; used for data, executables programs, and anything else you might like. In an 'ls -l' listing, they show up with a '-' in the first character of the permission (mode) field.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Directories:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Special files for assiciating file names with inodes.  In an 'ls -l' listing they show up with a 'd' in the first character of permissions field.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Symbolic links:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;In an 'ls -l' listing, they show up with an 'l' in the first character of the permission field.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Devices&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;Files representing both physical hardware devices and software pseudo-devices. There are two kinds:&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Block Devices:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Devices on which I/O happens in chunks of some fixed physical record size such as disk drives and tape drives. Access to sch devices goes thruough the kernels buffer cache.  In an 'ls -l' listing, they show up with a 'b' in the first character of the permissions field.&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Character Devices:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Also known as raw devices.  Originally, character devices were those on which I/O happened a few bytes at a time, such as terminals.  However, the character device is also used for direct I/O to block devices such as tape drives and disk drives bypassing the buffer cache.    In an 'ls -l' listing, they show up with a 'c' in the first character of the permissions field.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Named Pipes:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Also known as FIFO files. These special files acts as pipes; data written into them by one program can be read by another; no data go to or from the disk. FIFOs are created with the mkfifo command.   In an 'ls -l' listing, they show up with a 'p' in the first character of the permissions field.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;&lt;span style="font-style:italic;"&gt;Sockets:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Similar in purpose to named pipes, they are managed with the socket interprocess communication (IPC) system calls.   In an 'ls -l' listing, they show up with a 's' in the first character of the permissions field.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-4374188181356115827?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-Mr_opeuKTtgzuwLo_pFaT5TBgo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Mr_opeuKTtgzuwLo_pFaT5TBgo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-Mr_opeuKTtgzuwLo_pFaT5TBgo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-Mr_opeuKTtgzuwLo_pFaT5TBgo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/SR2-KOybTOY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/4374188181356115827/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=4374188181356115827&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4374188181356115827?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4374188181356115827?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/SR2-KOybTOY/interesting-articles-1-linux-filetypes.html" title="Interesting Articles-1 Linux Filetypes" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2009/01/interesting-articles-1-linux-filetypes.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DU8CQHwzfyp7ImA9WxRbGE8.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-3334599308982752694</id><published>2008-12-09T15:31:00.004+05:30</published><updated>2008-12-09T18:34:21.287+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-09T18:34:21.287+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="LINUX SHELL" /><title>Interesting C Program -24</title><content type="html">Hi all,
&lt;br /&gt;     Here is the alpha version of the shell that I recently developed. This program runs fine in Linux. This shell will accept max 3 arguments.
&lt;br /&gt;
&lt;br /&gt;Here's the program:
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;#include "stdio.h"
&lt;br /&gt;#include "stdlib.h"
&lt;br /&gt;#include "unistd.h"
&lt;br /&gt;#include "sys/wait.h"
&lt;br /&gt;char InputData[100];
&lt;br /&gt;char Command[100];
&lt;br /&gt;char Parameter1[100];
&lt;br /&gt;char Parameter2[100];
&lt;br /&gt;unsigned int CommandLength = 0;
&lt;br /&gt;unsigned int Parameter1Length = 0;
&lt;br /&gt;unsigned int Parameter2Length = 0;
&lt;br /&gt;unsigned int i=0;
&lt;br /&gt;
&lt;br /&gt;void read_command(void);
&lt;br /&gt;
&lt;br /&gt;int main()
&lt;br /&gt;{
&lt;br /&gt;	int status;
&lt;br /&gt;	printf("[Balaji]&gt;");
&lt;br /&gt;	while(1)
&lt;br /&gt;	{
&lt;br /&gt;		read_command();
&lt;br /&gt;		if(fork()!=0)
&lt;br /&gt;		{
&lt;br /&gt;			//waitpid(-1,&amp;status,0);
&lt;br /&gt;			wait(&amp;status);
&lt;br /&gt;		}
&lt;br /&gt;		else
&lt;br /&gt;		{
&lt;br /&gt;			if((Parameter1[0] == '\0')&amp;&amp;(Parameter2[0]=='\0'))
&lt;br /&gt;			{
&lt;br /&gt;				execlp(Command,Command,'\0');
&lt;br /&gt;			}
&lt;br /&gt;			else if((Parameter1[0] != '\0')&amp;&amp;(Parameter2[0]=='\0'))
&lt;br /&gt;			{
&lt;br /&gt;				execlp(Command,Command,Parameter1,'\0');
&lt;br /&gt;			}
&lt;br /&gt;			else
&lt;br /&gt;			{
&lt;br /&gt;				execlp(Command,Command,Parameter1,Parameter2,'\0');
&lt;br /&gt;			}
&lt;br /&gt;		}
&lt;br /&gt;		printf("[Balaji]&gt;");
&lt;br /&gt;		for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;CommandLength;i++)
&lt;br /&gt;		{
&lt;br /&gt;			Command[i] = '\0';
&lt;br /&gt;		}
&lt;br /&gt;		for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;Parameter1Length;i++)
&lt;br /&gt;		{
&lt;br /&gt;			Parameter1[i] = '\0';
&lt;br /&gt;		}
&lt;br /&gt;		for(i=0;i&lt;Parameter2Length;i++)
&lt;br /&gt;		{
&lt;br /&gt;			Parameter2[i] = '\0';
&lt;br /&gt;		}
&lt;br /&gt;	}
&lt;br /&gt;}
&lt;br /&gt;void read_command(void)
&lt;br /&gt;{
&lt;br /&gt;	unsigned char ParameterStart = 0;
&lt;br /&gt;	gets(InputData);
&lt;br /&gt;	for(i=0;InputData[i]!='\0';i++)
&lt;br /&gt;	{
&lt;br /&gt;		if((InputData[i]!=' ')&amp;&amp;(ParameterStart==0))
&lt;br /&gt;		{
&lt;br /&gt;			Command[i]=InputData[i];
&lt;br /&gt;			CommandLength = i;
&lt;br /&gt;		}
&lt;br /&gt;		else if((InputData[i]==' ')&amp;&amp;(ParameterStart ==0))
&lt;br /&gt;		{
&lt;br /&gt;			Command[i]='\0';
&lt;br /&gt;			CommandLength=i;
&lt;br /&gt;			ParameterStart = 1;
&lt;br /&gt;		}
&lt;br /&gt;		else if((InputData[i]!=' ')&amp;&amp;(ParameterStart==1))
&lt;br /&gt;		{
&lt;br /&gt;			Parameter1[i-CommandLength-1] = InputData[i];
&lt;br /&gt;			Parameter1Length = i-CommandLength-1;
&lt;br /&gt;		}
&lt;br /&gt;		else if((InputData[i]==' ')&amp;&amp;(ParameterStart==1))
&lt;br /&gt;		{
&lt;br /&gt;			Parameter1[i-CommandLength] = '\0';
&lt;br /&gt;			Parameter1Length = (i-CommandLength);
&lt;br /&gt;			ParameterStart = 2;
&lt;br /&gt;		}
&lt;br /&gt;		else if((InputData[i]!=' ')&amp;&amp;(ParameterStart==2))
&lt;br /&gt;		{
&lt;br /&gt;			Parameter2[i-CommandLength-Parameter1Length-1] = InputData[i];
&lt;br /&gt;			Parameter2Length = i-CommandLength-Parameter1Length-1;
&lt;br /&gt;		}
&lt;br /&gt;		else if((InputData[i]==' ')&amp;&amp;(ParameterStart==1))
&lt;br /&gt;		{
&lt;br /&gt;			Parameter2[i-CommandLength-Parameter1Length] = '\0';
&lt;br /&gt;			Parameter2Length = (i-CommandLength-Parameter1Length);
&lt;br /&gt;			ParameterStart = 3;
&lt;br /&gt;		}
&lt;br /&gt;		
&lt;br /&gt;	}
&lt;br /&gt;	if((InputData[i]=='\0')&amp;&amp;(ParameterStart==0))
&lt;br /&gt;	{
&lt;br /&gt;		Parameter1[0] = '\0';
&lt;br /&gt;		Parameter2[0] = '\0';
&lt;br /&gt;		Parameter1Length = 1;
&lt;br /&gt;		Parameter2Length = 1;
&lt;br /&gt;	}
&lt;br /&gt;}
&lt;br /&gt;
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;&lt;code&gt;.
&lt;br /&gt;gcc -o balaji shell.c
&lt;br /&gt;./balaji
&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-3334599308982752694?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/2YH8-BympjrXbEVWQv7X3qZATTA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2YH8-BympjrXbEVWQv7X3qZATTA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/2YH8-BympjrXbEVWQv7X3qZATTA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/2YH8-BympjrXbEVWQv7X3qZATTA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/Yptry2SnyLA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/3334599308982752694/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=3334599308982752694&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/3334599308982752694?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/3334599308982752694?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/Yptry2SnyLA/interesting-c-program-23_09.html" title="Interesting C Program -24" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>3</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2008/12/interesting-c-program-23_09.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8FRnY5eSp7ImA9WxRbFUo.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-2622631130553664964</id><published>2008-12-06T20:00:00.005+05:30</published><updated>2008-12-06T20:16:57.821+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-06T20:16:57.821+05:30</app:edited><title>Interesting C Program -23</title><content type="html">Hi all,&lt;br /&gt;     Its long time since I updated my blog. This time, a real weird puzzle is here for you to solve.&lt;br /&gt;Observe the following program...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#include "stdlib.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; char data[20];&lt;br /&gt; printf("Type Something Here with spaces: ");&lt;br /&gt; scanf("%s",&amp;data);&lt;br /&gt; printf("%s",data);&lt;br /&gt; system("pause");&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;when I run the code, I asks us to type something with spaces.&lt;br /&gt;I typed "abcd efgh". &lt;br /&gt;Try to guess the output.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The output is just "abcd". &lt;br /&gt;&lt;br /&gt;Alas what happened to "efgh"!!!&lt;br /&gt;&lt;br /&gt;The answer is in scanf's implementation. &lt;br /&gt;&lt;br /&gt;It has been mentioned in  "&lt;span style="font-style:italic;"&gt;&lt;a href="http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html"&gt;http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html&lt;/a&gt;&lt;/span&gt;", that,&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;s&lt;br /&gt;Matches a sequence of bytes that are not white-space characters. The application                                                 shall ensure that the corresponding argument is a pointer to the initial byte of an array of char, signed char, or unsigned char large enough to accept the sequence and a terminating null character code, which shall be added automatically.&lt;span style="font-style:italic;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Isn't it weird?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-2622631130553664964?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/di2CG4cSO3M3DEyrQNKjnyltJUI/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/di2CG4cSO3M3DEyrQNKjnyltJUI/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/di2CG4cSO3M3DEyrQNKjnyltJUI/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/di2CG4cSO3M3DEyrQNKjnyltJUI/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/OTSejkCiqmU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/2622631130553664964/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=2622631130553664964&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/2622631130553664964?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/2622631130553664964?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/OTSejkCiqmU/interesting-c-program-23.html" title="Interesting C Program -23" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2008/12/interesting-c-program-23.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkQBQX88fyp7ImA9WxZQFEQ.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-7851905162967660739</id><published>2008-01-16T14:43:00.001+05:30</published><updated>2008-02-20T14:35:50.177+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-02-20T14:35:50.177+05:30</app:edited><title>Interesting C Program -22</title><content type="html">Hi all,&lt;br /&gt;     This month's LFY had an interesting C Program that caught my attention. Lets discuss that in detail.&lt;br /&gt;&lt;br /&gt;I have the following C Program.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; struct value&lt;br /&gt; {&lt;br /&gt;  int val:1;&lt;br /&gt; };&lt;br /&gt; struct value x;&lt;br /&gt; x.val = 1;&lt;br /&gt; printf("%d",x.val);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What could be the output of the following Program?&lt;br /&gt;&lt;br /&gt;I too thought that the output would be 1. But its not 1, but -1. Why?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The explanation goes like this.&lt;br /&gt;&lt;br /&gt;The structure member has been declared "int", which is "signed int"&lt;br /&gt;&lt;br /&gt;We all know that the MSB of a signed int will be the sign bit. If it is 1 then the number is negative and if it is zero the number is positive.&lt;br /&gt;&lt;br /&gt;Right, now my question is, if the val takes the MSB ie. in binary format 1000 0000 0000 0000, which should be a -0. If the val takes LSB ie. in binary format 0000 0000 0000 0000, which should return 1. Why is it printing -1?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The explanation goes like this.&lt;br /&gt;&lt;br /&gt;Any signed integer will be represented in its two's complement form. &lt;br /&gt;&lt;br /&gt;Try out the following program.&lt;br /&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#include "math.h"&lt;br /&gt;void func(int x);&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int x=-10;&lt;br /&gt; func(x);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;void func(int x)&lt;br /&gt;{&lt;br /&gt; unsigned char x1;&lt;br /&gt; signed int i;&lt;br /&gt; for(i=15;i&gt;=0;i--)&lt;br /&gt; {&lt;br /&gt;  x1 = ((x/(unsigned int)pow(2,i))%2)+0x30;&lt;br /&gt;  printf("%c",x1);&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This will print -10 in binary format.  If you look at it, you will get "1111111111110110", which is two's complement of 10.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So the output, 1000 0000, will be printed in two's complement form, which is 1000 0001. This is signed integer. So outputs -1 instead of 1.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-7851905162967660739?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/7ssolk5h8U3orctFk9t7-IBY7eU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7ssolk5h8U3orctFk9t7-IBY7eU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/7ssolk5h8U3orctFk9t7-IBY7eU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/7ssolk5h8U3orctFk9t7-IBY7eU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/Kh1poiZTbgA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/7851905162967660739/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=7851905162967660739&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/7851905162967660739?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/7851905162967660739?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/Kh1poiZTbgA/interesting-c-program-22.html" title="Interesting C Program -22" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2008/01/interesting-c-program-22.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcER3g7cCp7ImA9WB9UFUg.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-6030294067695731303</id><published>2007-12-13T17:56:00.000+05:30</published><updated>2007-12-13T19:23:26.608+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-12-13T19:23:26.608+05:30</app:edited><title>Interesting C Program -21</title><content type="html">My friend came to me with the following weird C puzzle.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int x = 5;&lt;br /&gt; printf("%f",x);&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;This program throws me the following warning:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;double format, different type arg (arg 2)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and the output is 0.000000&lt;br /&gt;&lt;br /&gt;What is this?&lt;br /&gt;His arguement was like this. Though my compiler allocates 4 bytes for both integer and float datatypes, why am I not being able to retrieve the same value if I interchange the types?&lt;br /&gt;&lt;br /&gt;Yes, very good question.&lt;br /&gt;&lt;br /&gt;The explanation goes like this.&lt;br /&gt;&lt;br /&gt;The data will be retrieved from a variable in the way it is stored. If you retrieve it in a way different from the way it is stored, you will not be able to get the same value you have stored.&lt;br /&gt;&lt;br /&gt;Lets be a bit more clear.&lt;br /&gt;&lt;br /&gt;I am going to show you how the variables are stored in the memory. &lt;br /&gt;&lt;br /&gt;Observe the following program.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;int x=800;&lt;br /&gt;int *x_int_ptr = &amp;x;&lt;br /&gt;unsigned char *x_char_ptr = (unsigned char *)x_int_ptr;&lt;br /&gt;printf("%x %x %x  %x",*(x_char_ptr+3),*(x_char_ptr+2),*(x_char_ptr+1),*(x_char_ptr));&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The output is 0 0 3 20&lt;br /&gt;&lt;br /&gt;What is this? &lt;br /&gt;Yes, the integer will be stored in the local memory like this. The equivalent of Integer Decimal 800 is Integer Binary 0b0000 0000 0000 0000 0000 0011 0010 0000. &lt;br /&gt;But a character can store only 8 bits. So the higher byte 0000 0011 is stored as 3 in the second LS byte of output and the lower byte 0010 0000 which is 20 is stored in the first LS byte.&lt;br /&gt;&lt;br /&gt;An integer 800 is stored like this.&lt;br /&gt;&lt;br /&gt;Lets see how a float is stored.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;float x=800;&lt;br /&gt;float *x_int_ptr = &amp;x;&lt;br /&gt;unsigned char *x_char_ptr = (unsigned char *)x_int_ptr;&lt;br /&gt;printf("%x %x %x %x",*(x_char_ptr+3),*(x_char_ptr+2),*(x_char_ptr+1),*(x_char_ptr));&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The ouput is 44 48 0 0&lt;br /&gt;&lt;br /&gt;If we retrieve this value like an integer, how can we expect a correct result?&lt;br /&gt;Let me justify the output 44 48 0 0.&lt;br /&gt;This storage in memory is based on IEEE754 standard.&lt;br /&gt;&lt;br /&gt;Just go the following link.&lt;br /&gt;http://babbage.cs.qc.edu/IEEE-754/32bit.html&lt;br /&gt;&lt;br /&gt;There you will find a calculator which takes this hex value as input and computes the decimal value that is given as input.&lt;br /&gt;&lt;br /&gt;Just type 44480000 in field adjacent to Hexadecimal Representation, and you will be seeing the 800 in the field adjacent to Decimal Value Entered:.&lt;br /&gt;&lt;br /&gt;So you need to be very careful while storing and retrieving data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Isnt this program weird?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-6030294067695731303?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pl1CitrkdelvJukJfWNZ2nOze14/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pl1CitrkdelvJukJfWNZ2nOze14/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pl1CitrkdelvJukJfWNZ2nOze14/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pl1CitrkdelvJukJfWNZ2nOze14/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/Izv4754rLgQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/6030294067695731303/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=6030294067695731303&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6030294067695731303?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6030294067695731303?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/Izv4754rLgQ/interesting-c-program-21.html" title="Interesting C Program -21" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/12/interesting-c-program-21.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQAQX06eyp7ImA9WB9UEkQ.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-4923906648581071369</id><published>2007-12-10T19:19:00.000+05:30</published><updated>2007-12-10T20:05:40.313+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-12-10T20:05:40.313+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -20</title><content type="html">Today, when I was studying about preprocessing stuff in C Programs, I thought of trying out something different.  I wrote the following C program.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#define a #include"stdio.h"&lt;br /&gt;#define b main()&lt;br /&gt;#define c {&lt;br /&gt;#define d printf("hello world\n");&lt;br /&gt;#define e }&lt;br /&gt;a&lt;br /&gt;b&lt;br /&gt;c&lt;br /&gt;d&lt;br /&gt;e&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Will it work?&lt;br /&gt;&lt;br /&gt;No. It didnt worked!!!&lt;br /&gt;&lt;br /&gt;I got the following error.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;syntax error at '#' token&lt;br /&gt;syntax error before string constant&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;What exactly could be the reason?&lt;br /&gt;&lt;br /&gt;Lets analyse it step by step, from the DOS prompt. The following steps will work only when your path variables are correct. In order to correct them you must tweak in the Environment variables.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First lets just preprocess it. &lt;br /&gt;&lt;br /&gt;Type the following command in the DOS Prompt&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;gcc -E main.c&gt;main.i&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The output of preprocessing has been redirected to the main.i.&lt;br /&gt;&lt;br /&gt;When I opened main.i, I found the following.&lt;br /&gt;----------main.i file starts here---------------------&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# 1 "src\\main.c"&lt;br /&gt;# 1 "&lt;built-in&gt;"&lt;br /&gt;# 1 "&lt;command line&gt;"&lt;br /&gt;# 1 "src\\main.c"&lt;br /&gt;# 58 "src\\main.c"&lt;br /&gt; #include"stdio.h"&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;printf("hello world\n");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;----------main.i file ends here-----------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hurray!!! I found out the problem.&lt;br /&gt;After preprocessing, all the #defines has been replaced by their respective counter parts. But the only #include remains as it is. It didnot get replaced by the #include "stdio.h" file. This is causing the error.&lt;br /&gt;&lt;br /&gt;Now let me make some modifications. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#define b main()&lt;br /&gt;#define c {&lt;br /&gt;#define d printf("hello world\n");&lt;br /&gt;#define e }&lt;br /&gt;#include "stdio.h"&lt;br /&gt;b&lt;br /&gt;c&lt;br /&gt;d&lt;br /&gt;e&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now it is compiling.&lt;br /&gt;&lt;br /&gt;Is it correct? Lets check it out.&lt;br /&gt;&lt;br /&gt;Now run the same command&lt;br /&gt;&lt;code&gt;&lt;br /&gt;gcc -E main.c&gt;main.i&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Observe the main.i file&lt;br /&gt;My god, I am getting a very big main.i file.&lt;br /&gt;&lt;br /&gt;If you see that file, the stdio.h file has been pasted there.&lt;br /&gt;&lt;br /&gt;The conclusion is that the input to a compiler should not have #'s in the code. All #'s should be removed at the preprocessing stage itself.&lt;br /&gt;&lt;br /&gt;A compiler doesnot know #.&lt;br /&gt;&lt;br /&gt;Isnt this program weird? ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-4923906648581071369?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/KMAdQ9ydVXYXUgjz6lsk5U5yqCk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KMAdQ9ydVXYXUgjz6lsk5U5yqCk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/KMAdQ9ydVXYXUgjz6lsk5U5yqCk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/KMAdQ9ydVXYXUgjz6lsk5U5yqCk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/XU3R-D31Rmw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/4923906648581071369/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=4923906648581071369&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4923906648581071369?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4923906648581071369?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/XU3R-D31Rmw/interesting-c-program-20.html" title="Interesting C Program -20" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/12/interesting-c-program-20.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUDQHk7eip7ImA9WB9UEkQ.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-1449061045074149225</id><published>2007-12-05T11:16:00.000+05:30</published><updated>2007-12-10T19:47:51.702+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-12-10T19:47:51.702+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -19</title><content type="html">Hey,&lt;br /&gt;    Its long since my last post. I am here, with a very unique program.&lt;br /&gt;&lt;br /&gt;Observe the output of the following C program&lt;br /&gt;CASE:1&lt;br /&gt;&lt;code&gt;&lt;br /&gt;void func(void);&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    if(0)&lt;br /&gt;         func();    &lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Does this compile? (Yes/No).  The answer depends on the compiler you are using. In some compilers this will compile without any errors. How come? "func()" is not defined anywhere. How come it is running?&lt;br /&gt;&lt;br /&gt;Some smart compilers have that intelligence to compile such codes. This program runs, because "if(0)" is never going to be true. So the statement that follows is will never be executed. So, it dont even bother to search where the "func" function has been defined.&lt;br /&gt;&lt;br /&gt;Ok, lets play around with the same program. Try out the following program.&lt;br /&gt;CASE:2&lt;br /&gt;void func(void);&lt;br /&gt;int x = 0;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    if(x)&lt;br /&gt;         func();    &lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Alas! this is throws the following errors.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Compiling source file(s)...&lt;br /&gt;file_2.c&lt;br /&gt;Linking...&lt;br /&gt;C:\Documents and Settings\Administrator\Desktop\CTIPS\my_proj\Debug\file_2.o(.text+0x28): In function `main':&lt;br /&gt;C:\Documents and Settings\Administrator\Desktop\CTIPS\my_proj\file_2.c:65: undefined reference to `func'&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Why the hell it is throwing linker errors? &lt;br /&gt;&lt;br /&gt;Lets do some more modifications and try.&lt;br /&gt;&lt;br /&gt;Try out the following program.&lt;br /&gt;CASE:3&lt;br /&gt;&lt;code&gt;&lt;br /&gt;void func(void);&lt;br /&gt;const int x = 0;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    if(x)&lt;br /&gt;         func();    &lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Again this throws the same error.&lt;br /&gt;Is there any way of running this program?&lt;br /&gt;Yes, there are ways.&lt;br /&gt;&lt;br /&gt;There is a small tweaking you need to do in the compiler settings.&lt;br /&gt;&lt;br /&gt;Lets try out that.&lt;br /&gt;&lt;br /&gt;I am using MingWStudio. Try out similar things in your compiler or the Makefile.&lt;br /&gt;&lt;br /&gt;1. Go to Project-&gt;Settings.&lt;br /&gt;2. Go to Compile tab&lt;br /&gt;3. By default the Optimization level will be None.&lt;br /&gt;4. Change the Optimization to Level 1 or Level 2 or Level 3 or Minimum Size.&lt;br /&gt;5. Give OK.&lt;br /&gt;CASE:4&lt;br /&gt;Now Clean the program to remove some previous configuration and then build. &lt;br /&gt;&lt;br /&gt;This will definitely run.&lt;br /&gt;&lt;br /&gt;The explanation goes like this.&lt;br /&gt;In CASE:1, since mine is a smart compiler, this will be compiled without any errors.&lt;br /&gt;I am working on CASE:2, CASE:3 and CASE:4.&lt;br /&gt;&lt;br /&gt;Meanwhile if somebody knows why CASE:2 and CASE:3 didnt work and CASE:4 worked, please do comment me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-1449061045074149225?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/igVezD534SQu1OEg2VUMziveMCg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/igVezD534SQu1OEg2VUMziveMCg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/igVezD534SQu1OEg2VUMziveMCg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/igVezD534SQu1OEg2VUMziveMCg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/tWYFrFRvkdQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/1449061045074149225/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=1449061045074149225&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/1449061045074149225?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/1449061045074149225?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/tWYFrFRvkdQ/interesting-c-program-19.html" title="Interesting C Program -19" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/12/interesting-c-program-19.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUECQ344fip7ImA9WB9WEEw.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-3725735550246090397</id><published>2007-11-02T10:58:00.000+05:30</published><updated>2007-11-14T10:51:02.036+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-14T10:51:02.036+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SORTING ALGORITHMS" /><title>Sorting Algorithm - 2 (Shaker Sort)</title><content type="html">A slightly improved version of BUBBLE SORTING. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void shaker_sort(char *str,int count)&lt;br /&gt;{&lt;br /&gt; int i,exchange=0;&lt;br /&gt; do{&lt;br /&gt;  exchange = 0;&lt;br /&gt;  for(i=1;i&lt;code&gt;&lt;&lt;/code&gt;count-1;i++)&lt;br /&gt;  {&lt;br /&gt;   if(str[i]&gt;str[i+1])&lt;br /&gt;   {&lt;br /&gt;    exchange = 1;&lt;br /&gt;    swap_items(&amp;str[i],&amp;str[i+1]);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;  for(i=count-1;i&gt;0;i--)&lt;br /&gt;  {&lt;br /&gt;   if(str[i-1]&gt;str[i])&lt;br /&gt;   {&lt;br /&gt;    exchange = 1;&lt;br /&gt;    swap_items(&amp;str[i-1],&amp;str[i]);&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }while(exchange);&lt;br /&gt;}&lt;br /&gt;void swap_items(char *a,char *b)&lt;br /&gt;{&lt;br /&gt; (*a)^=(*b)^=(*a)^=(*b);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-3725735550246090397?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZXFl1puIbyvLKbfxO8kd7RNRS1M/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZXFl1puIbyvLKbfxO8kd7RNRS1M/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZXFl1puIbyvLKbfxO8kd7RNRS1M/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZXFl1puIbyvLKbfxO8kd7RNRS1M/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/33Yhti-R30k" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/3725735550246090397/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=3725735550246090397&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/3725735550246090397?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/3725735550246090397?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/33Yhti-R30k/void-shakersortchar-strint-count-int.html" title="Sorting Algorithm - 2 (Shaker Sort)" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/11/void-shakersortchar-strint-count-int.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUAERnk-eSp7ImA9WB9WEEw.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-1085969309130250720</id><published>2007-11-02T10:24:00.000+05:30</published><updated>2007-11-14T10:51:47.751+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-14T10:51:47.751+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="SORTING ALGORITHMS" /><title>Sorting Algorithm - 1 (BUBBLE SORT)</title><content type="html">A very primitive, simple and Well known Sorting algorithm.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void bubble_sort(char *str, int count)&lt;br /&gt;{&lt;br /&gt;     int i,j;&lt;br /&gt;     for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;count;i++)&lt;br /&gt;     {&lt;br /&gt;          for(j=count-1;j&gt;i;j++)&lt;br /&gt;          {&lt;br /&gt;               if(str[j-1]&gt;str[j])&lt;br /&gt;               {&lt;br /&gt;                    swap_terms(&amp;str[i],&amp;str[j]);&lt;br /&gt;               }&lt;br /&gt;          }&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void swap_terms(char *a,char *b)&lt;br /&gt;{&lt;br /&gt;     (*a)^=(*b)^=(*a)^=(*b);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-1085969309130250720?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/B971yKjkwiG5lQIO7Ynpmgxs0wo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/B971yKjkwiG5lQIO7Ynpmgxs0wo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/B971yKjkwiG5lQIO7Ynpmgxs0wo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/B971yKjkwiG5lQIO7Ynpmgxs0wo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/03b7nE2FEVA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/1085969309130250720/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=1085969309130250720&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/1085969309130250720?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/1085969309130250720?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/03b7nE2FEVA/sorting-algorithm-1-bubble-sort.html" title="Sorting Algorithm - 1 (BUBBLE SORT)" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/11/sorting-algorithm-1-bubble-sort.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YNSHY-fSp7ImA9WB9XEUk.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-8230063294152599153</id><published>2007-10-29T12:17:00.000+05:30</published><updated>2007-11-04T08:29:59.855+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-04T08:29:59.855+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -18</title><content type="html">Hi all,&lt;br /&gt;     Observe the output of the following program.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#define DPRINTI(X) printf("\n%s = %d \n",#X,X)&lt;br /&gt;#define DPRINTF(X) printf("\n%s = %f\n",#X,X)&lt;br /&gt;#define DPRINTC(X) printf("\n%s = %c\n",#X,X)&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;double x = 100.1;&lt;br /&gt;int y = 5;&lt;br /&gt;char z = 'a';&lt;br /&gt;void *p;&lt;br /&gt;&lt;br /&gt;p = &amp;z;&lt;br /&gt;DPRINTI(sizeof(*(char *)p));&lt;br /&gt;DPRINTC(*(char *)p);&lt;br /&gt;DPRINTI(p);&lt;br /&gt;&lt;br /&gt;p = &amp;y;&lt;br /&gt;DPRINTI(sizeof(*(int *)p));&lt;br /&gt;DPRINTI(*(int *)p);&lt;br /&gt;DPRINTI(p);&lt;br /&gt;&lt;br /&gt;p = &amp;x;&lt;br /&gt;DPRINTI(sizeof(*(double *)p));&lt;br /&gt;DPRINTF(*(double *)p);&lt;br /&gt;DPRINTI(p);&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The output is something like the following:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;sizeof(*(char *)p) = 1&lt;br /&gt;&lt;br /&gt;*(char *)p = a&lt;br /&gt;&lt;br /&gt;p = 2293635&lt;br /&gt;&lt;br /&gt;sizeof(*(int *)p) = 4&lt;br /&gt;&lt;br /&gt;*(int *)p = 5&lt;br /&gt;&lt;br /&gt;p = 2293636&lt;br /&gt;&lt;br /&gt;sizeof(*(float *)p) = 8&lt;br /&gt;&lt;br /&gt;*(double *)p = 100.100000&lt;br /&gt;&lt;br /&gt;p = 2293640&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Explanation goes like this.&lt;br /&gt;&lt;br /&gt;Initially a pointer has been initialized of type void * (generic pointer).  We are type casting that pointer p to point a location in which a character is stored. Then we are typecasting that pointer p to point a location in which an integer is stored. Later, we are again type casting that pointer p to point a location in which a float is stored. This program runs without any errors. &lt;br /&gt;The character variable is stored in 2293635 location (Size is 1 byte), ie 2293635.&lt;br /&gt;The Integer variable is stored in 2293636 location (Size is 4 bytes), ie 2293636, 2293637, 2293638 and 2293639.&lt;br /&gt;The Float variable is stored in 2293640 location (Size is 8 bytes), ie 2293640, 2293641, 2293642, 2293643, 2293644, 2293645, 2293646 and 2293647.&lt;br /&gt;Every thing seems simple.&lt;br /&gt;&lt;br /&gt;Hey wait wait. How can Life be so simple?&lt;br /&gt;&lt;br /&gt;Lets see what happens when the following code is executed?&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#define DPRINTI(X) printf("\n%s = %d \n",#X,X)&lt;br /&gt;#define DPRINTF(X) printf("\n%s = %f\n",#X,X)&lt;br /&gt;#define DPRINTC(X) printf("\n%s = %c\n",#X,X)&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;double x = 100.1;&lt;br /&gt;int y = 5;&lt;br /&gt;char z = 'a';&lt;br /&gt;void *p;&lt;br /&gt;&lt;br /&gt;p = &amp;x;&lt;br /&gt;DPRINTI(sizeof(*(double *)p));&lt;br /&gt;DPRINTF(*(double *)p);&lt;br /&gt;DPRINTI(p);&lt;br /&gt;&lt;br /&gt;p = &amp;y;&lt;br /&gt;DPRINTI(sizeof(*(int *)p));&lt;br /&gt;DPRINTI(*(int *)p);&lt;br /&gt;DPRINTI(p);&lt;br /&gt;&lt;br /&gt;p = &amp;z;&lt;br /&gt;DPRINTI(sizeof(*(char *)p));&lt;br /&gt;DPRINTC(*(char *)p);&lt;br /&gt;DPRINTI(p);&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The output is something like this:&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The output is something like the following:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;sizeof(*(float *)p) = 8&lt;br /&gt;&lt;br /&gt;*(double *)p = 100.100000&lt;br /&gt;&lt;br /&gt;p = 2293640&lt;br /&gt;&lt;br /&gt;sizeof(*(int *)p) = 4&lt;br /&gt;&lt;br /&gt;*(int *)p = 5&lt;br /&gt;&lt;br /&gt;p = 2293636&lt;br /&gt;&lt;br /&gt;sizeof(*(char *)p) = 1&lt;br /&gt;&lt;br /&gt;*(char *)p = a&lt;br /&gt;&lt;br /&gt;p = 2293635&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Dont you see something weird in the output?&lt;br /&gt;&lt;br /&gt;The addresses of float, int, and char should be respectively,2293635, 2293643 and 2293647. ie. the starting address should be 2293635. From there float occupies 8 bytes. The next 4 bytes is occupied by Integer (2293643, 2293644,2293645 and 2293646 and the next 1 byte is occupied by character variable, which is 2293647. &lt;br /&gt;But that is not happening.&lt;br /&gt;&lt;br /&gt;Can anybody comment me with the reason for that?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-8230063294152599153?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4yUG4ANeG9THXPK4eTZEpNlExqc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4yUG4ANeG9THXPK4eTZEpNlExqc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4yUG4ANeG9THXPK4eTZEpNlExqc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4yUG4ANeG9THXPK4eTZEpNlExqc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/C8HP7MNfFZA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/8230063294152599153/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=8230063294152599153&amp;isPopup=true" title="4 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/8230063294152599153?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/8230063294152599153?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/C8HP7MNfFZA/interesting-c-program-18.html" title="Interesting C Program -18" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>4</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/10/interesting-c-program-18.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEMBQHg_fCp7ImA9WB9XFEw.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-6228610748108758977</id><published>2007-10-24T19:45:00.001+05:30</published><updated>2007-11-07T10:44:11.644+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-07T10:44:11.644+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -17</title><content type="html">Hey!!!&lt;br /&gt;This code converts the decimal number into binary, decimal, octal and hexadecimal number systems. Here "pow()" function is used. Since pow() function returns float, the values are typecasted. &lt;br /&gt;Note: Never use a^b for "a raised to the power of b". This will do the EXOR operation.&lt;br /&gt;Try using pow(base,power) function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#include "math.h"&lt;br /&gt;/*----------#defines starts here----------*/&lt;br /&gt;#define DECIMAL 10&lt;br /&gt;#define BINARY 2&lt;br /&gt;#define OCTAL 8&lt;br /&gt;#define HEXADECIMAL 16&lt;br /&gt;#define DIGITS_DECIMAL 5&lt;br /&gt;#define DIGITS_BINARY 16&lt;br /&gt;#define DIGITS_OCTAL 3&lt;br /&gt;#define DIGITS_HEXADECIMAL 3&lt;br /&gt;/*-----------#defines ends here-----------*/&lt;br /&gt;/*   FUNCTION DECLARATIONS STARTS HERE    */&lt;br /&gt;char *tobinary(int x);&lt;br /&gt;char *todecimal(int x);&lt;br /&gt;char *tooctal(int x);&lt;br /&gt;char *tohexadecimal(int x);&lt;br /&gt;/*    FUNCTION DECLARATIONS ENDS HERE    */&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int x;&lt;br /&gt; char *y;&lt;br /&gt; printf("ENTER THE VALUE TO CONVERT:\t\t");&lt;br /&gt; scanf("%d",&amp;x);&lt;br /&gt; y=tobinary(x);&lt;br /&gt; printf("\nBINARY:\t\t%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c"\&lt;br /&gt; ,y[0],y[1],y[2],y[3],y[4],y[5],y[6],y[7],y[8],y[9],y[10],\&lt;br /&gt; y[11],y[12],y[13],y[14],y[15]);&lt;br /&gt; y=todecimal(x);&lt;br /&gt; printf("\nDECIMAL:\t%c %c %c %c %c",y[0],y[1],y[2],y[3],y[4]);&lt;br /&gt; y=tooctal(x);&lt;br /&gt; printf("\nOCTAL:\t\t%c %c %c",y[0],y[1],y[2]);&lt;br /&gt; y=tohexadecimal(x);&lt;br /&gt; printf("\nHEXADECIMAL:\t%c %c %c",y[0],y[1],y[2]);&lt;br /&gt; &lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;/*   FUNCTION DEFINITIONS STARTS HERE    */&lt;br /&gt;char *todecimal(int x)&lt;br /&gt;{&lt;br /&gt; char y[3];&lt;br /&gt; int i;&lt;br /&gt; for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;DIGITS_DECIMAL;i++)&lt;br /&gt; {&lt;br /&gt;  y[i] = ((x/(int)pow(DECIMAL,(DIGITS_DECIMAL-i-1)))%DECIMAL)+0x30;&lt;br /&gt; }&lt;br /&gt; return y; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;char *tobinary(int x)&lt;br /&gt;{&lt;br /&gt; char y[8];&lt;br /&gt; int i;&lt;br /&gt; for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;DIGITS_BINARY;i++)&lt;br /&gt; {&lt;br /&gt;  y[i] = ((x/(int)pow(BINARY,(DIGITS_BINARY-i-1)))%BINARY)+0x30;&lt;br /&gt; }&lt;br /&gt; return y; &lt;br /&gt;}&lt;br /&gt;char *tooctal(int x)&lt;br /&gt;{&lt;br /&gt; char y[3];&lt;br /&gt; int i;&lt;br /&gt; for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;DIGITS_OCTAL;i++)&lt;br /&gt; {&lt;br /&gt;  y[i] = ((x/(int)pow(OCTAL,(DIGITS_OCTAL-i-1)))%OCTAL)+0x30;&lt;br /&gt; }&lt;br /&gt; return y; &lt;br /&gt;}&lt;br /&gt;char *tohexadecimal(int x)&lt;br /&gt;{&lt;br /&gt; char y[3];&lt;br /&gt; int i;&lt;br /&gt; for(i=0;i&lt;code&gt;&lt;&lt;/code&gt;DIGITS_HEXADECIMAL;i++)&lt;br /&gt; {&lt;br /&gt;  y[i] = ((x/(int)pow(HEXADECIMAL,(DIGITS_HEXADECIMAL-i-1)))%HEXADECIMAL)+0x30;&lt;br /&gt;  if(y[i]==0x3A) y[i] =0x41;&lt;br /&gt;  if(y[i]==0x3B) y[i] =0x42;&lt;br /&gt;  if(y[i]==0x3C) y[i] =0x43;&lt;br /&gt;  if(y[i]==0x3D) y[i] =0x44;&lt;br /&gt;  if(y[i]==0x3E) y[i] =0x45;&lt;br /&gt;  if(y[i]==0x3F) y[i] =0x46;&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; return y; &lt;br /&gt;}&lt;br /&gt;/*     FUNCTION DEFINITIONS ENDS HERE      */&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-6228610748108758977?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9L6koMNBvDK4qnvbQI7iJyVmBBQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9L6koMNBvDK4qnvbQI7iJyVmBBQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9L6koMNBvDK4qnvbQI7iJyVmBBQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9L6koMNBvDK4qnvbQI7iJyVmBBQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/gcez6xu73Vg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/6228610748108758977/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=6228610748108758977&amp;isPopup=true" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6228610748108758977?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/6228610748108758977?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/gcez6xu73Vg/interesting-c-program-17.html" title="Interesting C Program -17" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>2</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/10/interesting-c-program-17.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eCp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-461943674350087973</id><published>2007-08-20T10:42:00.000+05:30</published><updated>2007-11-02T12:40:08.600+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.600+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -16</title><content type="html">Can u write a C program to swap two integers that does not use a temporary variable (or that uses only two variables to be swapped)?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here goes an implementation:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int a=1,b=3;&lt;br /&gt; printf("BEFORE SWAPPING : a=%d &amp; b=%d\n",a,b);&lt;br /&gt; a^=b^=a^=b;&lt;br /&gt; printf("AFTER SWAPPING : a=%d &amp; b=%d\n",a,b);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The output looks something like this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;BEFORE SWAPPING : a=1 &amp; b = 3&lt;br /&gt;AFTER SWAPPING : a=3 &amp; b = 1&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Looks good isn't it?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-461943674350087973?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WIJmkuV5VSvrTZv-bxhW-pu7Ei4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WIJmkuV5VSvrTZv-bxhW-pu7Ei4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WIJmkuV5VSvrTZv-bxhW-pu7Ei4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WIJmkuV5VSvrTZv-bxhW-pu7Ei4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/lBX2N1XOrQg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/461943674350087973/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=461943674350087973&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/461943674350087973?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/461943674350087973?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/lBX2N1XOrQg/interesting-c-programs-16.html" title="Interesting C Program -16" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/08/interesting-c-programs-16.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eCp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-924400693643130992</id><published>2007-08-19T19:51:00.000+05:30</published><updated>2007-11-02T12:40:08.600+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.600+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -15</title><content type="html">Atlast, Here is my implementation of Pascal Triangle!!!&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/*PASCAL TRIANGLE*/&lt;br /&gt;#include"stdio.h"&lt;br /&gt;int factorial(int);&lt;br /&gt;int combination(int,int);&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int rows,i,j;&lt;br /&gt; printf("ENTER THE NUMBER OF ROWS:\t");&lt;br /&gt; scanf("%d",&amp;rows);&lt;br /&gt; printf("\n---------------------------------------------------------\&lt;br /&gt;------------------\n");&lt;br /&gt; printf("                         PASCAL TRIANGLE WITH %d ROWS                     \   ",rows);&lt;br /&gt; printf("\n-----------------------------------------------------------\&lt;br /&gt;----------------\n");&lt;br /&gt; for(i=1;i&lt;=rows;i++)&lt;br /&gt; {&lt;br /&gt;  for(j=0;j&lt;=i;j++)&lt;br /&gt;  {&lt;br /&gt;   printf("%d\t",combination(i,j));&lt;br /&gt;  }&lt;br /&gt;  //printf("\n");&lt;br /&gt;  printf("\n---------------------------------------------------------------\&lt;br /&gt;------------\n");&lt;br /&gt; } &lt;br /&gt;}&lt;br /&gt;int factorial(int x)&lt;br /&gt;{&lt;br /&gt; if(x&lt;2)&lt;br /&gt;  return 1;&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt;  return x*factorial(x-1);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;int combination(int n,int r)&lt;br /&gt;{&lt;br /&gt; int y;&lt;br /&gt; y=factorial(n)/(factorial(r)*factorial(n-r));&lt;br /&gt; return y;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The Output looks like this&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ENTER THE NUMBER OF ROWS:       5&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;                         PASCAL TRIANGLE WITH 5 ROWS&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;1       1&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;1       2       1&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;1       3       3       1&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;1       4       6       4       1&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;1       5       10      10      5       1&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-924400693643130992?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/4r62qAIIyE9y9aFnX2bfhO-Vams/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4r62qAIIyE9y9aFnX2bfhO-Vams/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/4r62qAIIyE9y9aFnX2bfhO-Vams/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/4r62qAIIyE9y9aFnX2bfhO-Vams/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/7ELy0Rhgy24" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/924400693643130992/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=924400693643130992&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/924400693643130992?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/924400693643130992?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/7ELy0Rhgy24/interesting-c-program-15.html" title="Interesting C Program -15" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/08/interesting-c-program-15.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eCp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-1305534002330432712</id><published>2007-08-02T09:07:00.001+05:30</published><updated>2007-11-02T12:40:08.600+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.600+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -14</title><content type="html">Just see the output of the following C program. The output looks bit weird. Isnt it?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#define DPRINTF(x) printf("%s = %d\n",#x,x);&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int x[20];&lt;br /&gt; int *p,*q;&lt;br /&gt; p=&amp;x[5];&lt;br /&gt; q=&amp;x[9];&lt;br /&gt; DPRINTF(p);&lt;br /&gt; DPRINTF(q);&lt;br /&gt; DPRINTF(q-p);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The output is &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;p = 2293580&lt;br /&gt;q = 2293596&lt;br /&gt;q-p = 4&lt;br /&gt;&lt;br /&gt;q-p should be 16. But it gives 4. why?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The explanation goes like this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Lets take a real life example.&lt;br /&gt;&lt;br /&gt;Say you took 9 dozens of apples. You returned 5 dozens of apples. Then how many dozens of apples do you have? 4 dozens isnt it? You will not say 48 apples. &lt;br /&gt;&lt;br /&gt;Similar is the case here. x[9] is stored in 2293596 address location and x[5] is stored in 2293580. p and q are integer pointers, each occupying 4 bytes. Now when you  display the value of p and q, they will be 2293580 and 2293596 respectively. But if you ask for difference, it will be 4. &lt;br /&gt;Inshort, 9 integer pointers - 5 integer pointers = 4 integer pointers.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now just try this program:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#define DPRINTF(x) printf("%s = %d\n",#x,x);&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int x[20],y,z;&lt;br /&gt; int *p,*q;&lt;br /&gt; p=&amp;x[5];&lt;br /&gt; q=&amp;x[9];&lt;br /&gt; DPRINTF(p);&lt;br /&gt; DPRINTF(q);&lt;br /&gt; DPRINTF(q-p);&lt;br /&gt; y = p;&lt;br /&gt; z = q;&lt;br /&gt; DPRINTF(y);&lt;br /&gt; DPRINTF(z);&lt;br /&gt; DPRINTF(z-y);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The output is like this:&lt;br /&gt;&lt;br /&gt;p = 2293580&lt;br /&gt;q = 2293596&lt;br /&gt;q-p = 4&lt;br /&gt;y = 2293580&lt;br /&gt;z = 2293596&lt;br /&gt;z-y = 16&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If you see the difference between z and y, you will get 16.&lt;br /&gt;&lt;br /&gt;I think now no explanation is required now.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-1305534002330432712?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/NLgHU9NxXGo_FF2VEx0Wl-sHX_U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NLgHU9NxXGo_FF2VEx0Wl-sHX_U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/NLgHU9NxXGo_FF2VEx0Wl-sHX_U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/NLgHU9NxXGo_FF2VEx0Wl-sHX_U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/2U8cY3hCA9M" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/1305534002330432712/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=1305534002330432712&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/1305534002330432712?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/1305534002330432712?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/2U8cY3hCA9M/interesting-c-program-14.html" title="Interesting C Program -14" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/08/interesting-c-program-14.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eCp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-2178600669890689790</id><published>2007-08-02T08:41:00.001+05:30</published><updated>2007-11-02T12:40:08.600+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.600+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -13</title><content type="html">Hey!!! Now u can change the color of the output window (DOS window). How?&lt;br /&gt;&lt;br /&gt;Just try the following program:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;#include "string.h"&lt;br /&gt;#include "stdlib.h"&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;int i=0;&lt;br /&gt;for(i = 0;i&lt;3;i++)&lt;br /&gt;{&lt;br /&gt;char x[] = "color ";&lt;br /&gt;(i==0)?strcat(x,"0F"):((i==1)?strcat(x,"1E"):((i==2)?strcat(x,"2D")\&lt;br /&gt;:strcat(x,"3C")));&lt;br /&gt;system(x);&lt;br /&gt;system("pause");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Your output window looks colorful right?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-2178600669890689790?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uVopxcI9QK-qhQxQ6cGWqC3fmvs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uVopxcI9QK-qhQxQ6cGWqC3fmvs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uVopxcI9QK-qhQxQ6cGWqC3fmvs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uVopxcI9QK-qhQxQ6cGWqC3fmvs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/3KjMvFohboo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/2178600669890689790/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=2178600669890689790&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/2178600669890689790?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/2178600669890689790?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/3KjMvFohboo/interesting-c-programs-13.html" title="Interesting C Program -13" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/08/interesting-c-programs-13.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eSp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-5933168764728137252</id><published>2007-08-02T08:34:00.000+05:30</published><updated>2007-11-02T12:40:08.601+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.601+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -12</title><content type="html">Can you write a simple "Hello World" Program that doesnot use semicolon?&lt;br /&gt;Here is an implementation!!!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;      if(printf("Hello World")){}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-5933168764728137252?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/jhqXcDNRL27IYCBJvZwDIONX34I/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jhqXcDNRL27IYCBJvZwDIONX34I/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/jhqXcDNRL27IYCBJvZwDIONX34I/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/jhqXcDNRL27IYCBJvZwDIONX34I/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/Df5-DwiSGlI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/5933168764728137252/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=5933168764728137252&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/5933168764728137252?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/5933168764728137252?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/Df5-DwiSGlI/can-you-write-simple-hello-world.html" title="Interesting C Program -12" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/08/can-you-write-simple-hello-world.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eSp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-7510987646864709643</id><published>2007-07-13T17:02:00.000+05:30</published><updated>2007-11-02T12:40:08.601+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.601+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -11</title><content type="html">Want to know my name?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;char a[5][6] =  { &lt;br /&gt;     {0xe,0x6,0x8,0x6,0x7,0xe},&lt;br /&gt;     {0x9,0x9,0x8,0x9,0x2,0x4},&lt;br /&gt;     {0xe,0xf,0x8,0xf,0x2,0x4},&lt;br /&gt;     {0x9,0x9,0x8,0x9,0xa,0x4},&lt;br /&gt;     {0xe,0x9,0xe,0x9,0x4,0xe}&lt;br /&gt;    };&lt;br /&gt;m[4]={0x8,0x4,0x2,0x1};&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; int i,j,k;&lt;br /&gt; do&lt;br /&gt; {&lt;br /&gt;  j=0;&lt;br /&gt;  do&lt;br /&gt;  {&lt;br /&gt;   k=0;&lt;br /&gt;   do&lt;br /&gt;   {&lt;br /&gt;    (a[i][j]&amp;m[k])?printf("#"):printf(" ");&lt;br /&gt;   }while(++k&lt;4);&lt;br /&gt;   printf(" ");   &lt;br /&gt;  }while(++j&lt;6);&lt;br /&gt;  printf("\n");&lt;br /&gt; }while(++i&lt;5);&lt;br /&gt; &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-7510987646864709643?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/tumBCi3ff9vH2UaGiSnYaD4QMQs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tumBCi3ff9vH2UaGiSnYaD4QMQs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/tumBCi3ff9vH2UaGiSnYaD4QMQs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/tumBCi3ff9vH2UaGiSnYaD4QMQs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/pGw-92sjEAA" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/7510987646864709643/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=7510987646864709643&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/7510987646864709643?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/7510987646864709643?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/pGw-92sjEAA/interesting-c-program-11.html" title="Interesting C Program -11" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/07/interesting-c-program-11.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eSp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-7489741095742660277</id><published>2007-07-12T17:28:00.000+05:30</published><updated>2007-11-02T12:40:08.601+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.601+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -10</title><content type="html">Quine Program: (A C Program that prints itself)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/*quine.c*/&lt;br /&gt;#include"stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; FILE *fp1;&lt;br /&gt; char x[100][100]={0};&lt;br /&gt; int i; &lt;br /&gt; fp1 = fopen("quine.c","r");&lt;br /&gt; for(i=0;i&lt;50;i++)&lt;br /&gt;  fgets(x[i],50,fp1);&lt;br /&gt; for(i=0;i&lt;50;i++)&lt;br /&gt;  printf("%s",x[i]);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But Can we call this a Quine Program?&lt;br /&gt;&lt;br /&gt;The answer is NO.&lt;br /&gt;Why?&lt;br /&gt;Because, after compilation if you change the source code, new source file will be printed. Then how do you write a quine program?&lt;br /&gt;&lt;br /&gt;Heres an implementation of Quine:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;char *s="char *s=%c%s%c;%cmain(){printf(s,34,s,34,10,10);}%c";&lt;br /&gt;main() {printf(s,34,s,34,10,10);}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-7489741095742660277?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AAJUIG8zscsCMLl8MVdE_pZE6bQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AAJUIG8zscsCMLl8MVdE_pZE6bQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AAJUIG8zscsCMLl8MVdE_pZE6bQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AAJUIG8zscsCMLl8MVdE_pZE6bQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/pA-a1uVDSAk" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/7489741095742660277/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=7489741095742660277&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/7489741095742660277?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/7489741095742660277?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/pA-a1uVDSAk/interesting-c-program-10.html" title="Interesting C Program -10" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>1</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/07/interesting-c-program-10.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eSp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-5708620726583515047</id><published>2007-07-12T13:51:00.000+05:30</published><updated>2007-11-02T12:40:08.601+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.601+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -9</title><content type="html">Something weird in the output of the following program:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;void main(void)&lt;br /&gt;{&lt;br /&gt;     int c = 10;&lt;br /&gt;     printf("%d\n",c);&lt;br /&gt;     printf("%d\n",sizeof(++c));&lt;br /&gt;     printf("%d\n",c);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The output will be:&lt;br /&gt;10&lt;br /&gt;4&lt;br /&gt;10&lt;br /&gt;&lt;code&gt;++c&lt;code&gt; inside &lt;code&gt;sizeof&lt;code&gt; function is ignored.&lt;br /&gt;Why?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The answer goes like this:&lt;br /&gt;The input argument to sizeof function is datatype and not data. So the datatype of ++i will be considered instead of data ++i. So it will not be incremented.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-5708620726583515047?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pdQhYwmS5P1PLVKfkqjc9jIYW0g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pdQhYwmS5P1PLVKfkqjc9jIYW0g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pdQhYwmS5P1PLVKfkqjc9jIYW0g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pdQhYwmS5P1PLVKfkqjc9jIYW0g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/6UQGKcxnU90" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/5708620726583515047/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=5708620726583515047&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/5708620726583515047?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/5708620726583515047?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/6UQGKcxnU90/interesting-program-9.html" title="Interesting C Program -9" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/07/interesting-program-9.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eSp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-4002873377613472603</id><published>2007-07-09T10:45:00.000+05:30</published><updated>2007-11-02T12:40:08.601+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.601+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -8</title><content type="html">Just C the potential of the space in the following C Program:&lt;br /&gt;(Try removing the space before %c in scanf)&lt;br /&gt;&lt;code&gt;&lt;br /&gt; #include &lt;stdio.h&gt;&lt;br /&gt;  int main()&lt;br /&gt;  {&lt;br /&gt;      char c;&lt;br /&gt;      scanf("%c",&amp;c);&lt;br /&gt;      printf("%c\n",c);&lt;br /&gt;&lt;br /&gt;      scanf(" %c",&amp;c);&lt;br /&gt;      printf("%c\n",c);&lt;br /&gt;&lt;br /&gt;      return 0;&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-4002873377613472603?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/6UxvkJI6V3Yla_cm768btuJa_fk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6UxvkJI6V3Yla_cm768btuJa_fk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/6UxvkJI6V3Yla_cm768btuJa_fk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/6UxvkJI6V3Yla_cm768btuJa_fk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/5-J9Y8_3yaM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/4002873377613472603/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=4002873377613472603&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4002873377613472603?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/4002873377613472603?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/5-J9Y8_3yaM/interesting-c-program-8.html" title="Interesting C Program -8" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/07/interesting-c-program-8.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMESXg7eSp7ImA9WB9QGUU.&quot;"><id>tag:blogger.com,1999:blog-980280126094476813.post-196697674662645296</id><published>2007-07-09T10:35:00.000+05:30</published><updated>2007-11-02T12:40:08.601+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2007-11-02T12:40:08.601+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="INTERESTING C PROGRAMS" /><title>Interesting C Program -7</title><content type="html">Guess the Output of the following C Program:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include "stdio.h"&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;        int i=43;&lt;br /&gt;        printf("%d\n",printf("%d",printf("%d",i)));&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The answer is 4321.&lt;br /&gt;Explanation:&lt;br /&gt;printf returns the number of letters printed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/980280126094476813-196697674662645296?l=interestingcprograms.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9_dibGYt49_z8fGVOeH0QfugEbU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9_dibGYt49_z8fGVOeH0QfugEbU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9_dibGYt49_z8fGVOeH0QfugEbU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9_dibGYt49_z8fGVOeH0QfugEbU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/blogspot/bdfew/~4/n-zxf5JbrFo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://interestingcprograms.blogspot.com/feeds/196697674662645296/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=980280126094476813&amp;postID=196697674662645296&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/196697674662645296?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/980280126094476813/posts/default/196697674662645296?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/blogspot/bdfew/~3/n-zxf5JbrFo/interesting-c-program-7.html" title="Interesting C Program -7" /><author><name>Balaji V</name><uri>http://www.blogger.com/profile/18130457055508729339</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><thr:total>0</thr:total><feedburner:origLink>http://interestingcprograms.blogspot.com/2007/07/interesting-c-program-7.html</feedburner:origLink></entry></feed>

