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����)