Skip to content

Understanding Basic structure of a C program in Sinhala - Lesson 04

මේ තියෙන්නේ අපි කලින් Lesson 3 එකේදී run කරපු Program එක.

#include <stdio.h>
int main()
{
	printf("Hello, World!");
	return 0;
}

අපි මේ Program එකේ line by line අරගෙන බලමු මොනවද ඒ ඒ lines වලින් වෙන්නේ කියල.


#include <stdio.h>

  • මොකක්ද මේ #include <stdio.h> කියන command එක?

# include කියන්නේ C Language එකේ භාවිතා වන prerocessor drective එකක්. ඒ කියන්නේ මේ command එක මගින් input කරන file එකේ තියෙන codes(instructions) තමයි preprocessor එක read කරන්නේ compiling process එකට පෙර.

  • ඇයි එතකොට අපි stdio.h file එක අපේ program එකට input කරගත්තේ?

මේ stdio.h කියන file එකේ input/output functions ගනනාවක් තියෙනවා. අපි ලියපු program එකේ 4th Line එකේ printf() කියල function එකක් use කරලා තියෙනවා text එකක් print කරගන්න. මේ printf() function එක ක්‍රියා කිරීමට අවශ්‍ය instructions තියෙන්නෙත් stdio.h file එක තුල.



int main()

main() කියන්නේ special Function එකක්. මේ function එකේ සිට තමයි කෝඩ් එක execute/run වෙන්න පරන්ගන්නේ.



{ (Opening bracket)

Opening bracket එකෙන් indicates කරන්නේ function එකක ආරම්භය. මේ bracket එක open කිරීමෙන් අදහස් වෙන්නේ main() function එකේ ආරම්භය. මේ bracket එක close කිරිමෙන් function එකේ අවසානය indicate කරනවා.

{

Function body

}

Function body එක තුල තමයි අපේ logic එක ලියන්නේ. ඒ කියන්නේ අපිට program එකෙන් කරගන්න ඕනේ දේ සදහන් කරන්නේ මෙතන.



printf(“Hello World”);

කලින් කිව්ව වගේ printf() command එකෙන් කරන්නේ ඒ තුල සදහන් කරන message එක output screen එකේ display කරන එක. අපි print කරන්නේ text එකක් නිසා " " ඇතුලේ එක ටයිප් කරන්න ඕනේ.



return 0;

අපි function body එක තුල ලියන ලද code පිළිවෙලින් නිවැරදිව run වූ පසු මෙම return command එක මගින් main() function එකෙන් පිටතට 0 කියන value එක යවනවා. මෙමගින් තහවුරු කරන්නේ මේ කෝඩ් එක නිවැරදිව execute වූ බව. මේ return value එකට 0 විතරක් නෙවෙයි -32,768 to 32,767 අතර (integer vale) ඕනෑම අගයක් යොදාගත හැකියි.



} (Closing brackets)

Closing bracket එකෙන් indicates කරන්නේ function එකක අවසානය. මේ bracket එක close කිරීමෙන් අදහස් වෙන්නේ main() function එකේ අවසානය.

Tagged:
Sign In or Register to comment.