<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1646690589143127535</atom:id><lastBuildDate>Fri, 01 Nov 2024 11:02:03 +0000</lastBuildDate><category>C</category><category>C Programs for Technical Interview</category><category>C Programming Tutorials</category><category>Online C Written test</category><title>C Programming Online</title><description>C Programming Tutorials, Tricks and Concepts. Online C Programming Tests.</description><link>http://cprogrammingonline.blogspot.com/</link><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><generator>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1646690589143127535.post-1281259682564700136</guid><pubDate>Tue, 12 Mar 2013 14:08:00 +0000</pubDate><atom:updated>2013-03-18T21:33:54.648-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C</category><category domain="http://www.blogger.com/atom/ns#">C Programming Tutorials</category><category domain="http://www.blogger.com/atom/ns#">C Programs for Technical Interview</category><title>C Programming Tutorials : printf Format String</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;This post describes the use of Format String or Control String in printf function. An example of printf function is :&lt;br /&gt;
&lt;b&gt;printf(&quot; [FORMAT_STRING/CONTROL_STRING] &quot;, arg1, arg2, ... );&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;color: #cc0000; font-family: inherit;&quot;&gt;Basic Structure of Format String or Control String in printf() Function:&lt;/span&gt;&lt;/h2&gt;
&lt;div&gt;
% [FLAG] [WIDTH] . [PRECISION] [MODIFIER] [TYPE]&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;[FLAG]&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;10px&quot; style=&quot;width: 600px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;- (minus)&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Output is left-adjusted within the field. Remaining field will be blank.&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If no used, output is right-adjusted within the field.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Works with:&lt;/b&gt;&amp;nbsp;char, int , float, double, string.&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;+ (plus)&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;The sign of the numeric will be added before the numeric value i.e. if the numric value is positive, then a + sign will be added before the value.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Works with: &lt;/b&gt;int, float, double&lt;br /&gt;
&lt;b&gt;Prints nothing with: &lt;/b&gt;char, string&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;0 (zero)&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Causes leading zeros to appear.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Works with: &lt;/b&gt;string, int, float, double.&lt;br /&gt;
&lt;b&gt;Prints nothing with: &lt;/b&gt;&amp;nbsp;char&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;#&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;(with o or x)&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Causes octal and hex items to be preceded by 0 (zero) and 0x , respectively.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Works with:&lt;/b&gt;&lt;br /&gt;
&lt;table style=&quot;width: 300px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;( Octal )&lt;/td&gt;&lt;td&gt;&lt;b&gt;%#o&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;( Hex )&lt;/td&gt;&lt;td&gt;&lt;b&gt;%#x&lt;/b&gt; &amp;nbsp;or &lt;b&gt;%#X&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;#&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;(with e, f or g)&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Causes decimal point to be present in all floating point numbers.&lt;br /&gt;
Prevents the truncation of trailing zeros in g-type conversion.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Note: FLAGS can be mixed in any order&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;h3&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;[WIDTH]&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
It is a&amp;nbsp;+ve integer. It defines minimum field width.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Case 1:&lt;/b&gt;&amp;nbsp;Length of data &amp;lt; [WIDTH]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; Data is printed right-adjusted&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Case 2: &lt;/b&gt;Length of data &amp;gt;= [WIDTH]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; =&amp;gt; Entire data gets printed.&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;20px&quot; style=&quot;width: 600pxpx;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;500px&quot;&gt;&lt;b&gt;Note:&lt;/b&gt;&amp;nbsp;If the [WIDTH] is given as -ve, then the - (minus) sign will be treated as flag&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;[PRECISION]&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;10px&quot; style=&quot;width: 600px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;with String&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Indicates no of charecters to be printed .&lt;br /&gt;
If [PRECISION] &amp;gt; Length of data, entire String gets printed&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;with float, double and &amp;nbsp;long double&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Indicates no. of digits to be printed after decimal point.&lt;br /&gt;
&lt;br /&gt;
If [PRECISION] &amp;lt; no. of digits after decimal point,&lt;br /&gt;
rounded value will be printed.&lt;br /&gt;
&lt;br /&gt;
If [PRECISION] &amp;gt; no. of digits after decimal point,&lt;br /&gt;
trailing zeros will be added.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;with integer&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;If [PRECISION] &amp;gt; Length of data,&lt;br /&gt;
prints (precision - length of data) no. of zeros.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;with char&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Does nothing&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;center&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;20px&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;500px&quot;&gt;&lt;b&gt;Note:&lt;/b&gt;&amp;nbsp;[PRECISION] is a positive integer. If it is given as negative, then &lt;b&gt;- (minus) sign&amp;nbsp;+ precision value&amp;nbsp;+ type&lt;/b&gt; gets printed.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;[MODIFIERS]&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;10px&quot; style=&quot;width: 600px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;h&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;for short integer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;l&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;for long integers or double&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;L&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;for long double&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;[TYPE]&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;10px&quot; style=&quot;width: 600px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%a&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Hexadecimal output in the form&lt;br /&gt;
0x h.hhhhhh p+ or - xxxx (C99 only)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%A&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Hexadecimal output in the form&lt;br /&gt;
0x h.hhhhhh P+ or - xxxx (C99 only)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%x&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Hexadecimal integer&lt;br /&gt;
e.g. 0x5fc8&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%X&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Hexadecimal integer&lt;br /&gt;
e.g. 0x5FC8&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%o&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Octal integer&lt;br /&gt;
e.g. 0879&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%c&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;type char&lt;br /&gt;
e.g. &#39;a&#39;, &#39;A&#39;, &#39;8&#39; etc.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%d&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;decimal integer (signed )&lt;br /&gt;
e.g. 5, -4 etc.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%i&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;decimal integer (signed )&lt;br /&gt;
e.g. 6, -6 etc.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%u&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;unsigned decimal integer&lt;br /&gt;
etc. 5, 6 etc.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%s&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;String&lt;br /&gt;
e.g. &quot;Do you like this article?&quot; etc.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%e&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;scientific notation in the form&lt;br /&gt;
d.xxxxxx e&amp;nbsp;+ or - xxx&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%E&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;scientific notation in the form&lt;br /&gt;
d.xxxxxx E&amp;nbsp;+ or - xxx&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%f&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;float in the form d.xxxxxx&lt;br /&gt;
e.g. 5.000000&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%g&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;uses %e or %f whichever is shorter&lt;br /&gt;
e.g. 100000, 1e+006, 0.0005, 5e-005 etc.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%G&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;uses %E or %f whichever is shorter&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%p&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Segment address (of pointer variable) in Hex.&lt;br /&gt;
e.g. 12ao&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%Fp&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;Segment address and offset address in Hex.&lt;br /&gt;
e.g. 0001:00f2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%n&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;The associated argument must be a pointer to an integer. This specifier causes the number of charecters written (upto the point at which %n is entercounted) to be stored in that integer.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;100&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;%%&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;prints a % sign&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;center&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;20px&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;500px&quot;&gt;&lt;b&gt;Note:&lt;/b&gt;&amp;nbsp;[WIDTH] and [PRECISION] can be specified as a argument variable in printf() function. For example,&lt;br /&gt;
&lt;b&gt;printf( &quot;%*.*s&quot; , width, precision );&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;Few Examples of printf() Function&lt;/span&gt;&lt;/h2&gt;
Assume, the following variable declarations:&lt;br /&gt;
char str[]=&quot;world&quot;;&lt;br /&gt;
int a = 50;&lt;br /&gt;
int b = -50;&lt;br /&gt;
float c = 4.5446;&lt;br /&gt;
unsigned int d = 5;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note: The following examples are Tested on 32 bit GCC compiler&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;table border=&quot;1px&quot; cellpadding=&quot;10px&quot; style=&quot;width: 600px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td width=&quot;400&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;b&gt;Statements&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&lt;b&gt;Output&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;400&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%s&quot;, str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%-10s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%2s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%-2s&quot;,str);&lt;br /&gt;
printf(&quot;%(-10)s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%-(-10)s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%20(-10)s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%5s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%-5s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%+10s&quot;,str);&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
printf(&quot;%010s&quot;,str);&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;td&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;world&lt;br /&gt;
world&lt;br /&gt;
world&lt;br /&gt;
world&lt;br /&gt;
(-10)s&lt;br /&gt;
(-10)s&lt;br /&gt;
(-10)s&lt;br /&gt;
world&lt;br /&gt;
world&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;world&lt;br /&gt;
00000world&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;400&quot;&gt;printf(&quot;%-10d&quot;,a);&lt;br /&gt;
printf(&quot;%+-10d&quot;,a);&lt;br /&gt;
printf(&quot;%010d&quot;,a);&lt;br /&gt;
printf(&quot;%0+10d&quot;,a);&lt;br /&gt;
printf(&quot;%+0+10d&quot;,a);&lt;br /&gt;
printf(&quot;%010d&quot;,b);&lt;br /&gt;
printf(&quot;%#d&quot;,a);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%#x %x&quot;,a,a);&lt;br /&gt;
printf(&quot;%#o %o&quot;,a,a);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%f&quot;,6);&lt;br /&gt;
printf(&quot;%f&quot;,6.);&lt;br /&gt;
printf(&quot;%f&quot;,6.0);&lt;br /&gt;
printf(&quot;%f&quot;);&lt;br /&gt;
printf(&quot;%d&quot;);&lt;/td&gt;&lt;td&gt;50&lt;br /&gt;
+50&lt;br /&gt;
0000000050&lt;br /&gt;
+000000050&lt;br /&gt;
+000000050&lt;br /&gt;
-000000050&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
0x32 32&lt;br /&gt;
062 62&lt;br /&gt;
&lt;br /&gt;
0.000000&lt;br /&gt;
6.000000&lt;br /&gt;
6.000000&lt;br /&gt;
0.000000&lt;br /&gt;
garbage value&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td width=&quot;400&quot;&gt;printf(&quot;%10.2s&quot;,str);&lt;br /&gt;
printf(&quot;%10.8s&quot;,str);&lt;br /&gt;
printf(&quot;%10.-4s&quot;,str);&lt;br /&gt;
printf(&quot;%1.-4s&quot;,str);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%10.5f&quot;,c);&lt;br /&gt;
printf(&quot;%10.3f&quot;,c);&lt;br /&gt;
printf(&quot;%10.9f&quot;,c);&lt;br /&gt;
printf(&quot;%.5f&quot;,c);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%4.3d&quot;,a);&lt;br /&gt;
printf(&quot;%.0d&quot;,a);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%d %d&quot;, 5, -5);&lt;br /&gt;
printf(&quot;%i %i&quot;, 6, -6);&lt;br /&gt;
printf(&quot;%u %u&quot;, 7, -7);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%5.3c&quot;,&#39;d&#39;);&lt;br /&gt;
printf(&quot;%0c&quot;,&#39;d&#39;);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%I64&quot;);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%s&quot;,&quot;Hello&quot;);&lt;br /&gt;
printf(&quot;%s&quot;,&quot;%d&quot;,5);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;I64d&quot;,5);&lt;br /&gt;
printf(&quot;%I64d&quot;,-5);&lt;br /&gt;
&lt;br /&gt;
printf(&quot;%d&quot;+1,5);&lt;/td&gt;&lt;td&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; wo&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;world&lt;br /&gt;
-4s&lt;br /&gt;
-4s&lt;br /&gt;
&lt;br /&gt;
4.54460&lt;br /&gt;
4.545&lt;br /&gt;
4.54600000&lt;br /&gt;
4.54460&lt;br /&gt;
&lt;br /&gt;
050&lt;br /&gt;
50&lt;br /&gt;
&lt;br /&gt;
5 -5&lt;br /&gt;
6 -6&lt;br /&gt;
7 4294967289&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;d&lt;br /&gt;
d&lt;br /&gt;
&lt;br /&gt;
prints nothing&lt;br /&gt;
&lt;br /&gt;
Hello&lt;br /&gt;
%d&lt;br /&gt;
&lt;br /&gt;
21474836485&lt;br /&gt;
25769803771&lt;br /&gt;
&lt;br /&gt;
d&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;Confused, Have any questions?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Post your comments, questions, State your confusion to us.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
We&#39;re here to help you.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;Are you facing problems in writing C programs?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Hire us now!&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;a href=&quot;http://www.cprogrammingonline.blogspot.com/p/submit-your-problem.html&quot; target=&quot;_blank&quot;&gt;Submit Your Problem Now&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;If You Enjoy This Post, Do us a favor: Share This Page&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;!-- AddThis Button BEGIN --&gt;
&lt;br /&gt;
&lt;div class=&quot;addthis_toolbox addthis_default_style &quot;&gt;
&lt;a class=&quot;addthis_button_facebook_like&quot; fb:like:layout=&quot;button_count&quot; href=&quot;http://www.blogger.com/blogger.g?blogID=1646690589143127535&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;addthis_button_tweet&quot; href=&quot;http://www.blogger.com/blogger.g?blogID=1646690589143127535&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;addthis_button_pinterest_pinit&quot; href=&quot;http://www.blogger.com/blogger.g?blogID=1646690589143127535&quot;&gt;&lt;/a&gt;
&lt;a class=&quot;addthis_counter addthis_pill_style&quot; href=&quot;http://www.blogger.com/blogger.g?blogID=1646690589143127535&quot;&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;var addthis_config = {&quot;data_track_addressbar&quot;:true};&lt;/script&gt;
&lt;script src=&quot;//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-513f34da2d1cd72c&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;!-- AddThis Button END --&gt;

&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;Subscribe via Email&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h4&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;
&lt;form action=&quot;http://feedburner.google.com/fb/a/mailverify&quot; id=&quot;feedform&quot; method=&quot;post&quot; onsubmit=&quot;window.open(&#39;http://feedburner.google.com/fb/a/mailverify?uri=CProgrammingOnline&#39;, &#39;popupwindow&#39;, &#39;scrollbars=yes,width=550,height=520&#39;);return true&quot; target=&quot;popupwindow&quot;&gt;
&lt;input class=&quot;textarea&quot; name=&quot;email&quot; onblur=&quot;if (this.value == &amp;quot;&amp;quot;) {this.value = &amp;quot;Enter email address here&amp;quot;;}&quot; onfocus=&quot;if (this.value == &amp;quot;Enter email address here&amp;quot;) {this.value = &amp;quot;&amp;quot;;}&quot; type=&quot;text&quot; value=&quot;Enter email address here&quot; /&gt;
&lt;input name=&quot;uri&quot; type=&quot;hidden&quot; value=&quot;CProgrammingOnline&quot; /&gt;
&lt;input name=&quot;title&quot; type=&quot;hidden&quot; value=&quot;&quot; /&gt;
&lt;input name=&quot;loc&quot; type=&quot;hidden&quot; value=&quot;en_US&quot; /&gt;
&lt;input style=&quot;-moz-border-radius: 6px; -webkit-border-radius: 6px; background: #F5C4A1; border-radius: 6px; border: none; color: #532f23; cursor: pointer; font: 12px inherit; padding: 3px; text-shadow: 0 -1px 1px rgba(0,0,0,0.25);&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;&lt;/form&gt;
&lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
</description><link>http://cprogrammingonline.blogspot.com/2013/03/c-programming-tutorials-printf-format.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1646690589143127535.post-7453933157300224079</guid><pubDate>Tue, 04 Sep 2012 19:13:00 +0000</pubDate><atom:updated>2012-09-04T19:16:18.913-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Online C Written test</category><title>Online C Programming Test</title><description>&lt;div&gt;
&lt;center&gt;&lt;p&gt;&lt;h3&gt;Test Description&lt;/h3&gt;
&lt;b&gt;&lt;i&gt;Subject = C Programming&lt;br/&gt;
No of Questions = 20&lt;br /&gt;
Time = 30 mins&lt;br /&gt;
Total Marks = 20&lt;br/&gt;&lt;br/&gt;
Correct Answer = 1 mark&lt;br /&gt;
Wrong Answer = - 0.25 mark (negative)&lt;br/&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;
&lt;input type=&quot;button&quot; id=&quot;starttest&quot; value=&quot;Start Online Test&quot; onclick=&quot;startTest()&quot;/&gt;&lt;/center&gt;
&lt;p id=&quot;showtime&quot; style=&quot;color:#ff3300; font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;

&lt;form name=&quot;onlinetest&quot; id=&quot;onlinetest&quot; style=&quot;display: none;&quot;&gt;
    &lt;label name=&quot;question1&quot; id=&quot;question1&quot;&gt;&lt;b&gt;Question 1:&lt;i&gt; What is the output of the following C program?&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
 int main(){&lt;br/&gt;
 int i=5;&lt;br/&gt;
 printf(&quot;%d %d %d %d %d&quot;,i++,i--,++i,--i,i);&lt;br/&gt;
 }&lt;br/&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q1&quot; id=&quot;A1&quot; value=&quot;(A) 45554&quot; /&gt;(A) 45554&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q1&quot; id=&quot;B1&quot; value=&quot;(B) 45545&quot; /&gt;(B) 45545&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q1&quot; id=&quot;C1&quot; value=&quot;(C) 45554&quot; /&gt;(C) 56655&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q1&quot; id=&quot;D1&quot; value=&quot;(D) Undefined results&quot; /&gt;(D) Undefined results&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult1&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(1);&quot; /&gt;
 
 &lt;p id=&quot;youranswer1&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer1&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is B.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt; The arguments in a function are pushed into the stack from left to right.&lt;br/&gt;
  The evaluation is by popping out from the stack.&lt;br/&gt;
  So, the evaluation is from right to left.&lt;br/&gt;
  Hence, the order of execution is as follows: i, --i, ++i, i-- and finally i++&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question2&quot; id=&quot;question2&quot;&gt;&lt;b&gt;Question 2:&lt;i&gt; What is the output of the following C program?&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
 #define a 10&lt;br/&gt;
 int main(){&lt;br/&gt;
 #define a 50&lt;br/&gt;
 int i=5;&lt;br/&gt;
 printf(&quot;%d&quot;,a);&lt;br/&gt;
 }&lt;br/&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q2&quot; id=&quot;A2&quot; value=&quot;(A) 10&quot; /&gt;(A) 10&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q2&quot; id=&quot;B2&quot; value=&quot;(B) 50&quot; /&gt;(B) 50&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q2&quot; id=&quot;C2&quot; value=&quot;(C) Compiler Error&quot; /&gt;(C) Compiler Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q2&quot; id=&quot;D2&quot; value=&quot;(D) Unexpected results&quot; /&gt;(D) Unexpected results&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult2&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(2);&quot; /&gt;
 
 &lt;p id=&quot;youranswer2&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer2&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is B.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt; After executing #define a 10&lt;br/&gt;
  main(){&lt;br/&gt;#define 10 50&lt;br/&gt;printf(&quot;%d&quot;,10); }&lt;br/&gt;&lt;br/&gt;After executing next #define 10 50&lt;br/&gt;main(){&lt;br/&gt;
  printf(&quot;%d&quot;,50); }&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 
    &lt;label name=&quot;question3&quot; id=&quot;question3&quot;&gt;&lt;b&gt;Question 3:&lt;i&gt; What is the output of the following C program?&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
 int main(){&lt;br/&gt;
 int i = -3, j = 2, k = 0, m;&lt;br/&gt;
 m = ++i &amp;&amp; ++j || ++k;&lt;br/&gt;
 printf(&quot;%d %d %d %d&quot;,i,j,k,m);&lt;br/&gt;
 }&lt;br/&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q3&quot; id=&quot;A3&quot; value=&quot;(A) -2 3 0 1&quot; /&gt;(A) -2 3 0 1&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q3&quot; id=&quot;B3&quot; value=&quot;(B) -3 3 0 1&quot; /&gt;(B) -3 3 0 1&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q3&quot; id=&quot;C3&quot; value=&quot;(C) -2 3 1 1&quot; /&gt;(C) -2 3 1 1&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q3&quot; id=&quot;D3&quot; value=&quot;(D) -3 3 1 1&quot; /&gt;(D) -3 3 1 1&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult3&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(3);&quot; /&gt;
 
 &lt;p id=&quot;youranswer3&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer3&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is A.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 Here the priority of &amp;&amp; is greater than || so &amp;&amp; will be executed first&lt;br/&gt;
 m = (( ++i &amp;&amp; ++j ) || ++k)&lt;br/&gt;
 1st the value of i &amp; j will be incremented by 1. But as because left of || becomes true, irrespective of the value of right side,
 the value of the total expression will be true. So value of k will not be incremented.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 
    &lt;label name=&quot;question4&quot; id=&quot;question4&quot;&gt;&lt;b&gt;Question 4:&lt;i&gt; What is the output of the following C program?&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
 int main(){&lt;br/&gt;
 int i = 4, j = 2;&lt;br/&gt;
 int *p = &amp;i, *q = &amp;j;&lt;br/&gt;
 int k = *p/*q;&lt;br/&gt;
 printf(&quot;%d&quot;,k);&lt;br/&gt;
 }&lt;br/&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q4&quot; id=&quot;A4&quot; value=&quot;(A) 2&quot; /&gt;(A) 2&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q4&quot; id=&quot;B4&quot; value=&quot;(B) 0&quot; /&gt;(B) 0&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q4&quot; id=&quot;C4&quot; value=&quot;(C) Compiler Error&quot; /&gt;(C) Compiler Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q4&quot; id=&quot;D4&quot; value=&quot;(D) Runtime Error&quot; /&gt;(D) Runtime Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult4&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(4);&quot; /&gt;
 
 &lt;p id=&quot;youranswer4&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer4&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 Compiler Error: Unexpected end of file in a comment&lt;br/&gt;There should be space between / and * in line 4&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question5&quot; id=&quot;question5&quot;&gt;&lt;b&gt;Question 5:&lt;i&gt; What error would the following function give on compilation?&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
 f(int a, int b){&lt;br/&gt;
 int a;&lt;br/&gt;
 a = 20;&lt;br/&gt;
 return a;&lt;br/&gt;
 }&lt;br/&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q5&quot; id=&quot;A5&quot; value=&quot;(A) Missing Parenthesis in return statement&quot; /&gt;(A) Missing Parenthesis in return statement&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q5&quot; id=&quot;B5&quot; value=&quot;(B) The function should be defined as int f(int a, intb)&quot; /&gt;(B) The function should be defined as int f(int a, intb)&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q5&quot; id=&quot;C5&quot; value=&quot;(C) Redeclaration of a&quot; /&gt;(C) Redeclaration of a&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q5&quot; id=&quot;D5&quot; value=&quot;(D) No error&quot; /&gt;(D) No Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult5&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(5);&quot; /&gt;
 
 &lt;p id=&quot;youranswer5&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer5&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 Compiler Error: variable a is declared twice.&lt;br/&gt;One in formal arguments and another in body.&lt;br/&gt;So, Complier Error: Redeclaration of a&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question6&quot; id=&quot;question6&quot;&gt;&lt;b&gt;Question 6:&lt;i&gt; If n set the value 2, then the statement a[++n] = n++; will assign&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q6&quot; id=&quot;A6&quot; value=&quot;(A) 3 to a[4]&quot; /&gt;(A) 3 to a[4]&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q6&quot; id=&quot;B6&quot; value=&quot;(B) 2 to a[4]&quot; /&gt;(B) 2 to a[4]&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q6&quot; id=&quot;C6&quot; value=&quot;(C) 3 to a[3]&quot; /&gt;(C) 3 to a[3]&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q6&quot; id=&quot;D6&quot; value=&quot;(D) 4 to a[3]&quot; /&gt;(D) 4 to a[3]&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult6&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(6);&quot; /&gt;
 
 &lt;p id=&quot;youranswer6&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer6&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is B.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 a[++n] = n++;&lt;br/&gt;Here post increment operator will return value of n 1st.&lt;br/&gt;
                then n is incremented by 1&lt;br/&gt;
                Now pre-increment operator increments the value of n by 1 first and then return it.
                &lt;br/&gt;so here 2 will be assigned to a[4]&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question7&quot; id=&quot;question7&quot;&gt;&lt;b&gt;Question 7:&lt;i&gt; What will be the output of the following C function?&lt;/i&gt;&lt;br/&gt;
printf(&quot;xy&quot;,&quot;ab&quot;,&quot;mn&quot;);&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q7&quot; id=&quot;A7&quot; value=&quot;(A) xy&quot; /&gt;(A) xy&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q7&quot; id=&quot;B7&quot; value=&quot;(B) xy ab mn&quot; /&gt;(B) xy ab mn&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q7&quot; id=&quot;C7&quot; value=&quot;(C) garbage value&quot; /&gt;(C) garbage value&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q7&quot; id=&quot;D7&quot; value=&quot;(D) Compiler error&quot; /&gt;(D) Compiler error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult7&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(7);&quot; /&gt;
 
 &lt;p id=&quot;youranswer7&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer7&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is A.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 It will only print &quot;xy&quot;&lt;br/&gt;Other terms will not be printed.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question8&quot; id=&quot;question8&quot;&gt;&lt;b&gt;Question 8:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
unsigned i = 3;&lt;br/&gt;
if(i&gt;-1)  printf(&quot;I like Qualitycoding&quot;);&lt;br/&gt;
else  printf(&quot;I love QualityCoding&quot;);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q8&quot; id=&quot;A8&quot; value=&quot;(A) I like QualityCoding&quot; /&gt;(A) I like QualityCoding&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q8&quot; id=&quot;B8&quot; value=&quot;(B) I love QualityCoding&quot; /&gt;(B) I love QualityCoding&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q8&quot; id=&quot;C8&quot; value=&quot;(C) Compiler Error&quot; /&gt;(C) Compiler Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q8&quot; id=&quot;D8&quot; value=&quot;(D) Unexpected Results&quot; /&gt;(D) Unexpected Results&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult8&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(8);&quot; /&gt;
 
 &lt;p id=&quot;youranswer8&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer8&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is B.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 Comparison is to be done with both numbers as unsigned.&lt;br/&gt;
                Unsigned representation of -1 is 32769&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question9&quot; id=&quot;question9&quot;&gt;&lt;b&gt;Question 9:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
printf(5+&quot;Intelligent&quot;);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q9&quot; id=&quot;A9&quot; value=&quot;(A) Error&quot; /&gt;(A) Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q9&quot; id=&quot;B9&quot; value=&quot;(B) Intelligent&quot; /&gt;(B) Intelligent&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q9&quot; id=&quot;C9&quot; value=&quot;(C) ligent&quot; /&gt;(C) ligent&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q9&quot; id=&quot;D9&quot; value=&quot;(D) Intell&quot; /&gt;(D) Intell&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult9&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(9);&quot; /&gt;
 
 &lt;p id=&quot;youranswer9&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer9&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 printf function will print ligent.&lt;br/&gt;
                first 5 charecters will not be printed.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 &lt;label name=&quot;question10&quot; id=&quot;question10&quot;&gt;&lt;b&gt;Question 10:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
while(1) {&lt;br/&gt;
if( printf(&quot;%d&quot;, printf(&quot;%d&quot;) ) )&lt;br/&gt;
break;&lt;br/&gt;
else  continue;&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q10&quot; id=&quot;A10&quot; value=&quot;(A) Compilation Error&quot; /&gt;(A) Compilation Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q10&quot; id=&quot;B10&quot; value=&quot;(B) Runtime Error&quot; /&gt;(B) Runtime Error&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q10&quot; id=&quot;C10&quot; value=&quot;(C) Garbage Value&quot; /&gt;(C) Garbage Value&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q10&quot; id=&quot;D10&quot; value=&quot;(D) prints nothing&quot; /&gt;(D) prints nothing&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult10&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(10);&quot; /&gt;
 
 &lt;p id=&quot;youranswer10&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer10&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 As &#39;printf&#39; is declared within a &#39;printf&#39; it will print some garbage value. And as it is non zero value, 
so it will be executed and it will come out of the while loop.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question11&quot; id=&quot;question11&quot;&gt;&lt;b&gt;Question 11:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
#define prod(a,b) a*b&lt;br/&gt;
main(){&lt;br/&gt;
int x=3, y=4;&lt;br/&gt;
printf(&quot;%d&quot;, prod(x+2, y-1) );&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q11&quot; id=&quot;A11&quot; value=&quot;(A) 10&quot; /&gt;(A) 10&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q11&quot; id=&quot;B11&quot; value=&quot;(B) 15&quot; /&gt;(B) 15&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q11&quot; id=&quot;C11&quot; value=&quot;(C) 12&quot; /&gt;(C) 12&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q11&quot; id=&quot;D11&quot; value=&quot;(D) Compilation Error&quot; /&gt;(D) Compilation Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult11&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(11);&quot; /&gt;
 
 &lt;p id=&quot;youranswer11&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer11&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is A.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 here prod(x+2,y-1) will be substituted by macro as x + 2 * y - 1 = 10&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question12&quot; id=&quot;question12&quot;&gt;&lt;b&gt;Question 12:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
printf(&quot;%d %d&quot;,sizeof(NULL), sizeof(&quot; &quot;) );&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q12&quot; id=&quot;A12&quot; value=&quot;(A) 4 2&quot; /&gt;(A) 4 2&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q12&quot; id=&quot;B12&quot; value=&quot;(B) 2 2&quot; /&gt;(B) 2 2&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q12&quot; id=&quot;C12&quot; value=&quot;(C) 4 4&quot; /&gt;(C) 4 4&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q12&quot; id=&quot;D12&quot; value=&quot;(D) 2 4&quot; /&gt;(D) 2 4&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult12&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(12);&quot; /&gt;
 
 &lt;p id=&quot;youranswer12&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer12&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is A.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 In stdio.h header file NULL is defined as 0. So sizeof(0) is 4.&lt;br/&gt;
But sizeof(&quot; &quot;) is 2. &quot; &quot; means two charecters space i.e. &#39; &#39; and null charecter &#39;\0&#39;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 &lt;label name=&quot;question13&quot; id=&quot;question13&quot;&gt;&lt;b&gt;Question 13:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
char str1[]=&quot;Hello&quot;;&lt;br/&gt;
char str2[]=&quot;Hello&quot;;&lt;br/&gt;
if(str1==str2)&lt;br/&gt;
printf(&quot;equal&quot;);&lt;br/&gt;
else&lt;br/&gt;
printf(&quot;unequal&quot;);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q13&quot; id=&quot;A13&quot; value=&quot;(A) equal&quot; /&gt;(A) equal&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q13&quot; id=&quot;B13&quot; value=&quot;(B) unequal&quot; /&gt;(B) unequal&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q13&quot; id=&quot;C13&quot; value=&quot;(C) Compilation Error&quot; /&gt;(C) Compilation Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q13&quot; id=&quot;D13&quot; value=&quot;(D) Runtime Error&quot; /&gt;(D) Runtime Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult13&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(13);&quot; /&gt;
 
 &lt;p id=&quot;youranswer13&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer13&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is B.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 As str1 and str2 are comparing their base addresses and base addresses cann&#39;t be equal. So it will print &#39;unequal&#39;.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question14&quot; id=&quot;question14&quot;&gt;&lt;b&gt;Question 14:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
printf(&quot;%c&quot;,3[&quot;beautiful&quot;]);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q14&quot; id=&quot;A14&quot; value=&quot;(A) 3rd charecter from left i.e. prints a&quot; /&gt;(A) 3rd charecter from left i.e. prints a&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q14&quot; id=&quot;B14&quot; value=&quot;(B) 3rd charecter from right i.e. prints f&quot; /&gt;(B) 3rd charecter from right i.e. prints f&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q14&quot; id=&quot;C14&quot; value=&quot;(C) 4th charecter from left i.e. prints u&quot; /&gt;(C) 4th charecter from left i.e. prints u&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q14&quot; id=&quot;D14&quot; value=&quot;(D) 4th charecter from right i.e. prints i&quot; /&gt;(D) 4th charecter from right i.e. prints i&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult14&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(14);&quot; /&gt;
 
 &lt;p id=&quot;youranswer14&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer14&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 prints 4th charecter from left i.e. prints u.&lt;br/&gt;
3[&quot;beautiful&quot;] is equivalent to &quot;beautiful&quot;[3]&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question15&quot; id=&quot;question15&quot;&gt;&lt;b&gt;Question 15:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
float a=2.2, c=2.5;&lt;br/&gt;
if(a==2.2) printf(&quot;Hello,&quot;);&lt;br/&gt;
if(c==2.5) printf(&quot;How are you&quot;);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q15&quot; id=&quot;A15&quot; value=&quot;(A) Hello, How are you&quot; /&gt;(A) Hello, How are you&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q15&quot; id=&quot;B15&quot; value=&quot;(B) Hello,&quot; /&gt;(B) Hello,&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q15&quot; id=&quot;C15&quot; value=&quot;(C) How are you&quot; /&gt;(C) How are you&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q15&quot; id=&quot;D15&quot; value=&quot;(D) prints nothing&quot; /&gt;(D) prints nothing&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult15&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(15);&quot; /&gt;
 
 &lt;p id=&quot;youranswer15&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer15&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 comparing floating point value with == operator always gives false value except when fractional part is either .5 or .0&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question16&quot; id=&quot;question16&quot;&gt;&lt;b&gt;Question 16:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
if(0,1,2,3)&lt;br/&gt;
printf(&quot;I like QualityCoding&quot;);&lt;br/&gt;
else&lt;br/&gt;
printf(&quot;I love QualityCoding&quot;);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q16&quot; id=&quot;A16&quot; value=&quot;(A) I like QualityCoding&quot; /&gt;(A) I like QualityCoding&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q16&quot; id=&quot;B16&quot; value=&quot;(B) I love QualityCoding&quot; /&gt;(B) I love QualityCoding&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q16&quot; id=&quot;C16&quot; value=&quot;(C) Compilation Error&quot; /&gt;(C) Compilation Error&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q16&quot; id=&quot;D16&quot; value=&quot;(D) Runtime Error&quot; /&gt;(D) Runtime Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult16&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(16);&quot; /&gt;
 
 &lt;p id=&quot;youranswer16&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer16&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is A.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 The condition if(0,1,2,3) will evaluated to if(3) which is true because 3!=0 is true.&lt;br/&gt;
Comma operator will return 3 here i.e. the right most value.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question17&quot; id=&quot;question17&quot;&gt;&lt;b&gt;Question 17:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
printf(&quot;%s&quot;,0);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q17&quot; id=&quot;A17&quot; value=&quot;(A) (false)&quot; /&gt;(A) (false)&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q17&quot; id=&quot;B17&quot; value=&quot;(B) 0&quot; /&gt;(B) 0&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q17&quot; id=&quot;C17&quot; value=&quot;(C) (null)&quot; /&gt;(C) (null)&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q17&quot; id=&quot;D17&quot; value=&quot;(D) Compilation Error&quot; /&gt;(D) Compilation Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult17&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(17);&quot; /&gt;
 
 &lt;p id=&quot;youranswer17&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer17&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is C.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 It will print (null).&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question18&quot; id=&quot;question18&quot;&gt;&lt;b&gt;Question 18:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
int i, a[]={000,001,010,011,100,101,110,111};&lt;br/&gt;
for(i=0;i&lt;8;i++)&lt;br/&gt;
printf(&quot;%d &quot;,a[i]);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q18&quot; id=&quot;A18&quot; value=&quot;(A) 0 1 10 11 100 101 110 111&quot; /&gt;(A) 0 1 10 11 100 101 110 111&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q18&quot; id=&quot;B18&quot; value=&quot;(B) 0 1 8 9 64 65 72 73&quot; /&gt;(B) 0 1 8 9 64 65 72 73&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q18&quot; id=&quot;C18&quot; value=&quot;(C) 0 1 8 9 64 65 110 111&quot; /&gt;(C) 0 1 8 9 64 65 110 111&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q18&quot; id=&quot;D18&quot; value=&quot;(D) 0 1 8 9 100 101 110 111&quot; /&gt;(D) 0 1 8 9 100 101 110 111&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult18&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(18);&quot; /&gt;
 
 &lt;p id=&quot;youranswer18&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer18&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is D.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 The value of 010 and 011 will be 8 and 9. because these two numbers 010 and 011 are in octal i.e. preceeded by 0.&lt;br/&gt;
So, after storing it into the array, it will be converted into decimal value.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question19&quot; id=&quot;question19&quot;&gt;&lt;b&gt;Question 19:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
int i=5;&lt;br/&gt;
printf(&quot;%d &quot;,i++++++i);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q19&quot; id=&quot;A19&quot; value=&quot;(A) 10&quot; /&gt;(A) 10&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q19&quot; id=&quot;B19&quot; value=&quot;(B) 11&quot; /&gt;(B) 11&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q19&quot; id=&quot;C19&quot; value=&quot;(C) Unexpected result&quot; /&gt;(C) Unexpected result&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q19&quot; id=&quot;D19&quot; value=&quot;(D) Compiler Error&quot; /&gt;(D) Compiler Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult19&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(19);&quot; /&gt;
 
 &lt;p id=&quot;youranswer19&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer19&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is D.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 The expression is parsed as i++  ++  + i which is illegal. So, compiler error.&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
 
 
 &lt;label name=&quot;question20&quot; id=&quot;question20&quot;&gt;&lt;b&gt;Question 20:&lt;i&gt; What will be the output of the following C program?&lt;/i&gt;&lt;br/&gt;
main(){&lt;br/&gt;
int i=10,*p=&amp;i;&lt;br/&gt;
int c=i/*p; /*Result of division operation is stored in variable c*/;&lt;br/&gt;
printf(&quot;%d&quot;,c);&lt;br/&gt;
}&lt;/b&gt;&lt;br /&gt;&lt;/label&gt;
 
    &lt;input type=&quot;radio&quot; name=&quot;Q20&quot; id=&quot;A20&quot; value=&quot;(A) 1&quot; /&gt;(A) 1&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q20&quot; id=&quot;B20&quot; value=&quot;(B) 10&quot; /&gt;(B) 10&lt;br /&gt;
 &lt;input type=&quot;radio&quot; name=&quot;Q20&quot; id=&quot;C20&quot; value=&quot;(C) unexpected results&quot; /&gt;(C) unexpected results&lt;br /&gt;
    &lt;input type=&quot;radio&quot; name=&quot;Q20&quot; id=&quot;D20&quot; value=&quot;(D) Compiler Error&quot; /&gt;(D) Compiler Error&lt;br /&gt;
 &lt;input type=&quot;button&quot; id=&quot;clearresult20&quot; value=&quot;Clear Answer&quot; onclick=&quot;uncheck(20);&quot; /&gt;
 
 &lt;p id=&quot;youranswer20&quot; style=&quot;font-size: large; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
 &lt;center&gt;
 &lt;p id=&quot;answer20&quot; style=&quot;display: none;&quot;&gt;&lt;br /&gt;&lt;b&gt;Correct Answer is B.&lt;br/&gt;Explanation:&lt;/b&gt;&lt;br/&gt;
 line 3 will get evaluated as int c=i;&lt;br/&gt;
comment line in line 3 is /*p; /*Result of division operation is stored in variable c*/&lt;br/&gt;
After this comment line there is a semi-colon(;). Hence, answer is 10&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
    &lt;/center&gt;
&lt;/form&gt;


&lt;center&gt;
  &lt;input type=&quot;button&quot; id=&quot;showbutton&quot; value=&quot;Submit and View Result&quot; onclick=&quot;test1(20)&quot; style=&quot;display: none;&quot;/&gt;
  &lt;p id=&quot;showresult&quot; style=&quot;font-size: large; color: #FF3300; font-weight: bold; font-style: italic;&quot;&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;/div&gt;</description><link>http://cprogrammingonline.blogspot.com/2012/09/online-test.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1646690589143127535.post-7744241836844056597</guid><pubDate>Tue, 04 Sep 2012 10:05:00 +0000</pubDate><atom:updated>2013-03-18T21:35:49.432-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C</category><category domain="http://www.blogger.com/atom/ns#">C Programs for Technical Interview</category><title>C Program to find Armstrong Number</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Definition of Armstrong Number:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;A number is Armstrong if the sum of cubes of individual digits of a number&amp;nbsp;&lt;/i&gt;&lt;i&gt;is equal to the number itself.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Example:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
0, 1, 153, 370, 371, 407 etc.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Explanation:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Let us take 153.&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
So, the sum of cubes of individual digits&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
= 1&lt;sup&gt;3 +&amp;nbsp;&lt;/sup&gt;5&lt;sup&gt;3 +&amp;nbsp;&lt;/sup&gt;3&lt;sup&gt;3&lt;/sup&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;vertical-align: super;&quot;&gt;=&amp;nbsp;1 + 125 + 27&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;vertical-align: super;&quot;&gt;= 153&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;vertical-align: super;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;vertical-align: super;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Programming Approach (Algorithm):&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Step 1: number = &amp;lt;Entered Number&amp;gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Step 2: Right Most Digit = number % 10&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Step 3: number = number / 10&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Step 4: Sum = Sum + Cube of Right Most Digit&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Step 5: Repeat Step 2, 3 &amp;amp; 4 until number = 0&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Step 6: if Sum = &amp;lt;Entered Number&amp;gt; then return 1&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &amp;lt;Entered Number&amp;gt; is Armstrong number&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else return 0 // &amp;lt;Entered Number&amp;gt; is not an Armstrong number&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;C Program:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;/*&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;* PROGRAM NAME: Armstrong Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;* SOURCE: http://CProgrammingOnline.blogspot.com&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;/* HEADER FILE DECLARATION SECTION */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;/* FUNCTION PROTOTYPE DECLARATION SECTION */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;_Bool armstrong(int );&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;/* MAIN PROGRAM SECTION */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; int main(char* argv[], int argc){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; int number; &amp;nbsp; &amp;nbsp;//Used to store the given number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; printf(&quot;\nProgram to Test Whether a Number is Armstrong Number or Not\n&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; printf(&quot;Enter an Integer Value (Max Size = %d bytes): &quot;,sizeof(int));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;number);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; if(armstrong(number)==1){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n%d is an armstrong number.&quot;,number);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n%d is not an armstrong number.&quot;,number);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;/*&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;* FUNCTION SIGNATURE: _Bool armstrong(int );&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;* INPUT: int number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;* OUTPUT: 1 if number(INPUT) is an armstrong number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;* &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 if number(INPUT) is not an armstrong number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;_Bool armstrong(int number){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; int stored_number = number; &amp;nbsp;//Used to Store the given number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; int sum = 0; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Used to Store the sum of digits&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; char digit; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Used to Store the digits&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; while(stored_number &amp;gt; 0){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; digit = stored_number % 10;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum += digit * digit * digit;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stored_number /= 10;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; if(sum == number){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; } else {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #674ea7;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;Confused, Have any questions?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Post your comments, questions. State your confusion to us. We&#39;re here to help you.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;Are you facing problems in writing C programs?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Hire us now!&lt;br /&gt;
&lt;span style=&quot;color: #cc0000;&quot;&gt;&lt;a href=&quot;http://www.cprogrammingonline.blogspot.com/p/submit-your-problem.html&quot; target=&quot;_blank&quot;&gt;Submit Your Problem Now&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;Subscribe via Email&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;form action=&quot;http://feedburner.google.com/fb/a/mailverify&quot; id=&quot;feedform&quot; method=&quot;post&quot; onsubmit=&quot;window.open(&#39;http://feedburner.google.com/fb/a/mailverify?uri=CProgrammingOnline&#39;, &#39;popupwindow&#39;, &#39;scrollbars=yes,width=550,height=520&#39;);return true&quot; target=&quot;popupwindow&quot;&gt;
&lt;input class=&quot;textarea&quot; name=&quot;email&quot; onblur=&quot;if (this.value == &amp;quot;&amp;quot;) {this.value = &amp;quot;Enter email address here&amp;quot;;}&quot; onfocus=&quot;if (this.value == &amp;quot;Enter email address here&amp;quot;) {this.value = &amp;quot;&amp;quot;;}&quot; type=&quot;text&quot; value=&quot;Enter email address here&quot; /&gt;
&lt;input name=&quot;uri&quot; type=&quot;hidden&quot; value=&quot;CProgrammingOnline&quot; /&gt;
&lt;input name=&quot;title&quot; type=&quot;hidden&quot; value=&quot;&quot; /&gt;
&lt;input name=&quot;loc&quot; type=&quot;hidden&quot; value=&quot;en_US&quot; /&gt;
&lt;input style=&quot;-moz-border-radius: 6px; -webkit-border-radius: 6px; background: #F5C4A1; border-radius: 6px; border: none; color: #532f23; cursor: pointer; font: 12px inherit; padding: 3px; text-shadow: 0 -1px 1px rgba(0,0,0,0.25);&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
    
&lt;/form&gt;
&lt;span style=&quot;color: #cc0000; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;sup&gt;&lt;span style=&quot;font-size: 13.0pt; line-height: 115%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/sup&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;sup&gt;&lt;span style=&quot;font-size: 13.0pt; line-height: 115%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/sup&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;sup&gt;&lt;span style=&quot;font-size: 13.0pt; line-height: 115%;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/sup&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://cprogrammingonline.blogspot.com/2012/09/c-program-to-find-armstrong-number.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1646690589143127535.post-8715811458841270281</guid><pubDate>Sat, 04 Aug 2012 06:14:00 +0000</pubDate><atom:updated>2012-08-03T23:14:25.462-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C</category><title>Copy Text File using C Program</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; FILE *sfp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;// Source File Pointer&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; FILE *tfp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;// Target File Pointer&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char SourceFilename[255]; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;// Stores the source file name&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char TargetFilename[255]; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;// stores the target file name&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; char ch; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt; // used to read charecter&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &amp;nbsp; &amp;nbsp; &amp;nbsp; from source file name&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; /* Get sourcefile name and targetfile name from the user */&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; printf(&quot;\nEnter Soucefile Name: &quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; gets(SourceFilename);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; fflush(stdin);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; printf(&quot;Enter Targetfile Name (NOTE : If Targetfile already exists, its content will be overwritten): &quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; gets(TargetFilename);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; /* Open source file in read mode and target file in write mode */&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; sfp=fopen(SourceFilename,&quot;r&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(sfp==NULL){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\nERROR: Failed to open %s in read mode. Closing the program...&quot;,SourceFilename);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; tfp=fopen(TargetFilename,&quot;w&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(tfp==NULL){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\nERROR: Failed to open %s in write mode. Closing the program...&quot;,TargetFilename);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt; /* read charecter by charecter from sourcefile&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and write those charecters accordingly in targetfile */&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; while(1){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ch=fgetc(sfp);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(ch==EOF){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }else{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fputc(ch,tfp);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; /* close file pointers */&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; fclose(sfp);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; fclose(tfp);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
</description><link>http://cprogrammingonline.blogspot.com/2012/08/copy-text-file-using-c-program.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item></channel></rss>