��������ҵ�ҧ� �����ٻẺ�����ç���ҧ�з��ᵡ��ҧ�ѹ� ����Ѻ��������ҫ� ���ç���ҧ����ӴѺ�����¹�ѧ���
�ٻẺ
|
��ǹ�����żš� (Preprocessor statement)
��ǹ���е�ͧ�շء����� �Ҩ���¡�����ǹ��Ǣͧ����� ���繵�ͧ��˹����㹵����������� �¨Т�鹵鹴�������ͧ���� # ������¤�������礷տ (Directive) ����ͧ��á�˹���� ��
#include <stdio.h> ���� #include "stdio.h"
���¶֧��ü�ǡ�δ���������� stdio.h �������ҹ ��駹���δ������� stdio.h ��鹨�����쪹Դ��ͤ��� (Text file) ���������������ա�û�С�Ȥ�ҵ���� ��Ф�Ҥ�����ҧ� ��èؿѧ��ѹ�ҵðҹ��ҧ� �����Ҵ��¡ѹ�����Ǵ�������ǡѹ��� ��ШѴ��ŧ��ź���� �¨ж١���������ҹ����ѹ�Ѻ�ش�������������з������������
��ǹ��С�ȵ������ǹ��ҧ (Global declarations statement)
��ǹ������㹡�û�С�ȵ�������Ϳѧ��ѹ����ͧ�������� �·ء� ��ǹ�ͧ���������ö���¡������ŷ���С��������ǹ�����
��ǹ�ѧ��ѹ��ѡ (Function main)
��ǹ���ء������е�ͧ�� ������㹿ѧ��ѹ��ѡ�л�Сͺ���¤���觵�ҧ� �������������ӧҹ �ѧ��ѹ���������鹡�÷ӧҹ���¿ѧ��ѹ main() ��ǹ����觵�ҧ� �е�ͧ��¹���������ҧ����ͧ���� { ��� } ���� ��Ф���觷ء���������ҫըе�ͧ�Դ���´�������ͧ���� ; (semicolon) ����
��ǹ�ѧ��ѹ����˹��ͧ (User-defined function)
�繡����¹�������пѧ��ѹ��ҧ� ����������� �µ�ͧ���������ͧ���� { } ��е�ͧ���ҧ�ѧ��ѹ���ͤ����������ӧҹ�����ҵ�ͧ������Ѻ������������ö���¡���� ���������
��ǹԺ������� (Program Comment)
�������� (comment) �����ǹ����������˵آͧ����� ����������������¹���������ͤ���Ժ�¡ӡѺŧ�� source code ��觤������������ӡ���ż����ǹ����繤���������
������������ҫ��� 2 Ẻ���
- ��������Ẻ��÷Ѵ���� ������ͧ���� //
- ��������Ẻ���º�÷Ѵ ������ͧ���� /* ��� */
������ҧ��ä�����������ҫ�
1 | //Comment only one line |
2 | |
3 | #include <stdio.h> |
4 | |
5 | int main() |
6 | { |
7 | /*Comment |
8 | many |
9 | line*/ |
10 | } |
������á�ͧ�ѹ
1 | //MyFirstProgram.c |
2 | |
3 | #include <stdio.h> |
4 | |
5 | int main() |
6 | { |
7 | clrscr(); |
8 | printf("Hello World !\n"); |
9 | getch(); |
10 | } |
���Ѿ����
Hello World !
- �����˵�
- ���¶֧ ��顴���� Enter ���鹾����
Ժ�������
��÷Ѵ��� 1: | ����ǹ����������˵�Ẻ��÷Ѵ���Ǣͧ����� ��������Һ������������ MyFirstProgram.c |
��÷Ѵ��� 3: | �繡�ú͡�������������δ���������� stdio.h ���������㹡���żŴ��� �� stdio ����Ҩҡ standard input/output ��� .h ��� ���ʡ�Ţͧ�δ�����������ҫ� (h ����Ҩҡ header) ��� stdio.h ��� �δ��������������ҡ�û�С�� (declaration) �ͧ�ѧ��ѹ�ҵðҹ�ͧ���ҫշ������ǡѺ��èѴ��ô�ҹ�Թ�ص�����ҵ�ص����������¡ѹ���������ա�����¡��ҹ�ѧ��ѹ printf() �����ʴ��������͡�ҧ���Ҿ ������ͧ�ҡ��ǹ�ͧ��û�С�ȿѧ��ѹ printf() �١��è�������δ������� stdio.h �ѧ��鹨֧���繵�ͧ���δ������� stdio.h �������㹡���żŴ��� |
��÷Ѵ��� 5: | ��Ϳѧ��ѹ main() ����繿ѧ��ѹ��ѡ�ͧ����� ��÷ӧҹ�ͧ��������ҫը�������鹷��ѧ��ѹ��� |
��÷Ѵ��� 6: | ����ͧ���� { �кبش������鹢ͧ�ѧ��ѹ main() |
��÷Ѵ��� 7: | �繤�������������˹�Ҩ������ʴ����Ѿ�� |
��÷Ѵ��� 8: | �繡�����¡��ѧ��ѹ printf() ����繿ѧ��ѹ�ҵðҹ�ͧ���ҫշ�˹�ҷ���ʴ��Ţ������͡�ҧ���Ҿ 㹷������ʴ���ͤ��� Hello World ! �͡�ҧ���Ҿ |
��÷Ѵ��� 9: | �繡�����¡��ѧ��ѹ getch() ����繿ѧ��ѹ�ҵðҹ�ͧ���ҫշ�˹�ҷ���Ѻ����ѡ��� �����͡�ҡ˹�ҨͻѨ�غѹ |
��÷Ѵ��� 10: | ����ͧ���� } �кبش����ش�ͧ�ѧ��ѹ main() |