Back to the C [eps1]
April 8, 2008
Kemaren ketemu ma temen lama di locket baak(“masih kuliah aja luh”), yeah mr and ms sugeng (“kayak judul film”) lagi ngurus kuliahan juga (“dah inget ma kuliah lu geng”) and satu hal ni orang ngajakin gw masuk ke kantornya. Tapi yang bikin gw nulis ni Blog bukan karena sugeng ngajakin gw pindah ke kantornya, tapi dia bilang kita pake bahasa C, C ansi. duh ni langguage dah gak gw pake lagi setelah gw dah alumnus(alumni gak lulus) di vortex labs nya pull the plug . setelah pikir panjang akhirnya balik lah gw kemabali ke C, kembali masuk ke pull the plug(“sekarang dah pake drupal loh”) bahasa kuno yang masih sangat sakti.
capter 1:
marty maccfly bertanya ke pada Doc(ernest brown), doc, untuk apa doc kita disini, kata marty. ouu marty saat tertidur aku terjatuh dan akhirnya aq terinspirasi untuk mempelajari bahasa C. trus apa yang pertama harus kita buat dengan C lanjut marty, pertma yang kita lakukan adalah membuat hallo world di dalam C dan inilah kode nya :
/* helloworld program */
#include
int main(void)
{
printf("Hello, World!\n");
return 0;
}
lalu kita compile dia dengan menggunakan compiler C apapun maka hasilnya adalah seperti ini marty
Hello, World!
cool doc but i still don’t understand with this langguage, ok marty i will explain to you in next code, and this the second code :
#include
int main(void)
{
int num, result = 0;
scanf("%d", &num); // read the number from the keyboard
for(i = 1; i <= num; i++) { // compute the result
result += i;
}
printf("%d\n", result); // output the result
return 0;
}
hey what that mean doc i really confiusing right now, relaxs marty i will compile and run the program first
Hello, I am the computer and I know that 2+2 = 4!
i will explain it marty, first What’s ? That is what is known as a header
file. It’s the dot-h at the end that gives it away. In fact it’s the “Standard IO” (stdio) header
file that you will grow to know and love. It contains preprocessor directives and function
prototypes (more on that later) for common input and output needs. For our demo program,
we’re outputting the string “Hello, World!”, so we in particular need the function prototype for
the function from this header file.
printf(). now did u understand now marty, well yes i think, i begin understand that alittle, next doc !!!
alright marty The next line is main() . This is the definition of the function main(); everything between
the squirrely braces ( and ) is part of the function definition.{ }. A function??. “Great! More terminology I don’t know doc!”, a function is a collection of code marty, that is to be
executed as a group when the function is called. You can think of it as, “When I call main() , all the stuff in the squirrley braces will be executed, and not a moment before.” Now, the main function is a special one in many ways, but one way stands above the rest: it is the function that will be called automatically when your program starts executing. Nothing of yours gets called before main(). In the case of our example, this works fine since all we want to do is print a line and exit.
i think just this for right now marty, i must write the another code when it finish we will meet again in the more C programing.
to be continued……………….(on chptr 2 eps 1)