<?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-8666171843124727263</id><updated>2024-11-01T03:43:11.601-07:00</updated><category term="Advanced"/><category term="C"/><category term="C interview questions"/><category term="Concepts"/><category term="Interview questions"/><category term="c advanced concepts"/><category term="c for geeks"/><category term="questions asked in tally interview"/><category term="files"/><category term="libraries"/><category term="macros"/><category term="preprocessor"/><title type='text'>C for Geeks</title><subtitle type='html'>For all C lovers and geeks</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>56</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-5635964488400076543</id><published>2013-11-17T01:07:00.002-08:00</published><updated>2013-11-17T01:07:54.931-08:00</updated><title type='text'>check if a number is of 2&#39;s power</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
It is generally asked in interviews to check if a number can be converted into 2&#39;s power or not.&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For e.g&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
8= 2^3&lt;/div&gt;
&lt;div&gt;
16=2^4&lt;/div&gt;
&lt;div&gt;
and so on...&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now if we solve this program without bit manipulation operators,&lt;/div&gt;
&lt;div&gt;
It will be difficult to solve it.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Hint:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
IF a number is of 2&#39;s power, then its binary representation will have only one 1.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
e.g 16= 10000&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 8 = 1000&lt;/div&gt;
&lt;div&gt;
and you may check for any number.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now the problem is, how to implement this logic.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
let say our number is 16,&lt;/div&gt;
&lt;div&gt;
then&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;binary of 16= 10000&lt;/div&gt;
&lt;div&gt;
and&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
binary of 15= 01111&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
16 &amp;amp; 15 = 00000&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This result is only possible when number is of 2&#39;s power.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So generalized concept is&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;x = number &amp;amp; (number-1)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
if(x==0)&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
printf(&quot;number is of 2&#39;s power&quot;);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
else&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;printf(&quot;Tata bye bye.&quot;);&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Cheers !!!!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/5635964488400076543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2013/11/check-if-number-is-of-2s-power.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5635964488400076543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5635964488400076543'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2013/11/check-if-number-is-of-2s-power.html' title='check if a number is of 2&#39;s power'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-1279035520161280300</id><published>2012-10-31T02:18:00.003-07:00</published><updated>2012-10-31T02:21:07.436-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="files"/><category scheme="http://www.blogger.com/atom/ns#" term="libraries"/><category scheme="http://www.blogger.com/atom/ns#" term="macros"/><category scheme="http://www.blogger.com/atom/ns#" term="preprocessor"/><title type='text'>C Preprocessor directives</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;he C preprocessor modifies a source code file before handing it over to the compiler. You&#39;re most likely used to using the preprocessor to include files directly into other files, or #define constants, but the preprocessor can also be used to create &quot;inlined&quot; code using macros expanded at compile time and to prevent code from being compiled twice.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;center style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;
&lt;div class=&quot;noprint&quot;&gt;
&lt;div id=&quot;google_ads_div_RunOfSite_LargeRectangle_ATF_336x280_ad_wrapper&quot;&gt;
&lt;div id=&quot;google_ads_div_RunOfSite_LargeRectangle_ATF_336x280_ad_container&quot; style=&quot;display: inline-block;&quot;&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/center&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;There are essentially three uses of the preprocessor--directives, constants, and macros. Directives are commands that tell the preprocessor to skip part of a file, include another file, or define a constant or macro. Directives always begin with a sharp sign (#) and for readability should be placed flush to the left of the page. All other uses of the preprocessor involve processing #define&#39;d constants or macros. Typically, constants and macros are written in ALL CAPS to indicate they are special (as we will see).&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Header Files&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;The #include directive tells the preprocessor to grab the text of a file and place it directly into the current file. Typically, such statements are placed at the top of a program--hence the name &quot;header file&quot; for files thus included.&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Constants&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;If we write&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define [identifier name] [value]
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;whenever [identifier name] shows up in the file, it will be replaced by [value].&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;If you are defining a constant in terms of a mathematical expression, it is wise to surround the entire value in parentheses:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define PI_PLUS_ONE (3.14 + 1)
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;By doing so, you avoid the possibility that an order of operations issue will destroy the meaning of your constant:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;x = PI_PLUS_ONE * 5;
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Without parentheses, the above would be converted to&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;x = 3.14 + 1 * 5;
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;which would result in 1 * 5 being evaluated before the addition, not after. Oops!&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;It is also possible to write simply&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define [identifier name]
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;which defines [identifier name] without giving it a value. This can be useful in conjunction with another set of directives that allow conditional compilation.&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Conditional Compilation&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;There are a whole set of options that can be used to determine whether the preprocessor will remove lines of code before handing the file to the compiler. They include #if, #elif, #else, #ifdef, and #ifndef. An #if or #if/#elif/#else block or a #ifdef or #ifndef block must be terminated with a closing #endif.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;The #if directive takes a numerical argument that evaluates to true if it&#39;s non-zero. If its argument is false, then code until the closing #else, #elif, of #endif will be excluded.&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Commenting out Code&lt;/h3&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Conditional compilation is a particularly useful way to comment out a block of code that contains multi-line comments (which cannot be nested).&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#if 0
/* comment ...
*/

// code

/* comment */
#endif
&lt;/pre&gt;
&lt;h3 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Include Guards&lt;/h3&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Another common problem is that a header file is required in multiple other header files that are later included into a source code file, with the result often being that variables, structs, classes or functions appear to be defined multiple times (once for each time the header file is included). This can result in a lot of compile-time headaches. Fortunately, the preprocessor provides an easy technique for ensuring that any given file is included once and only once.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;By using the #ifndef directive, you can include a block of text only if a particular expression is undefined; then, within the header file, you can define the expression. This ensures that the code in the #ifndef is included only the first time the file is loaded.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#ifndef _FILE_NAME_H_
#define _FILE_NAME_H_

/* code */

#endif // #ifndef _FILE_NAME_H_
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Notice that it&#39;s not necessary to actually give a value to the expression _FILE_NAME_H_. It&#39;s sufficient to include the line &quot;#define _FILE_NAME_H_&quot; to make it &quot;defined&quot;. (Note that there is an&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;n&lt;/b&gt;&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;&amp;nbsp;in #ifndef--it stands for &quot;if not defined&quot;).&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;A similar tactic can be used for defining specific constants, such as NULL:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#ifndef NULL
#define NULL (void *)0
#endif // #ifndef NULL
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Notice that it&#39;s useful to comment which conditional statement a particular #endif terminates. This is particularly true because preprocessor directives are rarely indented, so it can be hard to follow the flow of execution.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Macros&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;The other major use of the preprocessor is to define macros. The advantage of a macro is that it can be type-neutral (this can also be a disadvantage, of course), and it&#39;s inlined directly into the code, so there isn&#39;t any function call overhead. (Note that in C++, it&#39;s possible to get around both of these issues with templated functions and the inline keyword.)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;A macro definition is usually of the following form:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define MACRO_NAME(arg1, arg2, ...) [code to expand to]
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;For instance, a simple increment macro might look like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define INCREMENT(x) x++
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;They look a lot like function calls, but they&#39;re not so simple. There are actually a couple of tricky points when it comes to working with macros. First, remember that the exact text of the macro argument is &quot;pasted in&quot; to the macro. For instance, if you wrote something like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define MULT(x, y) x * y
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;and then wrote&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;int z = MULT(3 + 2, 4 + 2);
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;what value do you expect z to end up with? The obvious answer, 30, is wrong! That&#39;s because what happens when the macro MULT expands is that it looks like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;int z = 3 + 2 * 4 + 2;    // 2 * 4 will be evaluated first!
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;So z would end up with the value 13! This is almost certainly not what you want to happen. The way to avoid it is to force the arguments themselves to be evaluated before the rest of the macro body. You can do this by surrounding them by parentheses in the macro definition:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define MULT(x, y) (x) * (y)
// now MULT(3 + 2, 4 + 2) will expand to (3 + 2) * (4 + 2)
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;But this isn&#39;t the only gotcha! It is also generally a good idea to surround the macro&#39;s code in parentheses if you expect it to return a value. Otherwise, you can get similar problems as when you define a constant. For instance, the following macro, which adds 5 to a given argument, has problems when embedded within a larger statement:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define ADD_FIVE(a) (a) + 5

int x = ADD_FIVE(3) * 3;
// this expands to (3) + 5 * 3, so 5 * 3 is evaluated first
// Now x is 18, not 24!
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;To fix this, you generally want to surround the whole macro body with parentheses to prevent the surrounding context from affecting the macro body.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define ADD_FIVE(a) ((a) + 5)

int x = ADD_FIVE(3) * 3;
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;On the other hand, if you have a multiline macro that you are using for its side effects, rather than to compute a value, you probably want to wrap it within curly braces so you don&#39;t have problems when using it following an if statement.&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;// We use a trick involving exclusive-or to swap two variables
#define SWAP(a, b)  a ^= b; b ^= a; a ^= b; 

int x = 10;
int y = 5;

// works OK
SWAP(x, y);

// What happens now?
if(x &amp;lt; 0)
    SWAP(x, y);
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;When SWAP is expanded in the second example, only the first statement, a ^= b, is governed by the conditional; the other two statements will always execute. What we really meant was that all of the statements should be grouped together, which we can enforce using curly braces:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define SWAP(a, b)  {a ^= b; b ^= a; a ^= b;} 
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Now, there is still a bit more to our story! What if you write code like so:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define SWAP(a, b)  { a ^= b; b ^= a; a ^= b; }

int x = 10;
int y = 5;
int z = 4;

// What happens now?
if(x &amp;lt; 0)
    SWAP(x, y);
else
    SWAP(x, z); 
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Then it will not compile because semicolon after the closing curly brace will break the flow between if and else. The solution? Use a do-while loop:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define SWAP(a, b)  do { a ^= b; b ^= a; a ^= b; } while ( 0 )

int x = 10;
int y = 5;
int z = 4;

// What happens now?
if(x &amp;lt; 0)
    SWAP(x, y);
else
    SWAP(x, z); 
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Now the semi-colon doesn&#39;t break anything because it is part of the expression. (By the way, note that we didn&#39;t surround the arguments in parentheses because we don&#39;t expect anyone to pass an expression into swap!)&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
More Gotchas&lt;/h3&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;By now, you&#39;ve probably realized why people don&#39;t really like using macros. They&#39;re dangerous, they&#39;re picky, and they&#39;re just not that safe. Perhaps the most irritating problem with macros is that you don&#39;t want to pass arguments with &quot;side effects&quot; to macros. By side effects, I mean any expression that does something besides evaluate to a value. For instance, ++x evaluates to x+1, but it also increments x. This increment operation is a side effect.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;The problem with side effects is that macros don&#39;t evaluate their arguments; they just paste them into the macro text when performing the substitution. So something like&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define MAX(a, b) ((a) &amp;lt; (b) ? (b) : (a))
int x = 5, y = 10;
int z = MAX(x++, y++);
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;will end up looking like this:&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;int x = (x++ &amp;lt; y++ ? y++ : x++)
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;The problem here is that y++ ends up being evaluated twice! The nasty consequence is that after this expression, y will have a value of 12 rather than the expected 11. This can be a real pain to debug!&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Multiline macros&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Until now, we&#39;ve seen only short, one line macros (possibly taking advantage of the semicolon to put multiple statements on one line.) It turns out that by using a the &quot;\&quot; to indicate a line continuation, we can write our macros across multiple lines to make them a bit more readable.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;For instance, we could rewrite swap as&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define SWAP(a, b)  {                   \
                        a ^= b;         \
                        b ^= a;         \ 
                        a ^= b;         \
                    } 
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Notice that you&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;do not&lt;/b&gt;&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;&amp;nbsp;need a slash at the end of the last line! The slash tells the preprocessor that the macro continues to the next line, not that the line is a continuation from a previous line.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Aside from readability, writing multi-line macros may make it more obvious that you need to use curly braces to surround the body because it&#39;s more clear that multiple effects are happening at once.&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Advanced Macro Tricks&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;In addition to simple substitution, the preprocessor can also perform a bit of extra work on macro arguments, such as turning them into strings or pasting them together.&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
Pasting Tokens&lt;/h3&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Each argument passed to a macro is a token, and sometimes it might be expedient to paste arguments together to form a new token. This could come in handy if you have a complicated structure and you&#39;d like to debug your program by printing out different fields. Instead of writing out the whole structure each time, you might use a macro to pass in the field of the structure to print.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;To paste tokens in a macro, use ## between the two things to paste together.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;For instance&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define BUILD_FIELD(field) my_struct.inner_struct.union_a.##field
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Now, when used with a particular field name, it will expand to something like&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;my_struct.inner_struct.union_a.field1
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;The tokens are literally pasted together.&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; font-family: verdana, sans-serif;&quot;&gt;
String-izing Tokens&lt;/h3&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;Another potentially useful macro option is to turn a token into a string containing the literal text of the token. This might be useful for printing out the token. The syntax is simple--simply prefix the token with a pound sign (#).&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;#define PRINT_TOKEN(token) printf(#token &quot; is %d&quot;, token)
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;For instance, PRINT_TOKEN(foo) would expand to&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;printf(&quot;&amp;lt;foo&amp;gt;&quot; &quot; is %d&quot; &amp;lt;foo&amp;gt;)
&lt;/pre&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;(Note that in C, string literals next to each other are concatenated, so something like &quot;token&quot; &quot; is &quot; &quot; this &quot; will effectively become &quot;token is this&quot;. This can be useful for formatting printf statements.)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot; /&gt;
&lt;span style=&quot;background-color: white; font-family: verdana, sans-serif; font-size: 12px;&quot;&gt;For instance, you might use it to print the value of an expression as well as the expression itself (for debugging purposes).&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;example&quot; style=&quot;background-color: #ffffcc; border: 1px dashed rgb(0, 0, 0); font-family: &#39;Courier New&#39;, Courier, mono; font-size: 12px; padding: 8px; width: auto;&quot;&gt;PRINT_TOKEN(x + y);&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/1279035520161280300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/10/c-preprocessor-directives.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/1279035520161280300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/1279035520161280300'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/10/c-preprocessor-directives.html' title='C Preprocessor directives'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6015423496990101057</id><published>2012-10-08T21:16:00.005-07:00</published><updated>2012-10-08T21:16:59.174-07:00</updated><title type='text'>Memset(),memcpy() and memmove() functions in c</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3&gt;
&lt;a href=&quot;http://www.blogger.com/null&quot; name=&quot;Heading10&quot;&gt;&lt;/a&gt;The memset() Function&lt;/h3&gt;
To set all the bytes in a block of memory to a particular value, use memset(). The function prototype is&lt;br /&gt;
&lt;pre&gt;void * memset(void *dest, int c, size_t &lt;i&gt;count&lt;/i&gt;);
&lt;/pre&gt;
The argument dest points to the block of memory. c is the value to set, and &lt;i&gt;count&lt;/i&gt; is the number of bytes, starting at dest, to be set. Note that while c is a type int, it is treated as a type char. In other words, only the low-order byte is used, and you can specify values of c only in the range 0 through 255.&lt;br /&gt;
Use memset() to initialize a block of memory to a specified value. Because this function can use only a type char as the initialization value, it is not useful for working with blocks of data types other than type char, except when you want to initialize to 0. In other words, it wouldn&#39;t be efficient to use memset() to initialize an array of type int to the value 99, but you could initialize all array elements to the value 0. memset() will be demonstrated in program below.&lt;br /&gt;
&lt;h3&gt;
&lt;a href=&quot;http://www.blogger.com/null&quot; name=&quot;Heading11&quot;&gt;&lt;/a&gt;The memcpy() Function&lt;/h3&gt;
memcpy() copies bytes of data between memory blocks, sometimes called &lt;i&gt;buffers&lt;/i&gt;. This function doesn&#39;t care about the type of data being copied--it simply makes an exact byte-for-byte copy. The function prototype is&lt;br /&gt;
&lt;pre&gt;void *memcpy(void *dest, void *src, size_t &lt;i&gt;count&lt;/i&gt;);
&lt;/pre&gt;
The arguments dest and src point to the destination and source memory blocks, respectively. &lt;i&gt;count&lt;/i&gt; specifies the number of bytes to be copied. The return value is dest. If the two blocks of memory overlap, the function might not operate properly--some of the data in src might be overwritten before being copied. Use the memmove() function, discussed next, to handle overlapping memory blocks. memcpy() will be demonstrated in program below.&lt;br /&gt;
&lt;h3&gt;
&lt;a href=&quot;http://www.blogger.com/null&quot; name=&quot;Heading12&quot;&gt;&lt;/a&gt;The memmove() Function&lt;/h3&gt;
memmove() is very much like memcpy(), copying a specified number of bytes from one memory block to another. It&#39;s more flexible, however, because it can handle overlapping memory blocks properly. Because memmove() can do everything memcpy() can do with the added flexibility of dealing with overlapping blocks, you rarely, if ever, should have a reason to use memcpy(). The prototype is&lt;br /&gt;
&lt;pre&gt;void *memmove(void *dest, void *src, size_t &lt;i&gt;count&lt;/i&gt;);
&lt;/pre&gt;
dest and src point to the destination and source memory blocks, and &lt;i&gt;count&lt;/i&gt; specifies the number of bytes to be copied. The return value is dest. If the blocks overlap, this function ensures that the source data in the overlapped region is copied before being overwritten. Sample program below demonstrates memset(), memcpy(), and memmove().&lt;br /&gt;
&lt;h4&gt;
A demonstration of memset(), memcpy(), and memmove().&lt;/h4&gt;
&lt;pre&gt;1: /* Demonstrating memset(), memcpy(), and memmove(). */
2:
3: #include &amp;lt;stdio.h&amp;gt;
4: #include &amp;lt;string.h&amp;gt;
4:
5: char message1[60] = &quot;Four score and seven years ago ...&quot;;
6: char message2[60] = &quot;abcdefghijklmnopqrstuvwxyz&quot;;
7: char temp[60];
8:
9: main()
10: {
11:    printf(&quot;\nmessage1[] before memset():\t%s&quot;, message1);
12:    memset(message1 + 5, `@&#39;, 10);
13:    printf(&quot;\nmessage1[] after memset():\t%s&quot;, message1);
14:
15:    strcpy(temp, message2);
16:    printf(&quot;\n\nOriginal message: %s&quot;, temp);
17:    memcpy(temp + 4, temp + 16, 10);
18:    printf(&quot;\nAfter memcpy() without overlap:\t%s&quot;, temp);
19:    strcpy(temp, message2);
20:    memcpy(temp + 6, temp + 4, 10);
21:    printf(&quot;\nAfter memcpy() with overlap:\t%s&quot;, temp);
22:
23:    strcpy(temp, message2);
24:    printf(&quot;\n\nOriginal message: %s&quot;, temp);
25:    memmove(temp + 4, temp + 16, 10);
26:    printf(&quot;\nAfter memmove() without overlap:\t%s&quot;, temp);
27:    strcpy(temp, message2);
28:    memmove(temp + 6, temp + 4, 10);
29:    printf(&quot;\nAfter memmove() with overlap:\t%s\n&quot;, temp);
30:
31: }
message1[] before memset():     Four score and seven years ago ...
message1[] after memset():      Four @@@@@@@@@@seven years ago ...
Original message: abcdefghijklmnopqrstuvwxyz
After memcpy() without overlap: abcdqrstuvwxyzopqrstuvwxyz
After memcpy() with overlap:    abcdefefefefefefqrstuvwxyz
Original message: abcdefghijklmnopqrstuvwxyz
After memmove() without overlap:        abcdqrstuvwxyzopqrstuvwxyz
After memmove() with overlap:   abcdefefghijklmnqrstuvwxyz
&lt;/pre&gt;
&lt;strong&gt;ANALYSIS: &lt;/strong&gt;The operation of memset() is straightforward. Note how the pointer notation message1 + 5 is used to specify that memset() is to start setting characters at the sixth character in message1[] (remember, arrays are zero-based). As a result, the 6th through 15th characters in message1[] have been changed to @.&lt;br /&gt;
When source and destination do not overlap, memcpy() works fine. The 10 characters of temp[] starting at position 17 (the letters q through z) have been copied to positions 5 though 14, where the letters e though n were originally located. If, however, the source and destination overlap, things are different. When the function tries to copy 10 characters starting at position 4 to position 6, an overlap of 8 positions occurs. You might expect the letters e through n to be copied over the letters g through p. Instead, the letters e and f are repeated five times.&lt;br /&gt;
If there&#39;s no overlap, memmove() works just like memcpy(). With overlap, however, memmove() copies the original source characters to the destination.&lt;br /&gt;
&lt;blockquote&gt;
&amp;nbsp; 
&lt;hr /&gt;
&lt;b&gt;DO&lt;/b&gt; use memmove() instead of memcpy() in case you&#39;re dealing with overlapping memory regions. 
&lt;b&gt;DON&#39;T&lt;/b&gt; try to use memset() to initialize type int, float, or double arrays to any value other than 0. &lt;/blockquote&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;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border-bottom: medium none; border-left: medium none; border-right: medium none; border-top: medium none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6015423496990101057/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/10/memsetmemcpy-and-memmove-functions-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6015423496990101057'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6015423496990101057'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/10/memsetmemcpy-and-memmove-functions-in-c.html' title='Memset(),memcpy() and memmove() functions in c'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6667559335674450018</id><published>2012-10-07T09:06:00.002-07:00</published><updated>2012-10-07T09:06:29.509-07:00</updated><title type='text'>Connect oracle with C/C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Interviewers often ask can you connect C/C++ with database or not?&lt;br /&gt;
It is tricky for those who haven&#39;t done it before.&lt;br /&gt;
But the answer is YES. We can connect it using a language Pro *C (or simply pro-C)&lt;br /&gt;
Here is the tutorial for doing it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span&gt;Overview&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Embedded SQL is a method of combining the computing power of a high-level language like C/C++ and the database manipulation capabilities of SQL. It allows you to execute any SQL statement from an application program. Oracle&#39;s embedded SQL environment is called Pro*C.&lt;/span&gt;A Pro*C program is compiled in two steps.&amp;nbsp; First, the Pro*C&amp;nbsp;&lt;i&gt;precompiler&lt;/i&gt;&amp;nbsp;recognizes the SQL statements embedded in the program, and replaces them with appropriate calls to the functions in the SQL runtime library. The output is pure C/C++ code with all the pure C/C++ portions intact. Then, a regular C/C++ compiler is used to compile the code and produces the executable.&lt;br /&gt;
&lt;h3&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;pro*c syntax&quot;&gt;&lt;/a&gt;&lt;span&gt;Pro*C Syntax&lt;/span&gt;&lt;/h3&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;sql&quot;&gt;&lt;/a&gt;SQL&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;All SQL statements need to start with&amp;nbsp;&lt;/span&gt;&lt;tt&gt;EXEC SQL&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;and end with a semicolon &quot;&lt;/span&gt;&lt;tt&gt;;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&quot;. You can place the SQL statements anywhere within a C/C++ block, with the restriction that the declarative statements do not come after the executable statements. As an example:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int a;
&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; EXEC SQL SELECT salary INTO :a
&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 Employee
&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; WHERE SSN=876543210;
&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; printf(&quot;The salary is %d\n&quot;, a);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;preprocessor directives&quot;&gt;&lt;/a&gt;Preprocessor Directives&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;The C/C++ preprocessor directives that work with Pro*C are&amp;nbsp;&lt;/span&gt;&lt;tt&gt;#include&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt&gt;#if&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;. Pro*C does not recognize&amp;nbsp;&lt;/span&gt;&lt;tt&gt;#define&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;. For example, the following code is invalid:&lt;/span&gt;&lt;pre&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #define THE_SSN 876543210
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL SELECT salary INTO :a
&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 Employee
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE SSN = THE_SSN;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* INVALID */&lt;/tt&gt;&lt;/pre&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;statement labels&quot;&gt;&lt;/a&gt;Statement Labels&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;You can connect C/C++ labels with SQL as in:&lt;/span&gt;&lt;pre&gt;&lt;tt&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL WHENEVER SQLERROR GOTO error_in_SQL;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ...&lt;/tt&gt; */
&lt;tt&gt;error_in_SQL:
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* do error handling */&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;&lt;h3&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;host variables&quot;&gt;&lt;/a&gt;&lt;span&gt;Host Variables&lt;/span&gt;&lt;/h3&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;basics&quot;&gt;&lt;/a&gt;Basics&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Host variables are the key to the communication between the host program and the database. A host variable expression must resolve to an&amp;nbsp;&lt;/span&gt;&lt;i&gt;lvalue&lt;/i&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;i&gt;i.e.&lt;/i&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, it can be assigned). You can declare host variables according to C syntax, as you declare regular C variables. The host variable declarations can be placed wherever C variable declarations can be placed. &lt;/span&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;The C datatypes that can be used with Oracle include:&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;char&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;char[&lt;/tt&gt;&lt;i&gt;n&lt;/i&gt;&lt;tt&gt;]&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;int&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;short&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;long&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;float&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;double&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;VARCHAR[&lt;/tt&gt;&lt;i&gt;n&lt;/i&gt;&lt;tt&gt;]&lt;/tt&gt;&amp;nbsp;- This is a psuedo-type recognized by the Pro*C precompiler. It is used to represent blank-padded, variable-length strings. Pro*C precompiler will convert it into a structure with a 2-byte length field and a&amp;nbsp;&lt;i&gt;n&lt;/i&gt;-byte character array.&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;You cannot use&amp;nbsp;&lt;/span&gt;&lt;tt&gt;register&lt;/tt&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;storage-class specifier for the host variables.&lt;/span&gt;A host variable reference must be prefixed with a colon &quot;&lt;tt&gt;:&lt;/tt&gt;&quot; in SQL statements, but should not be prefixed with a colon in C statements. When specifying a string literal via a host variable, the single quotes must be omitted; Pro*C understands that you are specifying a string based on the declared type of the host variable. C function calls and most of the pointer arithmetic expressions&amp;nbsp;&lt;i&gt;cannot&lt;/i&gt;&amp;nbsp;be used as host variable references even though they may indeed resolve to lvalues. The following code illustrates both legal and illegal host variable references:&lt;br /&gt;
&lt;pre&gt;int deptnos[3] = { 000, 111, 222 };
int get_deptno() { return deptnos[2]; }
int *get_deptnoptr() { return &amp;amp;(deptnos[2]); }
int main() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; int x; char *y; int z;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp(empno, ename, deptno)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES(:x, :y, :z);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* LEGAL */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp(empno, ename, deptno)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES(:x + 1,&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; /* LEGAL: the reference is to x */
&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; &#39;Big Shot&#39;,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* LEGAL: but not really a host var */
&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; :deptnos[2]);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* LEGAL: array element is fine */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp(empno, ename, deptno)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES(:x, :y,
&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; :(*(deptnos+2)));&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ILLEGAL: although it has an
lvalue */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp(empno, ename, deptno)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES(:x, :y,
&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; :get_deptno());&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ILLEGAL: no function calls */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp(empno, ename, deptno)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES(:x, :y,
&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; :(*get_depnoptr())); /* ILLEGAL: although it has an lvalue */
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
}&lt;/pre&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;pointers&quot;&gt;&lt;/a&gt;Pointers&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;You can define pointers using the regular C syntax, and use them in embedded SQL statements. As usual, prefix them with a colon:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int *x;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL SELECT xyz INTO :x FROM ...;&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;The result of this&amp;nbsp;&lt;/span&gt;&lt;tt&gt;SELECT&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;statement will be written into&amp;nbsp;&lt;/span&gt;&lt;tt&gt;*x&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, not&amp;nbsp;&lt;/span&gt;&lt;tt&gt;x&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;.&lt;/span&gt;&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;structures&quot;&gt;&lt;/a&gt;Structures&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Structures can be used as host variables, as illustrated in the following example:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; typedef struct {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char name[21];&amp;nbsp;&amp;nbsp;&amp;nbsp; /* one greater than column length; for &#39;\0&#39; */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int SSN;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } Emp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; Emp bigshot;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp (ename, eSSN)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES (:bigshot);&lt;/pre&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;arrays&quot;&gt;&lt;/a&gt;Arrays&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Host arrays can be used in the following way:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int emp_number[50];
&amp;nbsp;&amp;nbsp;&amp;nbsp; char name[50][11];
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO emp(emp_number, name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES (:emp_number, :emp_name);&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;which will insert all the 50 tuples in one go.&lt;/span&gt;Arrays can only be single dimensional. The example&amp;nbsp;&lt;tt&gt;char name[50][11]&lt;/tt&gt;&amp;nbsp;would seem to contradict that rule. However, Pro*C actually considers&amp;nbsp;&lt;tt&gt;name&lt;/tt&gt;&amp;nbsp;a one-dimensional array of strings rather than a two-dimensional array of characters. You can also have arrays of structures.&lt;br /&gt;
When using arrays to store the results of a query, if the size of the host array (say&amp;nbsp;&lt;i&gt;n&lt;/i&gt;) is smaller than the actual number of tuples returned by the query, then only the first&amp;nbsp;&lt;i&gt;n&lt;/i&gt;&amp;nbsp;result tuples will be entered into the host array.&lt;br /&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;indicator variables&quot;&gt;&lt;/a&gt;Indicator Variables&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Indicator variables are essentially &quot;&lt;/span&gt;&lt;tt&gt;NULL&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;flags&quot; attached to host variables. You can associate every host variable with an optional indicator variable. An indicator variable must be defined as a 2-byte integer (using the type&lt;/span&gt;&lt;tt&gt;short&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;) and, in SQL statements, must be prefixed by a colon and immediately follow its host variable. Or, you may use the keyword&amp;nbsp;&lt;/span&gt;&lt;tt&gt;INDICATOR&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;in between the host variable and indicator variable. Here is an example:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; short indicator_var;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL SELECT xyz INTO :host_var:indicator_var
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM ...;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL INSERT INTO R
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VALUES(:host_var INDICATOR :indicator_var, ...);&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;You can use indicator variables in the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;INTO&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;clause of a&amp;nbsp;&lt;/span&gt;&lt;tt&gt;SELECT&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;statement to detect&amp;nbsp;&lt;/span&gt;&lt;tt&gt;NULL&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&#39;s or truncated values in the output host variables. The values Oracle can assign to an indicator variable have the following meanings:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;center&gt;
&lt;table border=&quot;&quot; style=&quot;width: 100%px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;-1&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;The column value is&amp;nbsp;&lt;tt&gt;NULL&lt;/tt&gt;, so the value of the host variable is indeterminate.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Oracle assigned an intact column value to the host variable.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;&amp;gt;0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Oracle assigned a truncated column value to the host variable. The integer returned by the indicator variable is the original length of the column value.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;-2&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Oracle assigned a truncated column variable to the host variable, but the original column value could not be determined.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
You can also use indicator variables in the&amp;nbsp;&lt;tt&gt;VALUES&lt;/tt&gt;&amp;nbsp;and&amp;nbsp;&lt;tt&gt;SET&lt;/tt&gt;&amp;nbsp;clause of an&amp;nbsp;&lt;tt&gt;INSERT&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;UPDATE&lt;/tt&gt;&amp;nbsp; statement to assign&amp;nbsp;&lt;tt&gt;NULL&lt;/tt&gt;&#39;s to input host variables. The values your program can assign to an indicator variable have the following meanings:&lt;br /&gt;&amp;nbsp;&lt;table border=&quot;&quot; style=&quot;width: 100%px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;-1&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Oracle will assign a&amp;nbsp;&lt;tt&gt;NULL&lt;/tt&gt;&amp;nbsp;to the column, ignoring the value of the host variable.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;&amp;gt;=0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Oracle will assign the value of the host variable to the column.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;datatype equivalencing&quot;&gt;&lt;/a&gt;Datatype Equivalencing&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Oracle recognizes two kinds of datatypes: internal and external.&amp;nbsp;&lt;/span&gt;&lt;i&gt;Internal datatypes&lt;/i&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;specify how Oracle stores column values in database tables.&amp;nbsp;&lt;/span&gt;&lt;i&gt;External datatypes&lt;/i&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;specify the formats used to store values in input and output host variables. At precompile time, a default Oracle external datatype is assigned to each host variable. Datatype equivalencing allows you to override this default equivalencing and lets you control the way Oracle interprets the input data and formats the output data.&lt;/span&gt;The equivalencing can be done on a variable-by-variable basis using the&amp;nbsp;&lt;tt&gt;VAR&lt;/tt&gt;&amp;nbsp;statement. The syntax is:&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL VAR &amp;lt;host_var&amp;gt; IS &amp;lt;type_name&amp;gt; [ (&amp;lt;length&amp;gt;) ];&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;For example, suppose you want to select employee names from the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;emp&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;table, and then pass them to a routine that expects C-style&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&#39;\0&#39;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;-terminated strings. You need not explicitly&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&#39;\0&#39;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;-terminate the names yourself. Simply equivalence a host variable to the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;STRING&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;external datatype, as follows:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char emp_name[21];
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL VAR emp_name IS STRING(21);&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;The length of the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;ename&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;column in the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;emp&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;table is 20 characters, so you allot&amp;nbsp;&lt;/span&gt;&lt;tt&gt;emp_name&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;21 characters to accommodate the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&#39;\0&#39;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;-terminator.&amp;nbsp;&lt;/span&gt;&lt;tt&gt;STRING&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;is an Oracle external datatype specifically designed to interface with C-style strings. When you select a value from the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;ename&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;column into&amp;nbsp;&lt;/span&gt;&lt;tt&gt;emp_name&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, Oracle will automatically&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&#39;\0&#39;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;-terminate the value for you.&lt;/span&gt;You can also equivalence user-defined datatypes to Oracle external datatypes using the&amp;nbsp;&lt;tt&gt;TYPE&lt;/tt&gt;&amp;nbsp;statement. The syntax is:&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL TYPE &amp;lt;user_type&amp;gt; IS &amp;lt;type_name&amp;gt; [ (&amp;lt;length&amp;gt;) ] [REFERENCE];&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;You can declare a user-defined type to be a pointer, either explicitly, as a pointer to a scalar or structure, or implicitly as an array, and then use this type in a&amp;nbsp;&lt;/span&gt;&lt;tt&gt;TYPE&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;statement. In these cases, you need to use the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;REFERENCE&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;clause at the end of the statement, as shown below:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; typedef unsigned char *my_raw;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL TYPE my_raw IS VARRAW(4000) REFERENCE;
&amp;nbsp;&amp;nbsp;&amp;nbsp; my_raw buffer;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ... */
&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer = malloc(4004);&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Here we allocated more memory than the type length (4000) because the precompiler also returns the length, and may add padding after the length in order to meet the alignment requirement on your system.&lt;/span&gt;&lt;h3&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;dynamic sql&quot;&gt;&lt;/a&gt;&lt;span&gt;Dynamic SQL&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;While embedded SQL is fine for fixed applications, sometimes it is important for a program to dynamically create entire SQL statements. With dynamic SQL, a statement stored in a string variable can be issued.&amp;nbsp;&lt;/span&gt;&lt;tt&gt;PREPARE&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;turns a character string into a SQL statement, and&amp;nbsp;&lt;/span&gt;&lt;tt&gt;EXECUTE&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;executes that statement. Consider the following example.&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *s = &quot;INSERT INTO emp VALUES(1234, &#39;jon&#39;, 3)&quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL PREPARE q FROM :s;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL EXECUTE q;&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Alternatively,&amp;nbsp;&lt;/span&gt;&lt;tt&gt;PREPARE&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt&gt;EXECUTE&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;may be combined into one statement:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; char *s = &quot;INSERT INTO emp VALUES(1234, &#39;jon&#39;, 3)&quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL EXECUTE IMMEDIATE :s;&lt;/pre&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;transactions&quot;&gt;&lt;/a&gt;&lt;span&gt;Transactions&lt;/span&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Oracle PRO*C supports transactions as defined by the SQL standard. A transaction is a sequence of SQL statements that Oracle treats as a single unit of work. A transaction begins at your first SQL statement. A transaction ends when you issue &quot;&lt;/span&gt;&lt;tt&gt;EXEC SQL COMMIT&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&quot; (to make permanent any database changes during the current transaction) or &quot;&lt;/span&gt;&lt;tt&gt;EXEC SQL ROLLBACK&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&quot; (to undo any changes since the current transaction began). After the current transaction ends with your&amp;nbsp;&lt;/span&gt;&lt;tt&gt;COMMIT&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;or&amp;nbsp;&lt;/span&gt;&lt;tt&gt;ROLLBACK&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;statement, the next executable SQL statement will automatically begin a new transaction.&lt;/span&gt;&amp;nbsp;If your program exits without calling&amp;nbsp;&lt;tt&gt;EXEC SQL COMMIT&lt;/tt&gt;, all database changes will be discarded.&lt;br /&gt;
&lt;br /&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;error handling&quot;&gt;&lt;/a&gt;&lt;span&gt;Error Handling&lt;/span&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;After each executable SQL statement, your program can find the status of execution either by explicit checking of SQLCA, or by implicit checking using the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;WHENEVER&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;statement. These two ways are covered in details below.&lt;/span&gt;&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;sqlca&quot;&gt;&lt;/a&gt;SQLCA&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;SQLCA (SQL Communications Area) is used to detect errors and status changes in your program. This structure contains components that are filled in by Oracle at runtime after every executable SQL statement.&lt;/span&gt;To use SQLCA you need to include the header file&amp;nbsp;&lt;tt&gt;sqlca.h&lt;/tt&gt;&amp;nbsp;using the&amp;nbsp;&lt;tt&gt;#include&lt;/tt&gt;&amp;nbsp;directive. In case you need to include&amp;nbsp;&lt;tt&gt;sqlca.h&lt;/tt&gt;&amp;nbsp;at many places, you need to first undefine the macro&amp;nbsp;&lt;tt&gt;SQLCA&lt;/tt&gt;&amp;nbsp;with&amp;nbsp;&lt;tt&gt;#undef SQLCA&lt;/tt&gt;. The relevant chunk of&amp;nbsp;&lt;tt&gt;sqlca.h&lt;/tt&gt;&amp;nbsp;follows:&lt;br /&gt;
&lt;pre&gt;#ifndef SQLCA
#define SQLCA 1

struct sqlca {
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ub1 */ char sqlcaid[8];
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* b4 */ long sqlabc;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* b4 */ long sqlcode;
&amp;nbsp;&amp;nbsp;&amp;nbsp; struct {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ub2 */ unsigned short sqlerrml;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ub1 */ char sqlerrmc[70];
&amp;nbsp;&amp;nbsp;&amp;nbsp; } sqlerrm;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ub1 */ char sqlerrp[8];
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* b4 */ long sqlerrd[6];
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ub1 */ char sqlwarn[8];
&amp;nbsp;&amp;nbsp;&amp;nbsp; /* ub1 */ char sqlext[8];
};
/* ... */&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;The fields in&amp;nbsp;&lt;/span&gt;&lt;tt&gt;sqlca&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;have the following meaning:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;center&gt;
&lt;table border=&quot;&quot; style=&quot;width: 100%px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlcaid&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;This string component is initialized to &quot;SQLCA&quot; to identify the SQL Communications Area.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlcabc&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;This integer component holds the length, in bytes, of the SQLCA structure.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlcode&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;This integer component holds the status code of the most recently executed SQL statement:&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;center&gt;
&lt;table border=&quot;&quot; style=&quot;width: 90%px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;No error.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;&amp;gt;0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Statement executed but exception detected. This occurs when Oracle cannot find a row that meets your&amp;nbsp;&lt;tt&gt;WHERE&lt;/tt&gt;&amp;nbsp;condition or when a&amp;nbsp;&lt;tt&gt;SELECT INTO&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;FETCH&lt;/tt&gt;&amp;nbsp;returns no rows.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;&amp;lt;0&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Oracle did not execute the statement because of an error. When such errors occur, the current transaction should, in most cases, be rolled back.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlerrm&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;This embedded structure contains the following two components:&amp;nbsp;&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;sqlerrml&lt;/tt&gt;&amp;nbsp;- Length of the message text stored in&amp;nbsp;&lt;tt&gt;sqlerrmc&lt;/tt&gt;.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;sqlerrmc&lt;/tt&gt;&amp;nbsp;- Up to 70 characters of the message text corresponding to the error code stored in&amp;nbsp;&lt;tt&gt;sqlcode&lt;/tt&gt;.&lt;/li&gt;
&lt;br /&gt;&amp;nbsp;&lt;/ul&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlerrp&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Reserved for future use.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlerrd&lt;/tt&gt;&lt;/td&gt;&lt;td valign=&quot;TOP&quot;&gt;This array of binary integers has six elements:&amp;nbsp;&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;sqlerrd[0]&lt;/tt&gt;&amp;nbsp;- Future use.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;sqlerrd[1]&lt;/tt&gt;&amp;nbsp;- Future use.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;sqlerrd[2]&lt;/tt&gt;&amp;nbsp;- Numbers of rows processed by the most recent SQL statement.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;sqlerrd[3]&lt;/tt&gt;&amp;nbsp;- Future use.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;sqlerrd[4]&lt;/tt&gt;&amp;nbsp;- Offset that specifies the character position at which a parse error begins in the most recent SQL statement.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;sqlerrd[5]&lt;/tt&gt;&amp;nbsp;- Future use.&lt;/li&gt;
&lt;br /&gt;&amp;nbsp;&lt;/ul&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlwarn&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;This array of single characters has eight elements used as warning flags. Oracle sets a flag by assigning to it the character&amp;nbsp;&lt;tt&gt;&#39;W&#39;&lt;/tt&gt;.&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;center&gt;
&lt;table border=&quot;&quot; style=&quot;width: 90%px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[0]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Set if any other flag is set.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[1]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Set if a truncated column value was assigned to an output host variable.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[2]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Set if a&amp;nbsp;&lt;tt&gt;NULL&lt;/tt&gt;&amp;nbsp;column value is not used in computing a SQL aggregate such as&amp;nbsp;&lt;tt&gt;AVG&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;SUM&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[3]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Set if the number of columns in&amp;nbsp;&lt;tt&gt;SELECT&lt;/tt&gt;&amp;nbsp;does not equal the number of host variables specified in&amp;nbsp;&lt;tt&gt;INTO&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[4]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Set if every row in a table was processed by an&amp;nbsp;&lt;tt&gt;UPDATE&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;DELETE&lt;/tt&gt;&amp;nbsp;statement without a&amp;nbsp;&lt;tt&gt;WHERE&lt;/tt&gt;&amp;nbsp;clause.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[5]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Set if a procedure/function/package/package body creation command fails because of a PL/SQL compilation error.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[6]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;No longer in use.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;sqlwarn[7]&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;No longer in use.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td valign=&quot;TOP&quot;&gt;&lt;tt&gt;sqlext&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;Reserved for future use.&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
SQLCA can only accommodate error messages up to 70 characters long in its&amp;nbsp;&lt;tt&gt;sqlerrm&lt;/tt&gt;&amp;nbsp;component. To get the full text of longer (or nested) error messages, you need the&amp;nbsp;&lt;tt&gt;sqlglm()&lt;/tt&gt;&amp;nbsp;function:&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; void sqlglm(char *msg_buf, size_t *buf_size, size_t *msg_length);&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;where&amp;nbsp;&lt;/span&gt;&lt;tt&gt;msg_buf&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;is the character buffer in which you want Oracle to store the error message;&amp;nbsp;&lt;/span&gt;&lt;tt&gt;buf_size&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;specifies the size of&amp;nbsp;&lt;/span&gt;&lt;tt&gt;msg_buf&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;in bytes; Oracle stores the actual length of the error message in&amp;nbsp;&lt;/span&gt;&lt;tt&gt;*msg_length&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;. The maximum length of an Oracle error message is 512 bytes.&lt;/span&gt;&lt;h4&gt;
&lt;hr align=&quot;LEFT&quot; width=&quot;10%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;whenever statement&quot;&gt;&lt;/a&gt;WHENEVER Statement&lt;/h4&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;This statement allows you to do automatic error checking and handling. The syntax is:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL WHENEVER &amp;lt;condition&amp;gt; &amp;lt;action&amp;gt;;&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Oracle automatically checks SQLCA for&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&amp;lt;condition&amp;gt;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, and if such condition is detected, your program will automatically perform&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&amp;lt;action&amp;gt;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;.&lt;/span&gt;&lt;tt&gt;&amp;lt;condition&amp;gt;&lt;/tt&gt;&amp;nbsp;can be any of the following:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;SQLWARNING&lt;/tt&gt;&amp;nbsp;-&amp;nbsp;&lt;tt&gt;sqlwarn[0]&lt;/tt&gt;&amp;nbsp;is set because Oracle returned a warning&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;SQLERROR&lt;/tt&gt;&amp;nbsp;-&amp;nbsp;&lt;tt&gt;sqlcode&lt;/tt&gt;&amp;nbsp;is negative because Oracle returned an error&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;NOT FOUND&lt;/tt&gt;&amp;nbsp;-&amp;nbsp;&lt;tt&gt;sqlcode&lt;/tt&gt;&amp;nbsp;is positive because Oracle could not find a row that meets your&amp;nbsp;&lt;tt&gt;WHERE&lt;/tt&gt;&amp;nbsp;condition, or a&amp;nbsp;&lt;tt&gt;SELECT INTO&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;FETCH&lt;/tt&gt;&amp;nbsp;returned no rows&lt;/li&gt;
&lt;/ul&gt;
&lt;tt&gt;&amp;lt;action&amp;gt;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;can be any of the following:&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;CONTINUE&lt;/tt&gt;&amp;nbsp;- Program will try to continue to run with the next statement if possible&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;DO&lt;/tt&gt;&amp;nbsp;- Program transfers control to an error handling function&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;GOTO &amp;lt;label&amp;gt;&lt;/tt&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;- Program branches to a labeled statement&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;STOP&lt;/tt&gt;&amp;nbsp;- Program exits with an&amp;nbsp;&lt;tt&gt;exit()&lt;/tt&gt;&amp;nbsp;call, and uncommitted work is rolled back&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Some examples of the&amp;nbsp;&lt;/span&gt;&lt;tt&gt;WHENEVER&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;statement:&lt;/span&gt;&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL WHENEVER SQLWARNING DO print_warning_msg();
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL WHENEVER NOT FOUND GOTO handle_empty;&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Here is a more concrete example:&lt;/span&gt;&lt;pre&gt;/* code to find student name given id */
/* ... */
for (;;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Give student id number : &quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp; scanf(&quot;%d&quot;, &amp;amp;id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL WHENEVER NOT FOUND GOTO notfound;
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL SELECT studentname INTO :st_name
&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&amp;nbsp;&amp;nbsp; student
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&amp;nbsp; studentid = :id;
&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;Name of student is %s.\n&quot;, st_name);
&amp;nbsp;&amp;nbsp;&amp;nbsp; continue;
notfound:
&amp;nbsp;&amp;nbsp;&amp;nbsp; printf(&quot;No record exists for id %d!\n&quot;, id);
}
/* ... */&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Note that the WHENEVER statement does not follow regular C scoping rules. Scoping is valid for the entire program.&amp;nbsp; For example, if you have the following statement somewhere in your program (such as before a loop):&lt;/span&gt;&lt;tt&gt;EXEC SQL WHENEVER NOT FOUND DO break;&lt;/tt&gt;&lt;br /&gt;
All SQL statements that occur after this line in the file would be affected.&amp;nbsp; Make sure you use the following line to cancel the effect of WHENEVER when it is no longer needed (such as after your loop):&lt;br /&gt;
&lt;tt&gt;EXEC SQL WHENEVER NOT FOUND CONTINUE;&lt;/tt&gt;&lt;br /&gt;
&lt;h3&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;demo programs&quot;&gt;&lt;/a&gt;&lt;span&gt;Demo Programs&lt;/span&gt;&lt;/h3&gt;
&lt;b&gt;Note:&lt;/b&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;The demo programs will create and use four tables named&amp;nbsp;&lt;/span&gt;&lt;tt&gt;DEPT&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;tt&gt;EMP&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;tt&gt;PAY1&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, and&amp;nbsp;&lt;/span&gt;&lt;tt&gt;PAY2&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;. Be careful if any table in your database happens to have the same name!&lt;/span&gt;Several demo programs are available in&amp;nbsp;&lt;tt&gt;/afs/ir/class/cs145/code/proc&lt;/tt&gt;&amp;nbsp;on the leland system. They are named&amp;nbsp;&lt;tt&gt;sample*.pc&lt;/tt&gt;&amp;nbsp;(for C users) and&amp;nbsp;&lt;tt&gt;cppdemo*.pc&lt;/tt&gt;&amp;nbsp;(for C++ users). &quot;&lt;tt&gt;.pc&lt;/tt&gt;&quot; is the extension for Pro*C code. Do&amp;nbsp;&lt;i&gt;not&lt;/i&gt;&amp;nbsp;copy these files manually, since there are a couple of customizations to do. To download and customize the demo programs, follow the instructions below:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Make sure that you have run&amp;nbsp;&lt;tt&gt;source /afs/ir/class/cs145/all.env&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;In your home directory, run&amp;nbsp;&lt;tt&gt;load_samples &amp;lt;db_username&amp;gt; &amp;lt;db_passwd&amp;gt; &amp;lt;sample_dir&amp;gt;&lt;/tt&gt;, where&amp;nbsp;&lt;tt&gt;&amp;lt;sample_dir&amp;gt;&lt;/tt&gt;&amp;nbsp;is the name of the directory where you wish to put demo programs (&lt;i&gt;e.g.&lt;/i&gt;,&amp;nbsp;&lt;tt&gt;load_samples sally etaoinshrdlu cs145_samples&lt;/tt&gt;)&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;cd &amp;lt;sample_dir&amp;gt;&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;Run&amp;nbsp;&lt;tt&gt;make samples&lt;/tt&gt;&amp;nbsp;(or&amp;nbsp;&lt;tt&gt;make cppsamples&lt;/tt&gt;&amp;nbsp;for C++) to compile all demo programs&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Step (2) will set up the sample database, create a new directory as specified in&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&amp;lt;sample_dir&amp;gt;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, and copy the demo files into that directory. It will also change the user name and password in the sample programs to be yours, so that you do not have to type in your username and password every time when running a sample program. However,&amp;nbsp;&lt;/span&gt;&lt;tt&gt;sample1&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;tt&gt;cppdemo1&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;do provide an interface for the user to input the username and password, in case you would like to learn how to do it.&lt;/span&gt;If you happen to make any mistake when entering username or password in Step (2), just run&amp;nbsp;&lt;tt&gt;clean_samples &amp;lt;db_username&amp;gt; &amp;lt;db_passwd&amp;gt; &amp;lt;sample_dir&amp;gt;&lt;/tt&gt;&amp;nbsp;in your home directory, and then repeat Steps (2) to (4).&lt;br /&gt;
For Step (4), you can also compile each sample program separately. For example,&amp;nbsp;&lt;tt&gt;make sample1&lt;/tt&gt;&amp;nbsp;compiles&amp;nbsp;&lt;tt&gt;sample1.pc&lt;/tt&gt;&amp;nbsp;alone. The compilation process actually has two phases:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;tt&gt;proc iname=sample1.pc&lt;/tt&gt;&lt;/li&gt;
&lt;br /&gt;converts the embedded SQL code to corresponding library calls and outputs&amp;nbsp;&lt;tt&gt;sample1.c&lt;/tt&gt;
&lt;li&gt;&lt;tt&gt;cc &amp;lt;a_number_of_flags_here&amp;gt; sample1.c&lt;/tt&gt;&lt;/li&gt;
&lt;br /&gt;generates the executable&amp;nbsp;&lt;tt&gt;sample1&lt;/tt&gt;&lt;/ol&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;To compile your own code, say,&amp;nbsp;&lt;/span&gt;&lt;tt&gt;foo.pc&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, just change a few variables in&amp;nbsp;&lt;/span&gt;&lt;tt&gt;Makefile&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;: Add the program name&amp;nbsp;&lt;/span&gt;&lt;tt&gt;foo&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;to variable&amp;nbsp;&lt;/span&gt;&lt;tt&gt;SAMPLES&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;and the source file name&amp;nbsp;&lt;/span&gt;&lt;tt&gt;foo.pc&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;to variable&amp;nbsp;&lt;/span&gt;&lt;tt&gt;SAMPLE_SRC&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;. Then, do&amp;nbsp;&lt;/span&gt;&lt;tt&gt;make foo&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;after&lt;/span&gt;&lt;tt&gt;foo.pc&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;is ready.&amp;nbsp;&lt;/span&gt;&lt;tt&gt;foo.pc&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;will be precompiled to&amp;nbsp;&lt;/span&gt;&lt;tt&gt;foo.c&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;and then compiled to&amp;nbsp;&lt;/span&gt;&lt;tt&gt;foo&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, the executable. C++ users will need to add their program name to&amp;nbsp;&lt;/span&gt;&lt;tt&gt;CPPSAMPLES&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;instead of&amp;nbsp;&lt;/span&gt;&lt;tt&gt;SAMPLES&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, and source file name to&lt;/span&gt;&lt;tt&gt;CPPSAMPLE_SRC&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;instead of&amp;nbsp;&lt;/span&gt;&lt;tt&gt;SAMPLE_SRC&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;.&lt;/span&gt;The demo programs operate on the following tables:&lt;br /&gt;
&lt;pre&gt;CREATE TABLE DEPT
&amp;nbsp;&amp;nbsp;&amp;nbsp; (DEPTNO&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(2) NOT NULL,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DNAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VARCHAR2(14),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VARCHAR2(13));

CREATE TABLE EMP
&amp;nbsp;&amp;nbsp;&amp;nbsp; (EMPNO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(4) NOT NULL,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VARCHAR2(10),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; JOB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VARCHAR2(9),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MGR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(4),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HIREDATE&amp;nbsp; DATE,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SAL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(7, 2),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; COMM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(7, 2),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DEPTNO&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(2));

CREATE TABLE PAY1
&amp;nbsp;&amp;nbsp;&amp;nbsp; (ENAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VARCHAR2(10),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SAL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(7, 2));

CREATE TABLE PAY2
&amp;nbsp;&amp;nbsp;&amp;nbsp; (ENAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VARCHAR2(10),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SAL&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMBER(7, 2));&lt;/pre&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;These tables are created automatically when you run&amp;nbsp;&lt;/span&gt;&lt;tt&gt;load_samples&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;in Step (2). A few tuples are also inserted. You may like to browse the tables before running the samples on them. You can also play with them as you like (&lt;/span&gt;&lt;i&gt;e.g.&lt;/i&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;, inserting, deleting, or updating tuples). These tables will be dropped automatically when you run&amp;nbsp;&lt;/span&gt;&lt;tt&gt;clean_samples&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;.&amp;nbsp;&lt;/span&gt;&lt;b&gt;Note:&lt;/b&gt;&lt;tt&gt;clean_samples&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;&amp;nbsp;also wipes out the entire&amp;nbsp;&lt;/span&gt;&lt;tt&gt;&amp;lt;sample_dir&amp;gt;&lt;/tt&gt;&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;; make sure you move your own files to some other place before running this command!&lt;/span&gt;You should take a look at the sample source code before running it. The comments at the top describe what the program does. For example,&amp;nbsp;&lt;tt&gt;sample1&lt;/tt&gt;&amp;nbsp;takes an employee&#39;s&amp;nbsp;&lt;tt&gt;EMPNO&lt;/tt&gt;&amp;nbsp;and retrieve the name, salary, and commission for that employee from the table&amp;nbsp;&lt;tt&gt;EMP&lt;/tt&gt;.&lt;br /&gt;
You are supposed to study the sample source code and learn the following:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;How to connect to Oracle from the host program&lt;/li&gt;
&lt;li&gt;How to embed SQL in C/C++&lt;/li&gt;
&lt;li&gt;How to use cursors&lt;/li&gt;
&lt;li&gt;How to use host variables to communicate with the database&lt;/li&gt;
&lt;li&gt;How to use&amp;nbsp;&lt;tt&gt;WHENEVER&lt;/tt&gt;&amp;nbsp;to take different actions on error messages.&lt;/li&gt;
&lt;li&gt;How to use indicator variables to detect&amp;nbsp;&lt;tt&gt;NULL&lt;/tt&gt;&#39;s in the output&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;Now, you can use these techniques to code your own database application program. And have fun!&lt;/span&gt;&lt;h3&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;c++ users&quot;&gt;&lt;/a&gt;&lt;span&gt;C++ Users&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: #e0f7f0;&quot;&gt;To get the precompiler to generate appropriate C++ code, you need to be aware of the following issues:&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;Code emission by precompiler. To get C++ code, you need to set the option&amp;nbsp;&lt;tt&gt;CODE=CPP&lt;/tt&gt;&amp;nbsp;while executing&amp;nbsp;&lt;tt&gt;proc&lt;/tt&gt;. C users need not worry about this option; the default caters to their needs.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Parsing capability. The&amp;nbsp;&lt;tt&gt;PARSE&lt;/tt&gt;&amp;nbsp;option of&amp;nbsp;&lt;tt&gt;proc&lt;/tt&gt;&amp;nbsp;may take the following values:&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;tt&gt;PARSE=NONE&lt;/tt&gt;. C preprocessor directives are understood only inside a declare section, and all host variables need to be declared inside a declare section.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;PARSE=PARTIAL&lt;/tt&gt;. C preprocessor directives are understood; however, all host variables need to be declared inside a declare section.&lt;/li&gt;
&lt;li&gt;&lt;tt&gt;PARSE=FULL&lt;/tt&gt;. C preprocessor directives are understood and host variables can be declared anywhere. This is the default when&amp;nbsp;&lt;tt&gt;CODE&lt;/tt&gt;&amp;nbsp;is anything other than&amp;nbsp;&lt;tt&gt;CPP&lt;/tt&gt;; it is an error to specify&amp;nbsp;&lt;tt&gt;PARSE=FULL&lt;/tt&gt;&amp;nbsp;with&lt;tt&gt;CODE=CPP&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;So, C++ users must specify&amp;nbsp;&lt;tt&gt;PARSE=NONE&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;PARSE=PARTIAL&lt;/tt&gt;. They therefore lose the freedom to declare host variables anywhere in the code. Rather, the host variables must be encapsulated in&amp;nbsp;&lt;i&gt;declare sections&lt;/i&gt;&amp;nbsp;as follows:&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL BEGIN DECLARE SECTION;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // declarations...
&amp;nbsp;&amp;nbsp;&amp;nbsp; EXEC SQL END DECLARE SECTION;&lt;/pre&gt;
You need to follow this routine for declaring the host and indicator variables at all the places you do so.&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;File extension. You need to specify the option&amp;nbsp;&lt;tt&gt;CPP_SUFFIX=cc&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;CPP_SUFFIX=C&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Location of header files. By default,&amp;nbsp;&lt;tt&gt;proc&lt;/tt&gt;&amp;nbsp;searches for header files like&amp;nbsp;&lt;tt&gt;stdio.h&lt;/tt&gt;&amp;nbsp;in standard locations. However, C++ has its own header files, such as&amp;nbsp;&lt;tt&gt;iostream.h&lt;/tt&gt;, located elsewhere. So you need to use the&lt;tt&gt;SYS_INCLUDE&lt;/tt&gt;&amp;nbsp;option to specify the paths that&amp;nbsp;&lt;tt&gt;proc&lt;/tt&gt;&amp;nbsp;should search for header files.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
&lt;hr width=&quot;100%&quot; /&gt;
&lt;a href=&quot;&quot; name=&quot;list of embedded sql statements supported by pro*c&quot;&gt;&lt;/a&gt;&lt;span&gt;List of Embedded SQL Statements Supported by Pro*C&lt;/span&gt;&lt;/h3&gt;
&lt;center&gt;
&lt;table border=&quot;&quot; style=&quot;width: 100%px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;CENTER&quot; colspan=&quot;2&quot;&gt;&lt;b&gt;Declarative Statements&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL ARRAYLEN&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To use host arrays with PL/SQL&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL BEGIN DECLARE SECTION&lt;/tt&gt;&lt;br /&gt;&lt;tt&gt;EXEC SQL END DECLARE SECTION&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To declare host variables&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL DECLARE&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To name Oracle objects&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL INCLUDE&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To copy in files&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL TYPE&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To equivalence datatypes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL VAR&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To equivalence variables&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL WHENEVER&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To handle runtime errors&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;CENTER&quot; colspan=&quot;2&quot;&gt;&lt;b&gt;Executable Statements&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL ALLOCATE&lt;/tt&gt;&lt;/td&gt;&lt;td rowspan=&quot;14&quot;&gt;To define and control Oracle data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL ALTER&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL ANALYZE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL AUDIT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL COMMENT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL CONNECT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL CREATE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL DROP&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL GRANT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL NOAUDIT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL RENAME&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL REVOKE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL TRUNCATE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL CLOSE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL DELETE&lt;/tt&gt;&lt;/td&gt;&lt;td rowspan=&quot;8&quot;&gt;To query and manipulate Oracle data&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL EXPLAIN PLAN&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL FETCH&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL INSERT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL LOCK TABLE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL OPEN&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL SELECT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL UPDATE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL COMMIT&lt;/tt&gt;&lt;/td&gt;&lt;td rowspan=&quot;4&quot;&gt;To process transactions&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL ROLLBACK&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL SAVEPOINT&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL SET TRANSACTION&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL DESCRIBE&lt;/tt&gt;&lt;/td&gt;&lt;td rowspan=&quot;3&quot;&gt;To use dynamic SQL&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL EXECUTE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL PREPARE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL ALTER SESSION&lt;/tt&gt;&lt;/td&gt;&lt;td rowspan=&quot;2&quot;&gt;To control sessions&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL SET ROLE&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;tt&gt;EXEC SQL EXECUTE&lt;/tt&gt;&lt;br /&gt;&lt;tt&gt;END-EXEC&lt;/tt&gt;&lt;/td&gt;&lt;td&gt;To embed PL/SQL blocks&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/center&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
Source :-&amp;nbsp;&lt;a href=&quot;http://infolab.stanford.edu/~ullman/fcdb/oracle/or-proc.html&quot;&gt;http://infolab.stanford.edu/~ullman/fcdb/oracle/or-proc.html&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6667559335674450018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/10/connect-oracle-with-cc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6667559335674450018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6667559335674450018'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/10/connect-oracle-with-cc.html' title='Connect oracle with C/C++'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-4255303217249874074</id><published>2012-09-07T00:09:00.002-07:00</published><updated>2012-09-07T00:09:28.892-07:00</updated><title type='text'>Resume tips by a 15 years recruiter at google.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;What Resume Screeners Look For&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Resume screeners look for the same things that interviewers do:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;»»Are you smart?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;»»Can you code?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;That means that you should present your resume to show those two things. Your love of tennis, traveling, or magic cards won’t do much to show that, so it’s likely just wasting space.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Keep in mind that recruiters only spend a fixed amount of time (about 20 seconds) looking at your resume. If you limit the content to the best, most impressive, most relevant items, they’ll jump out at the recruiter. Weak items only dilute your resume and distract the recruiter&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;from what you’d like them to see.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Employment History&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Relevant Jobs: Your resume does not - and should not - include a full history of every role you’ve ever had. Your job serving ice cream, for example, will not show that you’re smart or that you can code. Include only the relevant things.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Writing Strong Bullets: For each role, try to discuss your accomplishments with the following approach: “Accomplished&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;X by implementing Y which led to Z.” Here’s an example:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;»»“Reduced object rendering time by 75% by applying Floyd’s algorithm,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;leading to a 10% reduction in system boot time.”&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Here’s another example with an alternate&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;wording:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;»»“Increased average match accuracy&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;from 1.2 to 1.5 by implementing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;a new comparison algorithm based on windiff.”&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Not everything you did will fit into this approach, but the principle is the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Got some extra time to prepare?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;If you have at least a couple months before an interview (or if you’re in school and not graduating yet), you may be able to improve your resume.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Go out and get project experience! Take course that have major projects. Get involved in open source. Ask a professor if there is any research you can get involved in, or ask if he/she can sponsor you on an independent study.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;This will put you in a better position to have your resume selected down the road. It will also give you lots of things to talk about in an interview.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;same: show what you did, how you did it, and what the results were. Ideally, you should try to make the results “measurable” somehow.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Projects&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Almost every candidate has some projects, even if they’re just academic projects. List them on your resume! I recommend putting a section called “Projects” on your resume and list your 2 - 4 most significant projects. State what the project was, which languages or technologies&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;it employed, and whether it was an individual or a team project. If your project was not for a course, that’s even better! It shows passion, initiative, and work ethic. You can state the type of project by listing course projects as “Course Project” and your independent projects as “Independent Projects” (or some other wording).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Programming Languages and Software&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Software: Generally speaking, I do not recommend listing that you’re familiar with Microsoft Office. Everyone is, and it just dilutes the “real” information. Familiarity with developer-specific&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;or highly technical software (e.g., Visual Studio, Eclipse, Linux) can be useful, but it often doesn’t make much of a difference.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Languages: Knowing which languages to list on your resume is always a tricky thing. Do you list everything you’ve ever worked with? Or only the ones that you’re more comfortable with (even though that might only be one or two languages)? I recommend the following compromise: list most languages you’ve used, but add your experience level. This approach is shown below:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;»»“Languages: Java (expert), C++ (proficient), JavaScript (prior experience), C (prior experience)”&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Advice for Non-Native English Speakers and Internationals&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Proofreading: Some companies will throw out your resume just because of a typo. Please get at least one native English speaker to proofread your resume.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;Personal Information: For US positions, do not include age, marital status, or nationality. This sort of personal information is not appreciated by companies, as it creates a legal liability&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: blue;&quot;&gt;for them. However, you may want to include your current work authorization / visa status, particularly when applying to smaller companies who may be unable to sponsor candidates.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/4255303217249874074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/resume-tips-by-15-years-recruiter-at.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4255303217249874074'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4255303217249874074'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/resume-tips-by-15-years-recruiter-at.html' title='Resume tips by a 15 years recruiter at google.'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-9140511845764245601</id><published>2012-09-05T22:12:00.000-07:00</published><updated>2012-09-05T22:12:08.222-07:00</updated><title type='text'>Reference to C Quiz.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Following are the references for some C quiz websites.&lt;br /&gt;Point of giving you the link is something different.&lt;br /&gt;
I want you to take quiz from there.&lt;br /&gt;In case you come across a problem in any question, simply post the link to that question or Copy/Paste the question here.&lt;br /&gt;
1.&lt;a href=&quot;http://www.freeaptitude.com/tag/c-programming-tricky-questions&quot;&gt;http://www.freeaptitude.com/tag/c-programming-tricky-questions&lt;/a&gt;
&lt;br /&gt;
2.&lt;a href=&quot;http://leebaannvarghes.hubpages.com/hub/Some-tricky-programming-questions-for-interview&quot;&gt;http://leebaannvarghes.hubpages.com/hub/Some-tricky-programming-questions-for-interview&lt;/a&gt;&lt;br /&gt;
3.&lt;a href=&quot;http://www.cprogrammingreference.com/questionbank_home.html&quot;&gt;http://www.cprogrammingreference.com/questionbank_home.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Don&#39;t forget to hit the like button&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/9140511845764245601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/reference-to-c-quiz.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/9140511845764245601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/9140511845764245601'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/reference-to-c-quiz.html' title='Reference to C Quiz.'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6557413289851198243</id><published>2012-09-05T03:20:00.000-07:00</published><updated>2012-09-05T03:44:47.369-07:00</updated><title type='text'>TCS technical interview questions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q:What will be the output of the following code?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
void main ()&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int i = 0 , a[3] ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
a[i] = i++;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
printf (“%d”,a[i]) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Ans&lt;/strong&gt;: The output for the above code would be a garbage value. In the statement a[i] = i++; the value of the&amp;nbsp;variable&amp;nbsp;i would get assigned first to a[i] i.e. a[0] and&amp;nbsp;then the&amp;nbsp;value of i would get incremented by 1. Since a[i] i.e. a[1] has not been initialized, a[i] will have a garbage value.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q:Why doesn’t the following code give the desired result?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A&lt;/strong&gt;: &amp;nbsp;int x = 3000, y = 2000 ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
long int z = x * y ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Ans:&amp;nbsp;Here the&amp;nbsp;multiplication is carried out between two ints x and y, and&amp;nbsp; the result that would overflow would be truncated before being assigned to&amp;nbsp; the&amp;nbsp;variable&amp;nbsp;z of type long int. However, to get the correct output, we should use an explicit cast to force long arithmetic as shown below:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
long int z = ( long int ) x * y ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Note that ( long int )( x * y ) would not give the desired effect.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q: Why doesn’t the following statement work?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A:&lt;/strong&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; char str[ ] = “Hello” ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
strcat ( str, ‘!’ ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
Ans: The&amp;nbsp;string function&amp;nbsp;strcat( ) concatenates strings and not a character. The basic difference between a string and a character is that a string is a collection of characters, represented by an array of characters whereas a character is a single character. To make the above statement work writes the statement as shown below:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
strcat ( str, “!” ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q:How do I know how many elements an array can hold&lt;/strong&gt;?&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A:&lt;/strong&gt;&amp;nbsp;The amount of memory an array can consume depends on the data type of an array. In DOS&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; environment, the amount of memory an array can consume depends on the current memory model (i.e. Tiny, Small, Large, Huge, etc.). In general an array cannot consume more than 64 kb. Consider following program, which shows the maximum number of elements an array of type int, float and char can have in case of Small memory model.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
main( )&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
int i[32767] ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
float f[16383] ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
char s[65535] ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q:How do I write code that reads data at memory location specified by segment and offset?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A:&lt;/strong&gt;&amp;nbsp;Use peekb( ) function. This function returns byte(s) read from specific segment and offset locations in memory. The following program illustrates use of this function. In this program from VDU memory we have read characters and its attributes of the first row. The information stored in file is then further read and displayed using peek( ) function.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
#include&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
#include&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
main( )&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
char far *scr = 0xB8000000 ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
FILE *fp ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
int offset ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
char ch ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
if ( ( fp = fopen ( “scr.dat”, “wb” ) ) == NULL )&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
printf ( “\nUnable to open file” ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
exit( ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
// reads and writes to file&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
for ( offset = 0 ; offset &amp;lt; 160 ; offset++ )&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
fprintf ( fp, “%c”, peekb ( scr, offset ) ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
fclose ( fp ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
if ( ( fp = fopen ( “scr.dat”, “rb” ) ) == NULL )&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
printf ( “\nUnable to open file” ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
exit( ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
// reads and writes to file&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
for ( offset = 0 ; offset &amp;lt; 160 ; offset++ )&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
{&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
fscanf ( fp, “%c”, &amp;amp;ch ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
printf ( “%c”, ch ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
fclose ( fp ) ;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
}&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q: What is C language?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A&lt;/strong&gt;: The&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;C programming language&lt;/strong&gt;&amp;nbsp;is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on&amp;nbsp;the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming&amp;nbsp;languages. C is prized for its efficiency, and is the most popular programming language for writing&amp;nbsp;system software, though it is also used for writing applications.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q: Inprintf() Function&amp;nbsp;What is the output of printf(“%d”)?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A&lt;/strong&gt;:1. When we write printf(“%d”,x); this means compiler will print the value of x. But as here, there is nothing after ï¿½%dï¿½ so compiler will show in output window garbage value.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
2. When we use %d the compiler internally uses it to access theargument&amp;nbsp;in the stack (argument&amp;nbsp;stack). Ideally compiler determines the offset of the data&amp;nbsp;variable&amp;nbsp;depending on&amp;nbsp;the format&amp;nbsp;specification string. Now when we write printf(“%d”,a) then compiler first accesses the top most element in the&amp;nbsp;argument&amp;nbsp;stack of the printf which is %d and depending on&amp;nbsp;the format&amp;nbsp;string it calculated to offset to the actual datavariable&amp;nbsp;in the memory which is to be printed. Now when only %d will be present in the printf then compiler will&amp;nbsp;calculate&amp;nbsp;the correct offset (which will be the offset to access the integer&amp;nbsp;variable) but as the actual data object is to be printed is not present at that memory location so it will print what ever will be the contents of that memory location.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
3. Some compilers check&amp;nbsp;the format&amp;nbsp;string&amp;nbsp;and will&amp;nbsp;generate an error without the proper number and type of arguments for things like printf(…) and scanf(…).&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q:malloc() Function- What is the difference between “calloc(…)” and “malloc(…)”?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A&lt;/strong&gt;:1. calloc(…) allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number_of_elements * size).&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
malloc(…) takes in only a single&amp;nbsp;argument&amp;nbsp;which is the memory required in bytes. malloc(…) allocated bytes of memory and not blocks of memory like calloc(…).&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
2. malloc(…) allocates memory &amp;nbsp;and returns a void pointer to the allocated space, or NULL if there is insufficient memory available.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
calloc(…) allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated space .&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q: In printf() Function- What is the difference between “printf(…)” and “sprintf(…)”?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A&lt;/strong&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;:&amp;nbsp;&lt;/strong&gt;sprintf(…) writes data to the character array whereas printf(…) writes data to the standard output device.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Q:Compilation How to reduce a final size of executable?&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;A&lt;/strong&gt;:Size of the final executable can be reduced using dynamic linking for libraries.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; color: #7a7a7a; font-family: Georgia, Times, serif; font-size: 14px; line-height: 21px; margin-bottom: 15px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6557413289851198243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/tcs-technical-interview-questions.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6557413289851198243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6557413289851198243'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/tcs-technical-interview-questions.html' title='TCS technical interview questions'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-4493143909707259498</id><published>2012-09-04T22:47:00.001-07:00</published><updated>2012-09-04T22:47:51.496-07:00</updated><title type='text'>Made it to amdocs</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Finally my blog helped me a lot.&lt;br /&gt;
Most of the questions I was asked were there on my blog.&lt;br /&gt;
Hope it will help you too.Be a part of it and discuss with us any question you wanna ask&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/4493143909707259498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/made-it-to-amdocs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4493143909707259498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4493143909707259498'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/09/made-it-to-amdocs.html' title='Made it to amdocs'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-8150712320486452270</id><published>2012-08-27T06:49:00.003-07:00</published><updated>2012-08-27T06:49:30.072-07:00</updated><title type='text'>Why ++i is faster than i++?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
It is a very common question asked in most of the interviews. That&#39;s why I am not writing the name of any specific company.&lt;br /&gt;
&lt;br /&gt;
It is true that prefix operator is faster than postfix operator because in case of postfix operator&lt;br /&gt;
Value of variable is copied in memory , operation is performed and then increment is done.&lt;br /&gt;
While in case of prefix operator no extra storage is needed.&lt;br /&gt;
Hence it is memory extensive and faster as compare to postfix operator.&lt;br /&gt;
But use prefix operator with care.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;GUYS IF YOU REALLY LIKE THE POSTS OF THIS BLOG THEN PLEASE JOIN OUR BLOG.&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;AND HELP US TO PUT MORE POSTS LIKE THIS.&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;PLEASE HIT THE LIKE BUTTON BELOW&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/8150712320486452270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/why-i-is-faster-than-i.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/8150712320486452270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/8150712320486452270'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/why-i-is-faster-than-i.html' title='Why ++i is faster than i++?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-3783403143377234293</id><published>2012-08-26T22:37:00.002-07:00</published><updated>2012-08-26T22:37:28.372-07:00</updated><title type='text'>AMDOCS: Predict the output</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;ind&quot; style=&quot;margin-left: 3ex;&quot;&gt;&lt;code style=&quot;font-family: courier, monospace; font-size: 9pt;&quot;&gt;&lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;ind&quot; style=&quot;margin-left: 3ex;&quot;&gt;&lt;code style=&quot;font-family: courier, monospace; font-size: 9pt;&quot;&gt;&lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;ind&quot; style=&quot;margin-left: 3ex;&quot;&gt;&lt;code style=&quot;font-family: courier, monospace; font-size: 9pt;&quot;&gt;&lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;#include&lt;/span&gt; &amp;lt;stdio.h&amp;gt;

&lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; a, b, c, d;
   a = 3;
   b = 5;
   c = a, b;
   d = &lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;(&lt;/span&gt;a, b&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;)&lt;/span&gt;;

   printf&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;color: teal;&quot;&gt;&quot;c=%d  &quot;&lt;/span&gt;, c&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;)&lt;/span&gt;;
   printf&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;str&quot; style=&quot;color: teal;&quot;&gt;&quot;d=%d\n&quot;&lt;/span&gt;, d&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;)&lt;/span&gt;;

   &lt;span class=&quot;kw1&quot; style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; 0;
&lt;span class=&quot;punc&quot; style=&quot;color: red;&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/3783403143377234293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/amdocs-predict-output.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/3783403143377234293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/3783403143377234293'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/amdocs-predict-output.html' title='AMDOCS: Predict the output'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-4680699053930314514</id><published>2012-08-26T00:17:00.002-07:00</published><updated>2012-08-26T00:17:42.700-07:00</updated><title type='text'>TCS: Predict the output</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-style: italic; margin: 0px; padding: 0px;&quot;&gt;main()&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;{&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px;&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;&lt;/span&gt;char *p;&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;span style=&quot;margin: 0px; padding: 0px;&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;&lt;/span&gt;printf(&quot;%d %d &quot;,sizeof(*p),sizeof(p));&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;}&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;strong style=&quot;font-size: 12px; margin: 0px; padding: 0px;&quot;&gt;&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;Answer:&lt;/em&gt;&lt;/strong&gt;&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;span style=&quot;margin: 0px; padding: 0px;&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;&lt;/span&gt;&lt;span style=&quot;margin: 0px; padding: 0px;&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;&lt;/span&gt;1 2&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&quot;&gt;
&lt;strong style=&quot;font-size: 12px; margin: 0px; padding: 0px;&quot;&gt;&lt;em style=&quot;margin: 0px; padding: 0px;&quot;&gt;Explanation:&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;background-color: white; color: #474646; font-family: Arial; font-size: 11px; line-height: 16px; padding: 0px;&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; The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.&lt;/div&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/4680699053930314514/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/tcs-predict-output.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4680699053930314514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4680699053930314514'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/tcs-predict-output.html' title='TCS: Predict the output'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6958159568626260159</id><published>2012-08-22T06:05:00.002-07:00</published><updated>2012-08-22T06:05:33.816-07:00</updated><title type='text'>Pacenet: getchar() andputchar() in C are functions or macros? and Why?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Most C implementations impose a significant overhead for&lt;br /&gt;
each function call. Thus we may want to define things that look like&lt;br /&gt;
functions but do not have the function call overhead.&lt;br /&gt;
Due to which&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;getchar() and putchar()&lt;/span&gt; are usually implemented as macros to avoid having&lt;br /&gt;
to call a function for each character of input or output.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6958159568626260159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/pacenet-getchar-andputchar-in-c-are.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6958159568626260159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6958159568626260159'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/pacenet-getchar-andputchar-in-c-are.html' title='Pacenet: getchar() andputchar() in C are functions or macros? and Why?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-2434609057856564665</id><published>2012-08-21T11:17:00.002-07:00</published><updated>2012-08-21T11:17:32.274-07:00</updated><title type='text'>Linker: What does an exe file means in C?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
An important idea in C is separate compilation: several programs can be&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
compiled at different times and bound together. But the linker is&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
separate from the C compiler and can&#39;t know too much about the details&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
of C; how can it know how to combine C programs? Although linkers&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
don&#39;t understand C, they do understand machine language and memory&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
layout, and it is up to each C compiler to translate C programs into terms&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
that make sense to the linker.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A typical linker combines several object modules produced by a compiler&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
or assembler together into a single entity, sometimes called a load&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
module or an executable file, that the operating system can execute directly.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Some of those object modules are given directly as input to the linker;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
others are fetched on demand from a library of object modules containing&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
printf and similar things.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A linker typically views an object module as containing a collection of&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
external objects. Each external object represents the contents of some part&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
of the machine&#39;s memory and is identified by an external name. Thus&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
every function not declared static is an external object, as is every&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
external variable not declared static. Some implementations make&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
static functions and variables into external objects as well by&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
transforming their names somehow so that they do not clash with identically&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
named variables in other source program files.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Most linkers forbid two different external objects in a single load&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
module to have the same name. However, several object modules to be&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
combined into a single load module might contain identically-named&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
external objects. One important job of a linker is to handle these name&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
conflicts.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The simplest way to handle such a conflict is to prohibit it. This is&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
surely correct if the external objects are functions: a program that contains&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
two different functions with the same name should be rejected. The&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
problem is harder, though, if the objects are variables. Different linkers&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
handle that situation in different ways;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/2434609057856564665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/linker-what-does-exe-file-means-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/2434609057856564665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/2434609057856564665'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/linker-what-does-exe-file-means-in-c.html' title='Linker: What does an exe file means in C?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6584478530431096610</id><published>2012-08-20T11:34:00.000-07:00</published><updated>2012-08-20T11:34:36.728-07:00</updated><title type='text'>Who Killed the Software Engineer? (Hint: It Happened in College)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Reference :-&amp;nbsp;&lt;a href=&quot;http://www.datamation.com/career/article.php/11067_3722876_1#&quot;&gt;http://www.datamation.com/career/article.php/11067_3722876_1#&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I know it is a very old article, but every guy must know about it.&lt;br /&gt;
All those who say c language&#39;s scope is diminishing.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;A conversation with Robert Dewar is enough to make you wonder about the future of the American software engineer. Dewar, a professor emeritus of computer science at&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.nyu.edu/&quot; style=&quot;background-color: white; color: #008cb4; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; text-decoration: none;&quot; target=&quot;new&quot;&gt;New York University&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;, believes that U.S. colleges are turning out programmers who are – there’s no nice way to say this – essentially incompetent.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
To support his claim, Dewar penned a scathing broadside decrying today’s college-level computer science training. (The article was co-authored by Edmond Schonberg, also a CS professor emeritus at NYU.) Entitled&amp;nbsp;&lt;a href=&quot;http://www.stsc.hill.af.mil/CrossTalk/2008/01/0801DewarSchonberg.html&quot; style=&quot;color: #008cb4; text-decoration: none;&quot; target=&quot;new&quot;&gt;Computer Science Education: Where are the Software Engineers of Tomorrow?&lt;/a&gt;, the widely read article has prompted heated discussion throughout the tech industry.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;right&quot; border=&quot;1&quot; bordercolor=&quot;#ffffff&quot; cellpadding=&quot;5&quot; cellspacing=&quot;2&quot; style=&quot;background-color: white; color: black; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px; text-align: start; width: 175px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td bgcolor=&quot;#FFFFFF&quot; border=&quot;1&quot; bordercolor=&quot;#CCCC99&quot;&gt;&lt;img align=&quot;center&quot; alt=&quot;Robert Dewar, New York University&quot; src=&quot;http://itmanagement.earthweb.com/img/2008/01/robert-dewar.jpg&quot; /&gt;&lt;span style=&quot;font-family: arial, helvetica; font-size: x-small;&quot;&gt;&lt;strong&gt;&lt;em&gt;Robert Dewar&lt;br /&gt;Professor emeritus, NYU&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;&lt;br /&gt;
&lt;table border=&quot;0&quot; style=&quot;width: 100%px;&quot;&gt;&lt;/table&gt;
&lt;/em&gt;&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
To sum up Dewar’s argument: today’s college computer science programs aren’t rigorous enough, and don’t promote in-depth thinking and problem solving. Instead, in an effort to boost enrollment, CS programs focus on easily accessible curricula, and so fail to prepare students to compete with their international peers.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
One of the article’s main points (one that was misunderstood, Dewar tells me) is that the adoption of Java as a first programming language in college courses has led to this decline. Not exactly. Yes, Dewar believes that Java’s graphic libraries&amp;nbsp;allow students to cobble together software without understanding the underlying source code.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
But the problem with CS programs goes far beyond their focus on Java, he says.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
“A lot of it is, ‘Let’s make this all more fun.’ You know, ‘Math is not fun, let’s reduce math requirements. Algorithms are not fun, let’s get rid of them.&amp;nbsp;&lt;em&gt;Ewww&lt;/em&gt;&amp;nbsp;– graphic libraries, they’re&amp;nbsp;&lt;em&gt;fun&lt;/em&gt;. Let’s have people mess with libraries. And [forget] all this business about ‘command line’ – we’ll have people use nice visual interfaces where they can point and click and do fancy graphic stuff and have&amp;nbsp;&lt;em&gt;fun&lt;/em&gt;.&quot;&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
Dewar says his email in-box is crammed full of positive responses to his article, from students as well as employers. Many readers have thanked him for speaking up about a situation they believe needs addressing, he says.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;
One email was from an IT staffer who is working with a junior programmer. The older worker suggested that the young engineer check the call stack to see about a problem, but unfortunately, “he’d never heard of a call stack.”&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe frameborder=&quot;0&quot; scrolling=&quot;no&quot; src=&quot;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&quot; style=&quot;border: none; height: 80px; width: 450px;&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6584478530431096610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/who-killed-software-engineer-hint-it.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6584478530431096610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6584478530431096610'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/who-killed-software-engineer-hint-it.html' title='Who Killed the Software Engineer? (Hint: It Happened in College)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6436094015855281020</id><published>2012-08-19T00:49:00.001-07:00</published><updated>2012-08-19T07:00:59.483-07:00</updated><title type='text'>A program which produces its own source code as its output?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;#include&amp;lt;conio.h&amp;gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;int main(){&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;clrscr();&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; FILE *fp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; char c;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; fp = fopen(__FILE__,&quot;r&quot;);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; do{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c= getc(fp);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;putchar(c);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; }&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; while(c!=EOF);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; fclose(fp);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; getch();&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&amp;nbsp; &amp;nbsp; return 0;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;

&lt;iframe frameborder=&#39;0&#39; scrolling=&#39;no&#39; src=&#39;https://www.facebook.com/plugins/like.php?href=cforgeeks.blogspot.com&#39; style=&#39;border:none; width:450px; height:80px&#39;/&gt;&lt;/iframe&gt;</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6436094015855281020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/a-program-which-produces-its-own-source.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6436094015855281020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6436094015855281020'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/a-program-which-produces-its-own-source.html' title='A program which produces its own source code as its output?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-5870712128858262974</id><published>2012-08-18T07:19:00.001-07:00</published><updated>2012-08-18T07:19:39.805-07:00</updated><title type='text'>Tutorial:Memory Allocation in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
In this chapter, we&#39;ll meet&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;, C&#39;s dynamic memory allocation function, and we&#39;ll cover dynamic memory allocation in some detail.&lt;br /&gt;
As we begin doing dynamic memory allocation, we&#39;ll begin to see (if we haven&#39;t seen it already) what pointers can really be good for. Many of the pointer examples in the previous chapter (those which used pointers to access arrays) didn&#39;t do all that much for us that we couldn&#39;t have done using arrays. However, when we begin doing dynamic memory allocation, pointers are the only way to go, because what&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;returns is a pointer to the memory it gives us. (Due to the equivalence between pointers and arrays, though, we will still be able to think of dynamically allocated regions of storage as if they were arrays, and even to use array-like subscripting notation on them.)&lt;br /&gt;
You have to be careful with dynamic memory allocation.&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;operates at a pretty ``low level&#39;&#39;; you will often find yourself having to do a certain amount of work to manage the memory it gives you. If you don&#39;t keep accurate track of the memory which&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;has given you, and the pointers of yours which point to it, it&#39;s all too easy to accidentally use a pointer which points ``nowhere&#39;&#39;, with generally unpleasant results. (The basic problem is that if you assign a value to the location pointed to by a pointer:&lt;br /&gt;
&lt;pre&gt; *p = 0;
&lt;/pre&gt;
and if the pointer&amp;nbsp;&lt;tt&gt;p&lt;/tt&gt;&amp;nbsp;points ``nowhere&#39;&#39;, well actually it can be construed to point somewhere, just not where you wanted it to, and that ``somewhere&#39;&#39; is where the 0 gets written. If the ``somewhere&#39;&#39; is memory which is in use by some other part of your program, or even worse, if the operating system has not protected itself from you and ``somewhere&#39;&#39; is in fact in use by the operating system, things could get ugly.)
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A problem with many simple programs, including in particular little teaching programs such as we&#39;ve been writing so far, is that they tend to use fixed-size arrays which may or may not be big enough. We have an array of 100&amp;nbsp;&lt;tt&gt;int&lt;/tt&gt;s for the numbers which the user enters and wishes to find the average of--what if the user enters 101 numbers? We have an array of 100&amp;nbsp;&lt;tt&gt;char&lt;/tt&gt;s which we pass to&amp;nbsp;&lt;tt&gt;getline&lt;/tt&gt;&amp;nbsp;to receive the user&#39;s input--what if the user types a line of 200 characters? If we&#39;re lucky, the relevant parts of the program check how much of an array they&#39;ve used, and print an error message or otherwise gracefully abort before overflowing the array. If we&#39;re not so lucky, a program may sail off the end of an array, overwriting other data and behaving quite badly. In either case, the user doesn&#39;t get his job done. How can we avoid the restrictions of fixed-size arrays?&lt;br /&gt;
The answers all involve the standard library function&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;. Very simply,&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;returns a pointer to&amp;nbsp;&lt;i&gt;n&lt;/i&gt;&amp;nbsp;bytes of memory which we can do anything we want to with. If we didn&#39;t want to read a line of input into a fixed-size array, we could use&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;, instead. Here&#39;s the first step:&lt;br /&gt;
&lt;pre&gt; #include &amp;lt;stdlib.h&amp;gt;

 char *line;
 int linelen = 100;
 line = malloc(linelen);
 /* incomplete -- malloc&#39;s return value not checked */
 getline(line, linelen);
&lt;/pre&gt;
&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;is declared in&amp;nbsp;&lt;tt&gt;&amp;lt;stdlib.h&amp;gt;&lt;/tt&gt;, so we&amp;nbsp;&lt;tt&gt;#include&lt;/tt&gt;&amp;nbsp;that header in any program that calls&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;. A ``byte&#39;&#39; in C is, by definition, an amount of storage suitable for storing one character, so the above invocation of&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;gives us exactly as many&amp;nbsp;&lt;tt&gt;char&lt;/tt&gt;s as we ask for. We could illustrate the resulting pointer like this:&lt;br /&gt;
&lt;img src=&quot;http://www.eskimo.com/~scs/cclass/notes/fig11.1.gif&quot; /&gt;&lt;br /&gt;
The 100 bytes of memory (not all of which are shown) pointed to by&amp;nbsp;&lt;tt&gt;line&lt;/tt&gt;&amp;nbsp;are those allocated by&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;. (They are brand-new memory, conceptually a bit different from the memory which the compiler arranges to have allocated automatically for our conventional variables. The 100 boxes in the figure don&#39;t have a name next to them, because they&#39;re not storage for a variable we&#39;ve declared.)&lt;br /&gt;
As a second example, we might have occasion to allocate a piece of memory, and to copy a string into it with&amp;nbsp;&lt;tt&gt;strcpy&lt;/tt&gt;:&lt;br /&gt;
&lt;pre&gt; char *p = malloc(15);
 /* incomplete -- malloc&#39;s return value not checked */
 strcpy(p, &quot;Hello, world!&quot;);
&lt;/pre&gt;
&lt;br /&gt;
When copying strings, remember that all strings have a terminating&amp;nbsp;&lt;tt&gt;\0&lt;/tt&gt;&amp;nbsp;character. If you use&amp;nbsp;&lt;tt&gt;strlen&lt;/tt&gt;&amp;nbsp;to count the characters in a string for you, that count will&amp;nbsp;&lt;em&gt;not&lt;/em&gt;&amp;nbsp;include the trailing&amp;nbsp;&lt;tt&gt;\0&lt;/tt&gt;, so you must add one before calling&lt;tt&gt;malloc&lt;/tt&gt;:&lt;br /&gt;
&lt;pre&gt; char *somestring, *copy;
 ...
 copy = malloc(strlen(somestring) + 1);  /* +1 for \0 */
 /* incomplete -- malloc&#39;s return value not checked */
 strcpy(copy, somestring);
&lt;/pre&gt;
&lt;br /&gt;
What if we&#39;re not allocating characters, but integers? If we want to allocate 100&amp;nbsp;&lt;tt&gt;int&lt;/tt&gt;s, how many bytes is that? If we know how big&amp;nbsp;&lt;tt&gt;int&lt;/tt&gt;s are on our machine (i.e. depending on whether we&#39;re using a 16- or 32-bit machine) we could try to compute it ourselves, but it&#39;s much safer and more portable to let C compute it for us. C has a&amp;nbsp;&lt;tt&gt;sizeof&lt;/tt&gt;&amp;nbsp;operator, which computes the size, in bytes, of a variable or type. It&#39;s just what we need when calling&lt;tt&gt;malloc&lt;/tt&gt;. To allocate space for 100&amp;nbsp;&lt;tt&gt;int&lt;/tt&gt;s, we could call&lt;br /&gt;
&lt;pre&gt; int *ip = malloc(100 * sizeof(int));
&lt;/pre&gt;
The use of the&amp;nbsp;&lt;tt&gt;sizeof&lt;/tt&gt;&amp;nbsp;operator tends to look like a function call, but it&#39;s really an operator, and it does its work at compile time.&lt;br /&gt;
Since we can use array indexing syntax on pointers, we can treat a pointer variable after a call to&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;almost exactly as if it were an array. In particular, after the above call to&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;initializes&amp;nbsp;&lt;tt&gt;ip&lt;/tt&gt;&amp;nbsp;to point at storage for 100&amp;nbsp;&lt;tt&gt;int&lt;/tt&gt;s, we can access&amp;nbsp;&lt;tt&gt;ip[0]&lt;/tt&gt;,&amp;nbsp;&lt;tt&gt;ip[1]&lt;/tt&gt;, ... up to&amp;nbsp;&lt;tt&gt;ip[99]&lt;/tt&gt;. This way, we can get the effect of an array even if we don&#39;t know until run time how big the ``array&#39;&#39; should be. (In a later section we&#39;ll see how we might deal with the case where we&#39;re not even sure at the point we begin using it how big an ``array&#39;&#39; will eventually have to be.)&lt;br /&gt;
Our examples so far have all had a significant omission: they have not checked&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&#39;s return value. Obviously, no real computer has an infinite amount of memory available, so there is no guarantee that&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;will be able to give us as much memory as we ask for. If we call&amp;nbsp;&lt;tt&gt;malloc(100000000)&lt;/tt&gt;, or if we call&amp;nbsp;&lt;tt&gt;malloc(10)&lt;/tt&gt;&amp;nbsp;10,000,000 times, we&#39;re probably going to run out of memory.&lt;br /&gt;
When&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;is unable to allocate the requested memory, it returns a&amp;nbsp;&lt;dfn&gt;null pointer&lt;/dfn&gt;. A null pointer, remember, points definitively nowhere. It&#39;s a ``not a pointer&#39;&#39; marker; it&#39;s not a pointer you can use. (As we said in section 9.4, a null pointer can be used as a failure return from a function that returns pointers, and&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;is a perfect example.) Therefore, whenever you call&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;, it&#39;s vital to check the returned pointer before using it! If you call&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;, and it returns a null pointer, and you go off and use that null pointer as if it pointed somewhere, your program probably won&#39;t last long. Instead, a program should immediately check for a null pointer, and if it receives one, it should at the very least print an error message and exit, or perhaps figure out some way of proceeding without the memory it asked for. But it cannot go on to use the null pointer it got back from&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;in any way, because that null pointer by definition points nowhere. (``It cannot use a null pointer in any way&#39;&#39; means that the program cannot use the&amp;nbsp;&lt;tt&gt;*&lt;/tt&gt;&amp;nbsp;or&amp;nbsp;&lt;tt&gt;[]&lt;/tt&gt;&amp;nbsp;operators on such a pointer value, or pass it to any function that expects a valid pointer.)&lt;br /&gt;
A call to&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;, with an error check, typically looks something like this:&lt;br /&gt;
&lt;pre&gt; int *ip = malloc(100 * sizeof(int));
 if(ip == NULL)
  {
  printf(&quot;out of memory\n&quot;);
  &lt;i&gt;exit or return&lt;/i&gt;
  }
&lt;/pre&gt;
After printing the error message, this code should return to its caller, or exit from the program entirely; it cannot proceed with the code that would have used&amp;nbsp;&lt;tt&gt;ip&lt;/tt&gt;.&lt;br /&gt;
Of course, in our examples so far, we&#39;ve still limited ourselves to ``fixed size&#39;&#39; regions of memory, because we&#39;ve been calling&amp;nbsp;&lt;tt&gt;malloc&lt;/tt&gt;&amp;nbsp;with fixed arguments like 10 or 100. (Our call to&amp;nbsp;&lt;tt&gt;getline&lt;/tt&gt;&amp;nbsp;is still limited to 100-character lines, or whatever number we set the&amp;nbsp;&lt;tt&gt;linelen&lt;/tt&gt;&amp;nbsp;variable to; our&amp;nbsp;&lt;tt&gt;ip&lt;/tt&gt;&amp;nbsp;variable still points at only 100&amp;nbsp;&lt;tt&gt;int&lt;/tt&gt;s.) However, since the sizes are now values which can in principle be determined at run-time, we&#39;ve at least moved beyond having to recompile the program (with a bigger array) to accommodate longer lines, and with a little more work, we could arrange that the ``arrays&#39;&#39; automatically grew to be as large as required. (For example, we could write something like&amp;nbsp;&lt;tt&gt;getline&lt;/tt&gt;&amp;nbsp;which could read the longest input line actually seen.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/5870712128858262974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/tutorialmemory-allocation-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5870712128858262974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5870712128858262974'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/tutorialmemory-allocation-in-c.html' title='Tutorial:Memory Allocation in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-1016120612553038348</id><published>2012-08-17T03:33:00.002-07:00</published><updated>2012-08-17T03:33:13.950-07:00</updated><title type='text'>BeginnerLevel: Order of evaluation of following expression? a &lt; b &amp;&amp; c &lt; d</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;(expression1) &amp;lt; &amp;nbsp;(expression2) &amp;amp;&amp;amp; (expression3) &amp;lt; (expression4)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;For such type of expressions , you must have a sound knowledge of precedence table.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;But this is an easiest example.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;We know that &#39;&amp;lt;&#39; operator has higher precedence than &#39;&amp;amp;&amp;amp;&#39; .&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Hence first of all &#39;&amp;lt;&#39; will be executed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;But there is not&amp;nbsp;surety&amp;nbsp;whether expression1 will be executed first or expression 2.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;The result of first &#39;&amp;lt;&#39; will decide whether expression after &#39;&amp;amp;&amp;amp;&#39; will get executed or not.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;If the result of first &#39;&amp;lt;&#39; is false the second &#39;&amp;lt;&#39; will not get executed. Else the same procedure will be followed for expression after &#39;&amp;amp;&amp;amp;&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: red; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/i&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;GUYS IF YOU REALLY LIKE THE POSTS OF THIS BLOG THEN PLEASE JOIN OUR BLOG.&lt;/u&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;AND HELP US TO PUT MORE POSTS LIKE THIS.&lt;/u&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Verdana, sans-serif;&quot;&gt;
&lt;i&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;PLEASE HIT THE LIKE BUTTON ON RIGHT HAND SIDE.&lt;/u&gt;&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/1016120612553038348/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/beginnerlevel-order-of-evaluation-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/1016120612553038348'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/1016120612553038348'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/beginnerlevel-order-of-evaluation-of.html' title='BeginnerLevel: Order of evaluation of following expression? a &lt; b &amp;&amp; c &lt; d'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-5597641048001440511</id><published>2012-08-16T22:34:00.000-07:00</published><updated>2012-08-16T22:44:41.527-07:00</updated><title type='text'>Beginner level: %g,%e,%E,%G in C</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;GUYS IF YOU REALLY LIKE THE POSTS OF THIS BLOG THEN PLEASE JOIN OUR BLOG.&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;AND HELP US TO PUT MORE POSTS LIKE THIS.&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;PLEASE HIT THE LIKE BUTTON ON RIGHT HAND SIDE.&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1 style=&quot;color: #0062b8; font-family: Tahoma, sans-serif; font-size: 25px; font-weight: normal;&quot;&gt;
printf()&lt;/h1&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;Syntax:&lt;/i&gt;&lt;br /&gt;
&lt;pre style=&quot;display: inline; font-size: 13px;&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
int printf( const char *format, ... );&lt;/pre&gt;
&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;Description:&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;The printf() function prints output to&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.elook.org/computing/standard-input---output.htm&quot; style=&quot;color: #0062b8; font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;STDOUT&lt;/a&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;, according to&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;format&lt;/i&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;and other arguments passed to printf(). The string&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;format&lt;/i&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;consists of two types of items - characters that will be printed to the screen, and&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;format&lt;/i&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;commands that define how the other arguments to printf() are displayed. Basically, you specify a&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;format&lt;/i&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;string that has text in it, as well as &quot;special&quot; characters that map to the other arguments of printf().&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;The %s means, &quot;insert the first argument, a string, right here.&quot; The %d indicates that the second argument (an integer) should be placed there. There are different %-codes for different variable types, as well as options to limit the length of the variables and whatnot.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;pre style=&quot;display: inline; font-size: 13px;&quot;&gt;Code  Format

----    ------

%c  character

%d  signed integers

%i  signed integers

%e  scientific notation, with a lowercase &quot;e&quot;

%E  scientific notation, with a uppercase &quot;E&quot;

%f  floating point

%g  use %e or %f, whichever is shorter

%G  use %E or %f, whichever is shorter

%o  octal

%s  a string of characters

%u  unsigned integer

%x  unsigned hexadecimal, with lowercase letters

%X  unsigned hexadecimal, with uppercase letters

%p  a pointer

%n  the argument shall be a pointer to an integer into which is placed the number of characters written so far

%%  a &#39;%&#39; sign&lt;/pre&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&lt;/span&gt;&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;An integer placed between a % sign and the&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;format&lt;/i&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;command acts as a minimum field width specifier, and pads the output with spaces or zeros to make it long enough. If you want to pad with zeros, place a zero before the minimum field width specifier. You can use a precision modifier, which has different meanings depending on the&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;format&lt;/i&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;code being used.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;ul style=&quot;font-family: Arial, sans-serif; font-size: 13px; line-height: 1.4em;&quot;&gt;&lt;br /&gt;
&lt;li&gt;With %e, %E, and %f, the precision modifier lets you specify the number of decimal places desired. For example,&lt;br /&gt;&lt;br /&gt;&lt;pre style=&quot;display: inline;&quot;&gt;%12.6f&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;will display a floating number at least 12 digits wide, with six decimal places.&lt;/li&gt;
&lt;br /&gt;
&lt;li&gt;With %g and %G, the precision modifier determines the maximum number of significant digits displayed.&lt;/li&gt;
&lt;br /&gt;
&lt;li&gt;With %s, the precision modifer simply acts as a&amp;nbsp;&lt;b&gt;maximum&lt;/b&gt;field length, to complement the minimum field length that precedes the period.&lt;/li&gt;
&lt;/ul&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;All of printf()&#39;s output is right-justified, unless you place a minus sign right after the % sign. For example,&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;pre style=&quot;display: inline; font-size: 13px;&quot;&gt;    %-12.4f&lt;/pre&gt;
&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;will display a floating point number with a minimum of 12 characters, 4 decimal places, and left justified. You may modify the %d, %i, %o, %u, and %x type specifiers with the letter&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;l&lt;/b&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;and the letter&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;h&lt;/b&gt;&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;to specify long and short data types (e.g. %hd means a short integer). The %e, %f, and %g type specifiers can have the letter l before them to indicate that a double follows. The %g, %f, and %e type specifiers can be preceded with the character &#39;#&#39; to ensure that the decimal point will be present, even if there are no decimal digits. The use of the &#39;#&#39; character with the %x type specifier indicates that the hexidecimal number should be printed with the &#39;0x&#39; prefix. The use of the &#39;#&#39; character with the %o type specifier indicates that the octal value should be displayed with a 0 prefix.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;You can also include constant escape sequences in the output string.&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;The return value of printf() is the number of characters printed, or a negative number if an error occurred.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot; /&gt;
&lt;i style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;Example:&lt;/i&gt;&lt;br /&gt;
&lt;pre style=&quot;display: inline; font-size: 13px;&quot;&gt;char name[20] = &quot;Bob&quot;;
int age = 21;
printf( &quot;Hello %s, you are %d years old\n&quot;, name, age );

OUTPUT: Hello Bob, you are 21 years old&lt;/pre&gt;
&lt;span style=&quot;font-family: Arial, sans-serif; font-size: 13px;&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/5597641048001440511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/beginner-level-geeg-in-c.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5597641048001440511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5597641048001440511'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/beginner-level-geeg-in-c.html' title='Beginner level: %g,%e,%E,%G in C'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-1999213072217373572</id><published>2012-08-16T05:17:00.004-07:00</published><updated>2012-08-18T07:42:51.722-07:00</updated><title type='text'>google:Why index of array always starts from 0</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;A simple question to all programmers that why the index of an array starts from 0 instead from 1.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;was it a mistake of compiler designer in history or it has some reason behind it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;Obviously it has a reason behind it. What is that reason?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Being honest to yourself, If you don&#39;t know the answer , Please join our site and contribute to society&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/1999213072217373572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/googlereason-why-index-of-array-starts.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/1999213072217373572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/1999213072217373572'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/googlereason-why-index-of-array-starts.html' title='google:Why index of array always starts from 0'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-273266433273038734</id><published>2012-08-15T21:52:00.000-07:00</published><updated>2012-08-15T23:36:29.541-07:00</updated><title type='text'>Yaho!: Easiest question ever(judge the output)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;What should be the output of this program?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;void main()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; int y=5,z=6;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; if(y || ++z)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; { &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;printf(&quot;\ny=%d&quot;,y);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp;printf(&quot;z=%d&quot;,z);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;output:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;y= ?(guess)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;z=?(guess)&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/273266433273038734/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/yaho-easiest-question-everjudge-output.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/273266433273038734'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/273266433273038734'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/yaho-easiest-question-everjudge-output.html' title='Yaho!: Easiest question ever(judge the output)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-4518749143413513879</id><published>2012-08-15T11:37:00.000-07:00</published><updated>2012-08-15T11:37:36.772-07:00</updated><title type='text'>Amazon: You are probably the master of C, if you can answer this beginner level question</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Why we use inclusive lower bond and exclusive upper bond for array?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;confused?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;i.e why we see this syntax&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;int a[10];&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;for(i=0;i&amp;lt;10;i++)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;instead of&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;int a[10];&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;for(i=0;i&amp;lt;=9;i++)&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Being faithful to your inner soul, If you don&#39;t know the answer, join our site and subscribe for latest updates.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;And don&#39;t forget to ask the answer of this question.&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/4518749143413513879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/amazon-you-are-probably-master-of-c-if.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4518749143413513879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/4518749143413513879'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/amazon-you-are-probably-master-of-c-if.html' title='Amazon: You are probably the master of C, if you can answer this beginner level question'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-6662543491419959220</id><published>2012-08-12T12:16:00.000-07:00</published><updated>2012-08-12T12:17:21.796-07:00</updated><title type='text'>C related books</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
A list of all C good &amp;nbsp;books&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.dropbox.com/sh/dfgr66w88zghz67/TgDwiauXt2&quot;&gt;All C books&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6662543491419959220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/c-related-books.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6662543491419959220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6662543491419959220'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/c-related-books.html' title='C related books'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-6486678783414908536</id><published>2012-08-12T10:46:00.001-07:00</published><updated>2012-08-12T10:46:26.285-07:00</updated><title type='text'>Difference between float *g( ); and (*h)( );</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;float *g(), (*h)();&lt;/i&gt;&lt;/span&gt;&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Here g( ) is function returning a pointer to a float type value&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;Whereas (*h) is a pointer type variable pointing to a function.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;Being honest guys If you didn&#39;t know the answer ,join our site. We are doing our best for it.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;We try to find questions from around 10 best books Of C.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;So contribute to us and be a part of our C family.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/6486678783414908536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/difference-between-float-g-and-h.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6486678783414908536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/6486678783414908536'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/difference-between-float-g-and-h.html' title='Difference between float *g( ); and (*h)( );'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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-8666171843124727263.post-9066530470929427323</id><published>2012-08-12T10:03:00.000-07:00</published><updated>2012-08-12T10:03:13.673-07:00</updated><title type='text'>TCS: Post the output of following statement :-  a+++++b</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;What should be the output of the following code if we print, &amp;nbsp;like&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;void main()&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;{&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;int a=4,b=3,x;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;x=a+++++b;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;printf(&quot;Value of x is :%d&quot;, x);&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;i&gt;}&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;----------------------------------&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Being honest, If you dont know the answer join our site for all latest questions like this.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Have fun!!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/9066530470929427323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/tcs-post-output-of-following-statement.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/9066530470929427323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/9066530470929427323'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/tcs-post-output-of-following-statement.html' title='TCS: Post the output of following statement :-  a+++++b'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8666171843124727263.post-5472865560062180885</id><published>2012-08-11T04:29:00.004-07:00</published><updated>2012-08-11T04:29:57.449-07:00</updated><title type='text'>Apple: In which case exit() and return() function works in same manner?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;&amp;nbsp;The exit() function is used to exit your program and return control&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;to the operating system. The return statement is used to return from a&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;function and return control to the calling function. If you issue a return&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;from the main() function, you are essentially returning control to the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;calling function, which is the operating system. In this case, the return&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: Verdana, sans-serif;&quot;&gt;statement and exit() function are similar.&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cforgeeks.blogspot.com/feeds/5472865560062180885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/apple-in-which-case-exit-and-return.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5472865560062180885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8666171843124727263/posts/default/5472865560062180885'/><link rel='alternate' type='text/html' href='http://cforgeeks.blogspot.com/2012/08/apple-in-which-case-exit-and-return.html' title='Apple: In which case exit() and return() function works in same manner?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07276256432536901359</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>