![[IMAGE: An Quarter-Size Version of The Joy of C Front Cover]](../Images/QuarterFrontCover.bmp)
This chapter is a gentle introduction to C. We begin with a pair of simple programs: one prints a welcoming message, the other calculates the actual cost of purchasing a set of items. We describe these programs in great detail and provide several variants of each. Along the way we introduce the basics of C program organization, the process of compilation and linking, and several fundamental language features: the printf function for performing formatted output, variable declaration and assignment, and the arithmetic operators.
Jump to: [Next Chapter]
°¢ÀÚÀÇ À̸§À» Ãâ·ÂÇÏ´Â C ÇÁ·Î±×·¥
#include <stdio.h>
main()
{
printf("±¤¼ö¾ß, ¾È³ç!");
}
#include <Çì´õÈÀÏ(ÈÀϸí.h)>
#include "Çì´õÈÀÏ(ÈÀϸí.h)"
/* < >¿Í" "ÀÇ ´Ù¸¥Á¡Àº Çì´õÈÀÏÀÌ ÀÖ´Â °÷ÀÇ µð·ºÅ丮 */
#¼±Çà󸮱â
/* ÁÖ·Î #define ¹®ÀÌ ¾²ÀÓ */
main() /* ÁÖÇÔ¼ö: ÇÁ·Î±×·¥ÀÇ ½ÇÇàÀÌ ½ÃÀ۵Ǵ °÷ */
{ /* ÇÔ¼öÀÇ ½ÃÀÛÀ» ³ªÅ¸³¿ */
¹® (statement)
:
:
} /* ÇÔ¼öÀÇ ³¡À» ³ªÅ¸³¿ */
ÇÔ¼ö¸í() /* »ç¿ëÀÚ°¡ ÀÛ¼ºÇÑ ÇÔ¼öµé.. */
{
¹® (statement)
:
}
ÇÔ¼ö¸í() /* ¿©·¯ °³ÀÇ ÇÔ¼ö¸¦ °è¼Ó Á¤ÀÇÇØ ¾µ ¼ö ÀÖ´Ù. */
:
:
Statement(¹®)ÀÇ ±¸¼º : Keyword or Reserved word, Identifier, Constant, String, Operator
Keywords or Reserved Words : ƯÁ¤ ¸ñÀû¿¡ »ç¿ëµÇ´Â ¿¹¾à¾î
/*
* File: add2.c
*/
#include <stdio.h> // standard I/O header file
void main()
{
int n1, n2, total; // Á¤¼öÇü º¯¼ö Á¤ÀÇ
printf("This program adds two numbers.\n");
printf("1st number? ");
n1 = scanf("%d", &n1);
printf("2nd number? ");
n2 = scanf("%d", &n2);
total = n1 + n2;
printf("The total is %d.\n", total);
}
* ´ÙÀ½ ÇÁ·Î±×·¥(wrong.c)ÀÇ À߸øÀ» ã¾Æ ½ÇÇà °¡´ÉÇÏ°Ô º¯°æÇ϶ó.
#include <stdio.h>
MAIN();
int a, b, c, sum
float d, e;
a = 1;
b = 2;
c = 1000;
sum = a + b + c
printf/*Display*/("sum = %d/n", sum)
¾ûÅ͸® ÇÁ·Î±×·¥: (messy.c)
Á» ³ªÀº ÇÁ·Î±×·¥: (price.c)
ÀÌ ÇÁ·Î±×·¥Àº ´Þ·¯¸¦ ¿øÀ¸·Î °è»êÇØ ÁÝ´Ï´Ù. ÇöÀç ȯÀ²Àº(¿ø/´Þ·¯)? 1215 ºñ²Ü ´Þ·¯´Â? 10 10´Þ·¯´Â 12150¿øÀÔ´Ï´Ù.
½ÇÇà°¡´ÉÇÑ ÇÁ·Î±×·¥ source fileÀ» e-mail·Î Á¦Ãâ(±â°£: 1ÁÖÀÏ)