<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4514516738910212028</id><updated>2024-09-11T17:49:02.955-07:00</updated><title type='text'>Test your C/C++ Programming Skills</title><subtitle type='html'>Test you C &amp;amp; C++ programming skills here. And enhance your knowledge.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://testyourprogrammingskills.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://testyourprogrammingskills.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4514516738910212028.post-6662055749780766558</id><published>2011-11-27T20:10:00.000-08:00</published><updated>2011-12-10T19:51:44.817-08:00</updated><title type='text'>Test your C++ Programming skills Part 1</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Custom ad */
google_ad_slot = &quot;2185810178&quot;;
google_ad_width = 728;
google_ad_height = 90;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script language=&quot;javascript&quot;&gt;
&lt;!--
var state = &#39;hidden&#39;;

function showhide(layer_ref) {
if (state == &#39;visible&#39;) {
state = &#39;hidden&#39;;
}
else {
state = &#39;visible&#39;;
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( &quot;document.all.&quot; + layer_ref + &quot;.style.visibility = state&quot;);
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById &amp;&amp; !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Q1. The class that in C++ for file input is?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent01&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent01&quot; style=&quot; visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;  ifstream&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q2. How would you define a class with a static data member and initialise it correctly?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent02&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent02&quot; style=&quot;visibility: hidden;&quot;&gt;class bad { static I;}&lt;br /&gt;
int bad::I=100;&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q3. What is the error in the code snippet below?&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
int *p;&lt;br /&gt;
int q;&lt;br /&gt;
p = new int;&lt;br /&gt;
delete q;&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent03&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent03&quot; style=&quot;visibility: hidden;&quot;&gt;&quot;p&quot; cannot be initialized to &quot;new int&quot; since &quot;p&quot; is an integer pointer.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q4. &lt;br /&gt;
class Foo {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; char *buf;&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; Foo (char const * b = &quot;default&quot;) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; buf = new char[srd::strlen(b)+1];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; std::strcpy(buf, b);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; ~Foo() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete[] buf;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
Foo Func(Foo f) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; return f;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Referring to the code above, when the &quot;func&quot; is called, the program may crash or have any unexpected behaviour. What is the reason of this problem?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent04&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent04&quot; style=&quot;visibility: hidden;&quot;&gt;Try yourself&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
Q5. Find the o/p:&lt;br /&gt;
#include &amp;lt; cstudio &gt;&lt;br /&gt;
&lt;br /&gt;
cclass A {&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; A() { std::putchar(&#39;A); }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; ~A() { std::putchar(&#39;~); std::putchar(&#39;A); }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class B {&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; B() { std::putchar(&#39;B); }&lt;br /&gt;
&amp;nbsp;&amp;nbsp; ~B() {std::putchar(&#39;~); std::putchar(&#39;B); }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
A a;&lt;br /&gt;
static B b;&lt;br /&gt;
int main() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; static B b; return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent05&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent05&quot; style=&quot;visibility: hidden;&quot;&gt;Try yourself...&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q6. &lt;br /&gt;
class A {&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; A() { std::memset(buf, 0, sizeof(buf)); }&lt;br /&gt;
&lt;br /&gt;
protected:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; char buf[256];&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
class B {&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; B(const A&amp; arg) : a(arg) {}  //Ctr1&lt;br /&gt;
&amp;nbsp;&amp;nbsp; B(const A&amp; arg) { a = arg;} //Ctr2&lt;br /&gt;
&lt;br /&gt;
protected:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; A a;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Consider the two constructors given for B in the sample. Only one of the constructors can be used because they have the same signature, which one?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent06&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent06&quot; style=&quot;visibility: hidden;&quot;&gt;Try yourself...&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q7. Choose the correct option:&lt;br /&gt;
&lt;br /&gt;
Mutable keyword can be applied to:&lt;br /&gt;
a) non-static data members of a class&lt;br /&gt;
b) non-const data members of a class&lt;br /&gt;
c) Both a and b&lt;br /&gt;
d) None of above&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent07&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent07&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
Try yourself...&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q8. Choose the correct option:&lt;br /&gt;
Objects have&lt;br /&gt;
a) Behaviour&lt;br /&gt;
b) State&lt;br /&gt;
c) both a and b&lt;br /&gt;
d) None&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent08&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent08&quot; style=&quot;visibility: hidden;&quot;&gt;You tell me...&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q9. The vtable entry for a pure virtual function in C++ is:&lt;br /&gt;
a) Zero&lt;br /&gt;
b) NULL&lt;br /&gt;
c) One&lt;br /&gt;
d) No entry in vtable&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent09&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent09&quot; style=&quot;visibility: hidden;&quot;&gt;Try yourself&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q10. Find the o/p of this:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; float *pf;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; pf = (float *) &amp;i;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; *pf = 100.00;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent10&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent10&quot; style=&quot;visibility: hidden;&quot;&gt;Runtime error&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q11. Can we declare a static function as virtual?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent11&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent11&quot; style=&quot;visibility: hidden;&quot;&gt;No.&lt;br /&gt;
The virtual function mechanism is used on the specific object that determines which virtual function to call. Since the static functions are not any way related to objects, they can not be declared as virtual.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q12. Is it compulsory to override a virtual function?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent12&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent12&quot; style=&quot;visibility: hidden;&quot;&gt;No.&lt;br /&gt;
If we do not override the virtual function in the derived class then the VTABLE of the derived class would contain the address of the base class virtual function.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q13.Can we get the typeid of void pointers?&lt;br /&gt;
&lt;p/&gt;&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent13&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent13&quot; style=&quot;visibility: hidden;&quot;&gt;No.&lt;br /&gt;
At runtime, type identification doesn&#39;t work with void pointers, because void * truly means no type information at all.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
&lt;script src=&quot;http://www.assoc-amazon.com/s/link-enhancer?tag=cques-20&amp;amp;o=1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://testyourprogrammingskills.blogspot.com/feeds/6662055749780766558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-your-c-programming-skills-part-1.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/6662055749780766558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/6662055749780766558'/><link rel='alternate' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-your-c-programming-skills-part-1.html' title='Test your C++ Programming skills Part 1'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4514516738910212028.post-1344763715702254547</id><published>2011-11-25T20:02:00.000-08:00</published><updated>2011-12-10T19:52:02.919-08:00</updated><title type='text'>Test your C Programming skills Part 4</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Custom ad */
google_ad_slot = &quot;2185810178&quot;;
google_ad_width = 728;
google_ad_height = 90;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script language=&quot;javascript&quot;&gt;
&lt;!--
var state = &#39;hidden&#39;;

function showhide(layer_ref) {
if (state == &#39;visible&#39;) {
state = &#39;hidden&#39;;
}
else {
state = &#39;visible&#39;;
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( &quot;document.all.&quot; + layer_ref + &quot;.style.visibility = state&quot;);
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById &amp;&amp; !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Q1. How scanf will execute?&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; char name[10],s[12];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; scanf(&quot; \&quot;%[^\&quot;]\&quot;&quot;,s);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent01&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent01&quot; style=&quot; visibility: hidden;&quot;&gt;First it checks for the leading white space and discards it.Then it matches&lt;br /&gt;
with a quotation mark and then it reads all character upto another quotation mark.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q2. What will be the position of the file marker?&lt;br /&gt;
&lt;br /&gt;
a) fseek(ptr,0,SEEK_SET);&lt;br /&gt;
&lt;br /&gt;
b) fseek(ptr,0,SEEK_CUR);&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent02&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent02&quot; style=&quot;visibility: hidden;&quot;&gt;a) The SEEK_SET sets the file position marker to the starting of the file.&lt;br /&gt;
b) The SEEK_CUR sets the file position marker to the current position of the file.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q3. What is the problem with the following code segment?&lt;br /&gt;
&lt;br /&gt;
while ((fgets(receiving array,50,file_ptr)) != EOF)&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent03&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent03&quot; style=&quot;visibility: hidden;&quot;&gt;fgets returns a pointer. So the correct end of file check is checking for !=&lt;br /&gt;
&lt;br /&gt;
NULL.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q4. Find the o/p:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; char *cptr,c;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; void *vptr,v;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; c=10; v=0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; cptr=&amp;c; vptr=&amp;v;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%c%v&quot;,c,v);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent04&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent04&quot; style=&quot;visibility: hidden;&quot;&gt;Compiler error (at line number 4): size of v is Unknown.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
You can create a variable of type void * but not of type void, since void is&lt;br /&gt;
an empty type. In the second line you are creating variable vptr of type void * and&lt;br /&gt;
v of type void hence an error.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
Q5. Find the o/p:&lt;br /&gt;
#define max 5&lt;br /&gt;
&lt;br /&gt;
#define int arr1[max]&lt;br /&gt;
&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; typedef char arr2[max];&lt;br /&gt;
&amp;nbsp;&amp;nbsp; arr1 list={0,1,2,3,4};&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; arr2 name=&quot;name&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d %s&quot;,list[0],name);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent05&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent05&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
Compiler error (in the line arr1 list = {0,1,2,3,4})&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
arr2 is declared of type array of size 5 of characters. So it can be used to&lt;br /&gt;
declare the variable name of the type arr2. But it is not the case of arr1. Hence an&lt;br /&gt;
&lt;br /&gt;
Rule of Thumb:&lt;br /&gt;
#defines are used for textual replacement whereas typedefs are used for&lt;br /&gt;
declaring new types.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q6. Find the o/p:&lt;br /&gt;
int i=10;&lt;br /&gt;
&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; extern int i; {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i=20;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i=30;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,i);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,i);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,i);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent06&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent06&quot; style=&quot;visibility: hidden;&quot;&gt;30,20,10&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
&#39;{&#39; introduces new block and thus new scope. In the innermost block i is&lt;br /&gt;
declared as, const volatile unsigned which is a valid declaration. i is assumed of&lt;br /&gt;
type int. So printf prints 30. In the next block, i has value 20 and so printf prints&lt;br /&gt;
20. In the outermost block, i is declared as extern, so no storage space is allocated&lt;br /&gt;
for it. After compilation is over the linker resolves it to global variable i (since it&lt;br /&gt;
is the only variable visible there). So it prints i&#39;s value as 10.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q7. Find the o/p:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int *j;{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i=10;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j=&amp;i;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,*j);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent07&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent07&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
The variable i is a block level variable and the visibility is inside that&lt;br /&gt;
block only. But the lifetime of i is lifetime of the function so it lives upto the exit&lt;br /&gt;
of main function. Since the i is still allocated space, *j prints the value stored in i&lt;br /&gt;
since j points i.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q8. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
const int i=4;&lt;br /&gt;
&lt;br /&gt;
float j;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; j = ++i;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d %f&quot;, i,++j);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent08&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent08&quot; style=&quot;visibility: hidden;&quot;&gt;Compiler error&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
i is a constant. you cannot change the value of constant&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q9. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
int i=_l_abc(10);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d\n&quot;,--i);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int _l_abc(int i) {&lt;br /&gt;
&lt;br /&gt;
return(i++);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent09&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent09&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
return(i++) it will first return i and then increments. i.e. 10 will be&lt;br /&gt;
returned.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q10. Find the o/p of this:&lt;br /&gt;
main(int argc, char **argv) {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;enter the character&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; getchar();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; sum(argv[1],argv[2]);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sum(num1,num2)int num1,num2; {&lt;br /&gt;
&lt;br /&gt;
return num1+num2;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent10&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent10&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
Explanation:&lt;br /&gt;
argv[1] &amp; argv[2] are strings. They are passed to the function sum without&lt;br /&gt;
converting it to integer values.&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q11. Find the o/p:&lt;br /&gt;
int one_d[]={1,2,3};&lt;br /&gt;
&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
int *ptr;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; ptr=one_d;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; ptr+=3;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,*ptr);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent11&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent11&quot; style=&quot;visibility: hidden;&quot;&gt;garbage value&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
ptr pointer is pointing to out of the array range of one_d.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q12. Find the o/p:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
FILE *ptr;&lt;br /&gt;
char i;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; ptr=fopen(&quot;zzz.c&quot;,&quot;r&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; while((i=fgetch(ptr))!=EOF)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; printf(&quot;%c&quot;,i);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent12&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent12&quot; style=&quot;visibility: hidden;&quot;&gt;contents of zzz.c followed by an infinite loop&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
The condition is checked against EOF, it should be checked against&lt;br /&gt;
NULL.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q13.Find the o/p:&lt;br /&gt;
int i;&lt;br /&gt;
&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
int t;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for ( t=4;scanf(&quot;%d&quot;,&amp;i)-t;printf(&quot;%d\n&quot;,i))&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; printf(&quot;%d--&quot;,t--);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// If the inputs are 0,1,2,3 find the o/p&lt;br /&gt;
&lt;p/&gt;&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent13&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent13&quot; style=&quot;visibility: hidden;&quot;&gt;4--0&lt;br /&gt;
&lt;br /&gt;
3--1&lt;br /&gt;
&lt;br /&gt;
2--2&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
&lt;script src=&quot;http://www.assoc-amazon.com/s/link-enhancer?tag=cques-20&amp;amp;o=1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://testyourprogrammingskills.blogspot.com/feeds/1344763715702254547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-you-c-programming-skills-part-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/1344763715702254547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/1344763715702254547'/><link rel='alternate' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-you-c-programming-skills-part-4.html' title='Test your C Programming skills Part 4'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4514516738910212028.post-7625938597771991889</id><published>2011-11-25T19:37:00.000-08:00</published><updated>2011-12-10T19:52:19.314-08:00</updated><title type='text'>Test your C Programming skills Part 3</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Custom ad */
google_ad_slot = &quot;2185810178&quot;;
google_ad_width = 728;
google_ad_height = 90;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script language=&quot;javascript&quot;&gt;
&lt;!--
var state = &#39;hidden&#39;;

function showhide(layer_ref) {
if (state == &#39;visible&#39;) {
state = &#39;hidden&#39;;
}
else {
state = &#39;visible&#39;;
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( &quot;document.all.&quot; + layer_ref + &quot;.style.visibility = state&quot;);
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById &amp;&amp; !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Q1. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; char *p;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; p=&quot;Hello&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%c\n&quot;,*&amp;*p);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent01&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent01&quot; style=&quot; visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  H&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q2. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i=1;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; while (i&lt;=5){

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,i);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (i&gt;2)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i++;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
fun() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; here:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;PP&quot;);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent02&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent02&quot; style=&quot;visibility: hidden;&quot;&gt;Compiler error: Undefined label &#39;here&#39; in function main&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q3. Find the o/p:&lt;br /&gt;
void main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i=5;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,i++ + ++i);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent03&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent03&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  Output Cannot be predicted exactly.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  Explanation:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  Side effects are involved in the evaluation of i.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q4. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i=1,j=2;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; switch(i) {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; case 1: printf(&quot;GOOD&quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; case j: printf(&quot;BAD&quot;);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent04&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent04&quot; style=&quot;visibility: hidden;&quot;&gt;Compiler Error: Constant expression required in function main.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
The case statement can have only constant expressions (this implies that&lt;br /&gt;
we cannot use variable names directly so an error).&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
Enumerated types can be used in case statements.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
Q5. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,scanf(&quot;%d&quot;,&amp;i)); // value 10 is given as input here&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent05&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent05&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
Scanf returns number of items successfully read.Here 10 is given as input&lt;br /&gt;
which should have been scanned successfully. So number of items read is 1.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q6. Find the o/p:&lt;br /&gt;
#define f(g,g2) g##g2&lt;br /&gt;
&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int var12=100;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,f(var,12));&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent06&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent06&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q7. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i=0;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for(;i++;printf(&quot;%d&quot;,i)) ;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent07&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent07&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q8. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;, out);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int out=100;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent08&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent08&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compiler error: undefined symbol out in function main.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
The rule is that a variable is available for use from the point of declaration.&lt;br /&gt;
Even though a is a global variable, it is not available for main. Hence an error.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q9. Find the o/p:&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; extern out;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;, out);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int out=100;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent09&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent09&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
This is the correct way of writing the previous program.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q10. Find the o/p of this:&lt;br /&gt;
main( ) {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int a[ ] = {10,20,30,40,50},j,*p;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for(j=0; j&lt;5; j++){

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(“%d” ,*;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a++;

&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp; p = a;

&amp;nbsp;&amp;nbsp; for(j=0; j&lt;5; j++){

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(“%d ” ,*p);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p++;

&amp;nbsp;&amp;nbsp; }

}

&lt;p&gt;&lt;br /&gt;
 &lt;/p&gt;&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent10&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent10&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
Compiler error: lvalue required.&lt;br /&gt;
&lt;br /&gt;
Explanation:&lt;br /&gt;
Error is in line with statement a++. The operand must be an lvalue and may be of any of&lt;br /&gt;
scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q11. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; static char *s[ ] = {“black”, “white”, “yellow”, “violet”};&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; p = ptr;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; **++p;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; printf(“%s”,*--*++p + 3);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent11&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent11&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ck&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q12. Find the o/p:&lt;br /&gt;
main() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp; int i,j;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; for(i=0;i&lt;=10;i++){

&amp;nbsp;&amp;nbsp; j+=5;

&amp;nbsp;&amp;nbsp; assert(i&lt;5);

}

&lt;p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent12&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent12&quot; style=&quot;visibility: hidden;&quot;&gt;Runtime error: Abnormal program termination.&lt;br /&gt;
&lt;br /&gt;
Explaination:&lt;br /&gt;
assert failed (i&lt;5), &lt;file name&gt;,&lt;line number&gt;&lt;br /&gt;
asserts are used during debugging to make sure that certain conditions are&lt;br /&gt;
satisfied. If assertion fails, the program will terminate reporting the same. After&lt;br /&gt;
debugging use,&lt;br /&gt;
&lt;br /&gt;
#undef NDEBUG&lt;br /&gt;
&lt;br /&gt;
and this will disable all the assertions from the source code. Assertion is a&lt;br /&gt;
good debugging tool to make use of.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q13.What are the files which are automatically opened when a C file is executed?&lt;br /&gt;
&lt;p/&gt;&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent13&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent13&quot; style=&quot;visibility: hidden;&quot;&gt;stdin, stdout, stderr (standard input,standard output,standard error).&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;http://www.assoc-amazon.com/s/link-enhancer?tag=cques-20&amp;amp;o=1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://testyourprogrammingskills.blogspot.com/feeds/7625938597771991889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-your-c-skills-part-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/7625938597771991889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/7625938597771991889'/><link rel='alternate' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-your-c-skills-part-3.html' title='Test your C Programming skills Part 3'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4514516738910212028.post-3476139929212211868</id><published>2011-11-25T18:19:00.000-08:00</published><updated>2011-12-10T19:52:34.210-08:00</updated><title type='text'>Test your C Programming skills Part 2</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Custom ad */
google_ad_slot = &quot;2185810178&quot;;
google_ad_width = 728;
google_ad_height = 90;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script language=&quot;javascript&quot;&gt;
&lt;!--
var state = &#39;hidden&#39;;

function showhide(layer_ref) {
if (state == &#39;visible&#39;) {
state = &#39;hidden&#39;;
}
else {
state = &#39;visible&#39;;
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( &quot;document.all.&quot; + layer_ref + &quot;.style.visibility = state&quot;);
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById &amp;&amp; !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Q1. How would you declare a pointer variable ptr so that it can not be used to modify the string it points to (although ptr itself can be changed to point to some other string)? &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent01&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent01&quot; style=&quot; visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  char * const ptr = &quot;Hello&quot;;&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q2. How are the string literals are processed by compiler?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent02&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent02&quot; style=&quot;visibility: hidden;&quot;&gt;String literals are allocated in data area that may be read-only.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q3. &lt;br /&gt;
int a[25];&lt;br /&gt;
int * p = a + 3;&lt;br /&gt;
&lt;br /&gt;
Which one of the following is equivalent to the above code snippet?&lt;br /&gt;
a) int a[25]; &lt;br /&gt;
int *p = &amp;a[3];&lt;br /&gt;
&lt;br /&gt;
b) int a[25];&lt;br /&gt;
int * p = &amp;(a + 3);&lt;br /&gt;
&lt;br /&gt;
c) int a[25];&lt;br /&gt;
int * p = (&amp;a)[3];&lt;br /&gt;
&lt;br /&gt;
d) int a[25];&lt;br /&gt;
int * p = &amp;a[2];&lt;br /&gt;
&lt;br /&gt;
e) int a[25];&lt;br /&gt;
int * p = a[3];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent03&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent03&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  e)&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q4. How would you declare a constant pointer to a constant string?&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent04&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent04&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; const char * const ptr;&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
Q5. Find the o/p:&lt;br /&gt;
int divider(double m, double n)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m/n;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;, divider(10/3);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent05&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent05&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q6. Find the o/p:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct xx{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char name[]=&quot;hello&quot;;&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct xx *s;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%s&quot;,s-&gt;name);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent06&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent06&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compiler Error&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Explanation:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; You should not initialize variables in structure declaration.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q7. Find the o/p:&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int const *p=5;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,++(*p));&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent07&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent07&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compiler error: Cannot modify a constant value.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q8. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; float me = 1.1;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; double you = 1.1;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(me==you)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;I love U&quot;);&lt;br /&gt;
&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;&amp;nbsp;&amp;nbsp; printf(&quot;I hate U&quot;);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent08&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent08&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I hate U&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q9. Find the o/p:&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
main() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static int var = 5;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d &quot;,var--);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(var)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; main();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent09&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent09&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5 4 3 2 1 &lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q10. Find the o/p of this:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extern int i;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=20;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d&quot;,i);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent10&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent10&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Linker Error : Undefined symbol &#39;_i&#39;&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q11. Find the o/p:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *p;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%d %d &quot;,sizeof(*p),sizeof(p));&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent11&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent11&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 4&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q12. Find the o/p:&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char string[]=&quot;Hello World&quot;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; display(string);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void display(char *string){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;%s&quot;,string);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent12&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent12&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Compiler Error : Type mismatch in redeclaration of function display&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q13. What is output?&lt;br /&gt;
main(){&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i=10;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=!i&gt;14;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;i=%d&quot;,i);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;p/&gt;&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent13&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent13&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=0&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
&lt;script src=&quot;http://www.assoc-amazon.com/s/link-enhancer?tag=cques-20&amp;amp;o=1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://testyourprogrammingskills.blogspot.com/feeds/3476139929212211868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-your-cc-programming-skills-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/3476139929212211868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/3476139929212211868'/><link rel='alternate' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/11/test-your-cc-programming-skills-part-2.html' title='Test your C Programming skills Part 2'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4514516738910212028.post-5098579878216333349</id><published>2011-05-26T01:48:00.000-07:00</published><updated>2011-12-10T19:56:42.038-08:00</updated><title type='text'>Test your C Programming skills Part 1</title><content type='html'>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;ca-pub-7390990723809521&quot;;
/* Custom ad */
google_ad_slot = &quot;2185810178&quot;;
google_ad_width = 728;
google_ad_height = 90;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script language=&quot;javascript&quot;&gt;
&lt;!--
var state = &#39;hidden&#39;;

function showhide(layer_ref) {
if (state == &#39;visible&#39;) {
state = &#39;hidden&#39;;
}
else {
state = &#39;visible&#39;;
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( &quot;document.all.&quot; + layer_ref + &quot;.style.visibility = state&quot;);
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById &amp;&amp; !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Q1. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char *ptr=&quot;hello&quot;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char ary[]=&quot;world&quot;;&lt;br /&gt;
&lt;br /&gt;
printf(&quot;PTR: &amp;amp;ptr=%x, ptr=%x, *ptr=%x, ptr[0]=%x\n&quot;, &amp;amp;ptr,ptr, *ptr, ptr[0]); &lt;br /&gt;
printf(&quot;ARY: &amp;amp;ary=%x,ary=%x, *ary=%x, ary[0]=%x\n&quot;, &amp;amp;ary, ary, *ary, ary[0]); &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent01&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent01&quot; style=&quot; visibility: hidden;&quot;&gt;PTR: &amp;amp;ptr=bfb86990, ptr=8048524, *ptr=68, ptr[0]=68&lt;br /&gt;
ARY: &amp;amp;ary=bfb8698a,ary=bfb8698a, *ary=77, ary[0]=77&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q2. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char a; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int b;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short c;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node next;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }n1;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
printf(&quot;Ans1:%d\n&quot;, sizeof(n1));&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent02&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent02&quot; style=&quot;visibility: hidden;&quot;&gt;This program will not compiler.&lt;br /&gt;
Reason: The compiler can&#39;t figure out the space needed for the structure n1.&lt;br /&gt;
[kongkond@jorhat ~]$ gcc Q2.c&lt;br /&gt;
Q2.c: In function ‘main’:&lt;br /&gt;
Q2.c:7: error: field ‘next’ has incomplete type&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q3. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char a; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int b;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; short c;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct node *next;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }n1;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
printf(&quot;Ans1:\n\t node=%x\n \t node+2=%x\n&quot;, (char *)&amp;amp;n1, (char *)&amp;amp;n1+2);&lt;br /&gt;
printf(&quot;Ans2:%d\n&quot;, sizeof(n1));&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent03&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent03&quot; style=&quot;visibility: hidden;&quot;&gt;Ans1:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;node=bfcc5c94&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;node+2=bfcc5c96&lt;br /&gt;
Ans2:16&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q4. What is the difference between fopen() and open()? When do you choose to use one over the other?&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent04&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent04&quot; style=&quot;visibility: hidden;&quot;&gt;FILE * fopen(const char *restrict filename, const char *restrict mode);&lt;br /&gt;
--Upon successful completion fopen() returns a FILE pointer.&amp;nbsp; Otherwise, NULL is returned and the global variable errno is set to indicate the error.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int open(const char *pathname, int flags);&lt;br /&gt;
int open(const char *pathname, int flags, mode_t mode);&lt;br /&gt;
--Given a pathname for a file, open() returns a file descriptor, a small, non-negative integer for use in subsequent system calls (read(2), write(2), lseek(2), fcntl(2), etc.). The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process. &lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
Q5. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
if(!printf(&quot;Hello &quot;)){}&lt;br /&gt;
else&lt;br /&gt;
printf(&quot;World!&quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent05&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent05&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
Hello World!&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q6. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
struct i{&lt;br /&gt;
int a; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
double b; &amp;nbsp; &amp;nbsp;//8&lt;br /&gt;
char * c; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
char d[7]; &amp;nbsp; &amp;nbsp;//8&lt;br /&gt;
short e; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
int f; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
};&lt;br /&gt;
printf(&quot;sizeof(i)= %d&quot;, sizeof(struct i));&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent06&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent06&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;4+8+4+8+4+4=32&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q6.1. Find the o/p:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
struct i{&lt;br /&gt;
int a; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
double b; &amp;nbsp; &amp;nbsp;//8&lt;br /&gt;
char * c; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
char d[3]; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
short e; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
int f; &amp;nbsp; &amp;nbsp;//4&lt;br /&gt;
};&lt;br /&gt;
printf(&quot;sizeof(i)= %d&quot;, sizeof(struct i));&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent061&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent061&quot; style=&quot;visibility: hidden;&quot;&gt;&amp;nbsp;4+8+4+4+4+4=28&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;br /&gt;
Q7. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(NULL) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent07&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent07&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;gt; ./a.out&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q8. Find the o/p:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = 0;&lt;br /&gt;
printf(i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent08&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent08&quot; style=&quot;visibility: hidden;&quot;&gt;In newer gcc compiler this will not compile. In older ones:&lt;br /&gt;
&amp;gt; ./a.out&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But,&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = 0;&lt;br /&gt;
printf(&quot;%f\n&quot;, i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Ans: random number like:&lt;br /&gt;
-0.008430&lt;br /&gt;
&lt;br /&gt;
And the result of the following will be like this:&lt;br /&gt;
# include &amp;lt; stdio.h &amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = 0;&lt;br /&gt;
printf(&quot;%f %d\n&quot;, i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
Ans:random number like:&lt;br /&gt;
-0.008430 &amp;nbsp; 134513785&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q9. Find the o/p:&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;%s&quot;,NULL) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent09&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent09&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
&amp;gt; ./a.out&lt;br /&gt;
(null)&lt;br /&gt;
&lt;br /&gt;
But,&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
int i = -10;&lt;br /&gt;
printf(&quot;%s\n&quot;,i) ;&lt;br /&gt;
return ;&lt;br /&gt;
}&lt;br /&gt;
will result in &quot;Segmentation fault&quot; if the value of i is other than zero.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q10. Find the o/p of this last one:&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;%%&quot;,7);&lt;br /&gt;
}&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent10&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent10&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;br /&gt;
Try yourself&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q11. How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent11&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent11&quot; style=&quot;visibility: hidden;&quot;&gt;Well, first you need to know how to declare an array of N items of type T - that&#39;s&lt;br /&gt;
&lt;br /&gt;
T foo[N];&lt;br /&gt;
&lt;br /&gt;
Now you need to look at how to declare a pointer to function returning something, say, an object of type S. That&#39;s like this:&lt;br /&gt;
&lt;br /&gt;
S (*bar)();&lt;br /&gt;
&lt;br /&gt;
Now assume that S is ``pointer to function returning pointer to char&#39;&#39;. We get&lt;br /&gt;
&lt;br /&gt;
(char *) (*)() (*bar)().&lt;br /&gt;
&lt;br /&gt;
So, the whole thing turns out to be (with appropriate parentheses)&lt;br /&gt;
&lt;br /&gt;
(((char)(*))((*)())(((*)((foo)))())([(N)]));&lt;br /&gt;
&lt;br /&gt;
If your compiler complains, break this down into subexpressions.&lt;br /&gt;
&lt;br /&gt;
To call it, just use&lt;br /&gt;
&lt;br /&gt;
foo[i]();&lt;br /&gt;
&lt;br /&gt;
This works because, in C, declaration reflects use, but it&#39;s one of those weird distorted mirrors.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q12. What is asmlinkage and what is it&#39;s use?&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent12&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent12&quot; style=&quot;visibility: hidden;&quot;&gt;&quot;asmlinkage&quot; is defined, for example, in the header file&lt;br /&gt;
&quot;include/asm-i386/linkage.h&quot; as&lt;br /&gt;
__attribute__((regparm(0)))&lt;br /&gt;
that tells compiler put all function parameters in the stack (i.e.&lt;br /&gt;
disables call optimization). &lt;br /&gt;
In simple terms, a) you are using assembly code using asmlinkage, and b) all the function parameters are pushed into the stack and optimization is disabled for this purpose.&lt;br /&gt;
For more details check this &lt;a href=&quot;http://kernelnewbies.org/FAQ/asmlinkage&quot;&gt;link&lt;/a&gt;.&lt;br /&gt;
&lt;/div&gt;&lt;hr /&gt;&lt;br /&gt;
Q13. What is output?&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
printf(&quot;%x&quot;,-1&lt;&lt;4);
}
&lt;p/&gt;&lt;br /&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;showhide(&#39;agent13&#39;);&quot;&gt;Ans: &lt;/a&gt;&lt;br /&gt;
&lt;div id=&quot;agent13&quot; style=&quot;visibility: hidden;&quot;&gt;[root@monday kongkon]# gcc 2.c&lt;br /&gt;
2.c: In function âmainâ:&lt;br /&gt;
2.c:3: warning: incompatible implicit declaration of built-in function âprintfâ&lt;br /&gt;
[root@monday kongkon]# ./a.out&lt;br /&gt;
fffffff0[root@monday kongkon]#&lt;br /&gt;
&lt;br /&gt;
(1)10=(0000 0000 0000 0001)2&lt;br /&gt;
(-1)10=(2&#39;s complement of binary 1)=(1&#39;s complement of 1 added with 1) =(1111 1111 1111 1110 + 1 )2=(1111 1111 1111 1111)2&lt;br /&gt;
Now,&lt;br /&gt;
(-1)10 &lt;&lt; 4 = (1111 1111 1111 0000)2=(F F F 0)16
Note: In Computer, Negative numbers are represented in 2&#39;s complement form, which is 1&#39;s complement +1.

&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
&lt;script src=&quot;http://www.assoc-amazon.com/s/link-enhancer?tag=cques-20&amp;amp;o=1&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://testyourprogrammingskills.blogspot.com/feeds/5098579878216333349/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/05/q1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/5098579878216333349'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4514516738910212028/posts/default/5098579878216333349'/><link rel='alternate' type='text/html' href='http://testyourprogrammingskills.blogspot.com/2011/05/q1.html' title='Test your C Programming skills Part 1'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/13775194780909673988</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>