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

<channel>
	<title>Yusuf Mücahit &#187; C</title>
	<atom:link href="http://yusufmucahit.com/category/programming/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://yusufmucahit.com</link>
	<description>ODTÜ - Bilgisayar Mühendisliği</description>
	<lastBuildDate>Tue, 19 May 2015 19:52:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Introduction to Programming with C &#8211; First Program</title>
		<link>http://yusufmucahit.com/en/c-ile-programlamaya-giris-ilk-program/</link>
		<comments>http://yusufmucahit.com/en/c-ile-programlamaya-giris-ilk-program/#comments</comments>
		<pubDate>Sat, 25 Jan 2014 11:24:10 +0000</pubDate>
		<dc:creator><![CDATA[Yusuf]]></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C programing]]></category>
		<category><![CDATA[C programlama]]></category>
		<category><![CDATA[C programlamaya giriş]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[Hello world]]></category>
		<category><![CDATA[İlk program]]></category>
		<category><![CDATA[introduction to programming]]></category>
		<category><![CDATA[Programlamaya giriş]]></category>

		<guid isPermaLink="false">http://yusufmucahit.com/?p=48</guid>
		<description><![CDATA[The basic overview of C program is like that; #include < stdio.h > int main(){ printf("Hello world!"); /* prints hello world to the screen */ return 0; } Let examine]]></description>
				<content:encoded><![CDATA[<p>The basic overview of C program is like that;</p>
<pre class="brush:c">#include < stdio.h >

int main(){

    printf("Hello world!");
    /* prints hello world to the screen */
    return 0;
}</pre>
<p>Let examine these lines one by one:</p>
<pre class="brush:c">#include < stdio.h ></pre>
<p>With &#8220;#include&#8221; command we say to compiler which header files our program needs and include them by putting the name of header file into < and > symbols. Standart input and output functions of C stand in that header file(stdio.h).</p>
<pre class="brush:c">int main()</pre>
<p>Actually main is a function and our program looks for a function called main then runs it. The &#8220;int&#8221; word implies that this function returns an integer data type. Data types and functions will be in my next posts.{ and } symbols express that the lines between them belong to that function.</p>
<pre class="brush:c">printf("Hello world!\n");</pre>
<p>printf is a function which prints a string to the screen. Sending a string between quotation marks is enough to call this function. &#8220;\n&#8221; is the new line character. &#8220;;&#8221; means this is the end of the line and this is compulsory. Unless we put semicolon end of the line, compiler sends a syntax error and does not compile our program.</p>
<pre class="brush:c">/* prints hello world to the screen */</pre>
<p>/* */ symbols prevent compiler from reading lines between them. So why we need these lines, if compiler does not read? These are for adding comments to our code. In other words, if anybody or we read the program again, understand better how any line works with these comments. If our comment is only one line length, we can use // symbol.</p>
<pre class="brush:c">/*
This
is
a
multiple
comment
block
*/
// This is one line comment</pre>
<pre class="brush:c">return 0;</pre>
<p>I&#8217;ve mentioned that main is a function which returns an integer. This line refers the end of the function and process. We use this to halt program.</p>
<p>This is it. We wrote the first C program. <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://yusufmucahit.com/en/c-ile-programlamaya-giris-ilk-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Importance of Brackets When Defining Macros</title>
		<link>http://yusufmucahit.com/en/makro-tanimlarken-parentezlerin-onemi/</link>
		<comments>http://yusufmucahit.com/en/makro-tanimlarken-parentezlerin-onemi/#comments</comments>
		<pubDate>Sun, 28 Jul 2013 14:27:38 +0000</pubDate>
		<dc:creator><![CDATA[Yusuf]]></dc:creator>
				<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://yusufmucahit.com/?p=19</guid>
		<description><![CDATA[In C programming, there are some points to be careful while using &#8220;#define&#8221; macro. One of them is use of brackets because these macros do not work exactly how in]]></description>
				<content:encoded><![CDATA[<p>In C programming, there are some points to be careful while using &#8220;#define&#8221; macro. One of them is use of brackets because these macros do not work exactly how in the mind of humans. If you see lots of useless paranthesis in others codes you should read this article.  Macros do exactly what you want from them without examining and calculating. Without further ado, let me give an example of some codes:</p>
<pre class="brush:c">#include 
#define ABS(x) x&gt;0?x:-x

int main()
{
    printf("%d\n",ABS(3-5));
    return 0;
}</pre>
<p>In this code segment the macro called ABS, if the value sent to it is less then 0 puts &#8220;-&#8221; sign in front of this value, else leaves it as it is. In short, the absolute value. The expectation is +2 because 3-5=-2. However, the value which is sent to macro is not -2 but 3-5. The difference is that macros do not calculate the argument and work with the result, like functions. Macros works like dictionaries. Just before the compile they make the modifications and finishes their jobs, like in the basic notepad programs, find and change module (ctrl+h). After this tip, analyzing the ABS macro again shows us putting &#8220;-&#8221; sign in front of the 3-5 gives -3-5 which is equal to -8. In fact,there is nothing to be surprised, is there? <img src="http://yusufmucahit.com/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Then, here is the solution:</p>
<pre class="brush:c">#define ABS(x) (x)&gt;0?(x):-(x)</pre>
<p>If we defined the macro with paranthesis, there would not be any problem. Another example is;</p>
<pre class="brush:c">#include 
#define SQR(x) (x*x)
int main()
{
    printf("%d\n",SQR(2+3));      
    return 0;
}</pre>
<p>I do not make same explenations again and again. The expectation is 2+3=5, so the result is 5*5=25. Whereas SQR turns 2+3 value into 2+3*2+3. It is same with 2+(3*2)+3 in maths, so with 11 not 25.</p>
<pre class="brush:c">#define SQR(x) ((x)*(x))</pre>
<p>Defining the macro with useless(!) brackets, makes all c programmers happy. <img src="http://yusufmucahit.com/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://yusufmucahit.com/en/makro-tanimlarken-parentezlerin-onemi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
