Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
🔒 NordVPN Premium – 3 Months
hrdilshan
Updated:
Yesterday at 8:29 PM
🚀 Microsoft Office 365 Pro Plus – Lifetime Access! 🚀
hrdilshan
Updated:
Yesterday at 8:28 PM
Linkedin Premium Business / Careere /Sales Navigator - 1/2/3/6/9/12 Months - Reddem Link
hrdilshan
Updated:
Yesterday at 8:27 PM
Colombo
YEYE 3 in 1 Instant Coffee Mix 50 Sachet
Romeshka
Updated:
Wednesday at 12:16 AM
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Jul 3, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
Lesson 03: C Programming
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="x-pert" data-source="post: 657645" data-attributes="member: 837"><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Please read <a href="http://www.elakiri.com/forum/showthread.php?t=35788" target="_blank">lesson 01</a> and <a href="http://www.elakiri.com/forum/showthread.php?t=35876" target="_blank">lesson 02</a> to get a clear idea befor reading this.... </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Thought to start this lesson with some words of ma mate L Flon. <img src="/styles/default/xenforo/smilies/default/lol.gif" class="smilie" loading="lazy" alt=":lol:" title="LOL :lol:" data-shortname=":lol:" /> </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">He once said.... “There is no programming language, no matter how structured, that will prevent Programmers from writing bad programs.” </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Keeping that in mind... Lets start this. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">OK... First thing first. How to insert a comment to the codings and what is the purpose of inserting comments to your codes. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">You might think that programmers will always write codings. No guys. That’s a myth. <img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Far more time is spent maintaining, upgrading and debugging existing code. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Actually according to my data sources the amount of time which we spend in maintaining is skyrocketing. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">From 1980 to 2000 the average lines of code went from 23,000 to 2,200,000. The average age of an application went up from 4.75 years to 11.3 years. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">So just the same as a human.... Source codes also should be maintained within its life time. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">When comes to maintaining codes, there are 2 big big problems which we have to face.</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">1) Code is difficult to correct, coz the authors even can’t understand it.</span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">2) Modifications or upgrades are difficult to make coz the programmer should spend a considerable amount of time figuring out what the program does. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">To make your coding more readable and more understandable, you have to include comments appropriately. Usually it is recommended to have 40% of your lines of code as comments. <img src="/styles/default/xenforo/smilies/default/P.gif" class="smilie" loading="lazy" alt=":P" title=":P :P" data-shortname=":P" /></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Comments in C language starts with a slash asterisk <strong>(/*) </strong>and ends with an asterisk slash <strong>(*/).</strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"><strong>/*</strong> *******************************************************</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* hello -- program to print "Hello World". On the screen.*</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* Author: NRYDDS a.k.a x-pert. *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* Purpose: Demonstration of a simple program. *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* Usage: *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* Other comments: exclusively from <a href="http://www.elakiri.com" target="_blank">http://www.elakiri.com</a> *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* Runs the program and the message appears. *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">******************************************************* <strong>*/</strong></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">#include <stdio.h></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">int main()</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">{</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/* Tell the world hello */</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">printf("Hello World\n");</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">return (0);</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">}</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">In the above example, I have <strong>Bold</strong> the start and the end of the comment. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">All the characters which are between those two points belong to the comment. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">These types of comments are called ‘comment boxes’. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Less important comments are not boxed. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px">Such as <span style="font-family: 'Courier New'">/* Tell the world hello */ </span>in the above example. </span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><strong>Some commenting styles as in: Oualline, S. Practical C programming, O’Reilly Publications</strong></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/********************************************************</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">********************************************************</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">******** WARNING: This is an example of a *******</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">******** warning message that grabs the *******</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">******** attention of the programmer. *******</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">********************************************************</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">********************************************************/</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/*------------> Another, less important warning <--------*/</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/*>>>>>>>>>>>> Major section header <<<<<<<<<<<<<<<< */</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/********************************************************</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* We use boxed comments in this book to denote the *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* beginning of a section or program. *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">********************************************************/</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/*------------------------------------------------------*\</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* This is another way of drawing boxes. *</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">\*------------------------------------------------------*/</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/*</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* This is the beginning of a section.</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* ^^^^ ^^ ^^^ ^^^^^^^^^ ^^ ^ ^^^^^^^</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">*</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* In the paragraph that follows, we explain what</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* the section does and how it works.</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">*/</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'"></span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/*</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* A medium-level comment explaining the next</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* dozen (or so) lines of code. Even though we don't have</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">* the bold typeface, we can **emphasize** words.</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">*/</span></span></span></p><p><span style="font-family: 'Arial'"><span style="font-size: 12px"><span style="font-family: 'Courier New'">/* A simple comment explaining the next line */</span></span></span></p></blockquote><p></p>
[QUOTE="x-pert, post: 657645, member: 837"] [FONT="Arial"][SIZE="3"]Please read [URL="http://www.elakiri.com/forum/showthread.php?t=35788"]lesson 01[/URL] and [URL="http://www.elakiri.com/forum/showthread.php?t=35876"]lesson 02[/URL] to get a clear idea befor reading this.... Thought to start this lesson with some words of ma mate L Flon. :lol: He once said.... “There is no programming language, no matter how structured, that will prevent Programmers from writing bad programs.” Keeping that in mind... Lets start this. OK... First thing first. How to insert a comment to the codings and what is the purpose of inserting comments to your codes. You might think that programmers will always write codings. No guys. That’s a myth. :D Far more time is spent maintaining, upgrading and debugging existing code. Actually according to my data sources the amount of time which we spend in maintaining is skyrocketing. From 1980 to 2000 the average lines of code went from 23,000 to 2,200,000. The average age of an application went up from 4.75 years to 11.3 years. So just the same as a human.... Source codes also should be maintained within its life time. When comes to maintaining codes, there are 2 big big problems which we have to face. 1) Code is difficult to correct, coz the authors even can’t understand it. 2) Modifications or upgrades are difficult to make coz the programmer should spend a considerable amount of time figuring out what the program does. To make your coding more readable and more understandable, you have to include comments appropriately. Usually it is recommended to have 40% of your lines of code as comments. :P Comments in C language starts with a slash asterisk [B](/*) [/B]and ends with an asterisk slash [B](*/).[/B] [FONT="Courier New"][B]/*[/B] ******************************************************* * hello -- program to print "Hello World". On the screen.* * * * * * Author: NRYDDS a.k.a x-pert. * * * * Purpose: Demonstration of a simple program. * * * * Usage: * * Other comments: exclusively from [url]http://www.elakiri.com[/url] * * * * Runs the program and the message appears. * ******************************************************* [B]*/[/B] #include <stdio.h> int main() { /* Tell the world hello */ printf("Hello World\n"); return (0); } [/FONT] In the above example, I have [B]Bold[/B] the start and the end of the comment. All the characters which are between those two points belong to the comment. These types of comments are called ‘comment boxes’. Less important comments are not boxed. Such as [FONT="Courier New"]/* Tell the world hello */ [/FONT]in the above example. [B]Some commenting styles as in: Oualline, S. Practical C programming, O’Reilly Publications[/B] [FONT="Courier New"]/******************************************************** ******************************************************** ******** WARNING: This is an example of a ******* ******** warning message that grabs the ******* ******** attention of the programmer. ******* ******************************************************** ********************************************************/ /*------------> Another, less important warning <--------*/ /*>>>>>>>>>>>> Major section header <<<<<<<<<<<<<<<< */ /******************************************************** * We use boxed comments in this book to denote the * * beginning of a section or program. * ********************************************************/ /*------------------------------------------------------*\ * This is another way of drawing boxes. * \*------------------------------------------------------*/ /* * This is the beginning of a section. * ^^^^ ^^ ^^^ ^^^^^^^^^ ^^ ^ ^^^^^^^ * * In the paragraph that follows, we explain what * the section does and how it works. */ /* * A medium-level comment explaining the next * dozen (or so) lines of code. Even though we don't have * the bold typeface, we can **emphasize** words. */ /* A simple comment explaining the next line */[/FONT][/SIZE][/FONT] [/QUOTE]
Insert quotes…
Verification
Winadiyakata thappara keeyak tibeda?
Post reply
Top
Bottom