งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

INTRODUCTION TO C LANGUAGE

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "INTRODUCTION TO C LANGUAGE"— ใบสำเนางานนำเสนอ:

1 INTRODUCTION TO C LANGUAGE
PROGRAMMING WITH C INTRODUCTION TO C LANGUAGE

2 INTRODUCTION TO C LANGUAGE
พัฒนาโดย Mr. Dennis Ritchie (1970) ภาษามาตรฐานบนระบบ UNIX เป็นภาษาที่มีประสิทธิภาพสูง ทำงานได้รวดเร็วกว่าภาษาอื่นๆ ทำงานบนไมโครคอมพิวเตอร์ถึงเมนเฟรม มาตรฐานของภาษาซีเรียกว่า ANSI C

3 C PROGRAMING STRUCTURE
# PREPROCESSING DIRECTIVE DECLARATION GLOBAL VARIABLE DECLARATION FUNCTION PROTOTYPE DECLARATION main( ) { LOCAL VARIABLE DECLARATION . . . STATEMENTS . . . }

4 C PROGRAMING STRUCTURE
# Pre-processing directive เป็นการกำหนดให้มีการกระทำใดๆ ก่อนจะเข้าสู่การทำงานของคำสั่งต่างๆ ในโปรแกรม เช่น #include – อ่านไฟล์ภายนอกเข้ามารวมในโปรแกรม #define - กำหนดค่าคงที่หรือมาโคร Global Variable เป็นการประกาศตัวแปรแบบรวม เพื่อให้สามารถถูกเรียกใช้ได้จากทุกส่วนในโปรแกรม Function Prototype declaration เป็นการประกาศรูปแบบของฟังก์ชั่นที่สร้างขึ้น เพื่อเรียกใช้งานในโปรแกรม

5 C Programming Structure
Pre-Processing Directive #include <stdio.h> void main() { printf(“This is my first progarm in C”); } Main program Statement

6 C Programming Structure
#include <stdio.h> การนำไฟล์จากหน่วยความจำภายนอก (ดิสก์) มาผนวกรวมในโปรแกรมด้วย (กรณีนี้คือไฟล์ stdio.h) void main( ) การกำหนดโมดูลหรือฟังก์ชั่นหลักของโปรแกรม ซึ่งจะเป็นจุดเริ่มต้นและจุดสิ้นสุดของโปรแกรม ภายในฟังก์ชั่น main จะบรรจุคำสั่ง (Statement) เพื่อกำหนดการทำงานของโปรแกรม

7 C Programming Structure
#include <stdio.h> // Include Header file #define SIZE 10 // Constant Declaration int result; // Global Variable Declaration void sum(int, int); // Function Prototype Declaration void main( ) { int num; // Local Variable Declaration . . . Statement } void sum(int num1 , int num2) // User-defined Function int val1 , val2; // Local Variable Declaration . . . Statement . . .

8 Comment Single (Short) Comment (//) In C++, comments are prefaced by //. All characters following // are treated as part of the comment. Block Comment (/*…*/) Bold comment /* ************************** ************************** */

9 ข้อกำหนดในการเขียนโปรแกรมภาษาซี
ตัวอักษรแบบพิมพ์เล็กและพิมพ์ใหญ่ถือว่าเป็นคนละตัว คำสั่งต้องเขียนด้วยตัวอักษรตัวพิมพ์เล็ก ต้องปิดท้ายคำสั่งด้วยเครื่องหมาย ; เขียนคำสั่งได้หลายคำสั่งใน 1 บรรทัด โดยทั่วไปการตั้งชื่อตัวแปร (Variable) และฟังก์ชั่น (Function) เพื่อใช้งานในโปรแกรม จะใช้ตัวอักษรพิมพ์เล็ก แต่จะใช้ตัวอักษรพิมพ์ใหญ่สำหรับชื่อของค่าคงที่ (Constant)

10 การตั้งชื่อตัวแปรและฟังก์ชั่นในภาษาซี
ห้ามใช้คำสงวน (Keyword) ที่ภาษาซีกำหนดไว้ ต้องเป็นตัวอักษรภาษาอังกฤษ และตัวเลขเท่านั้น ห้ามใช้สัญลักษณ์และเครื่องหมายใดๆ ในการตั้งชื่อ (ยกเว้นเครื่องหมายขีดเส้นใต้ _ ซึ่งภาษาซีถือเป็นตัวอักษร) ต้องขึ้นต้นชื่อด้วยตัวอักษรเท่านั้น ห้ามมีช่องว่างระหว่างชื่อ ตัวอักษรพิมพ์เล็กและใหญ่ ถือว่าเป็นคนละตัว ความยาวของชื่อไม่เกิน 32 ตัวอักษร

11 Guidelines for Specifying Variable Names
Begin with a letter of the alphabet. First character to be followed by a sequence of letters and / or digits. Avoid using letter O in situations where it can be confused with the number 0 and the lowercase letter l can be mistaken with the number 1.

12 Guidelines for Specifying Variable Names (cont.)
Uppercase and lowercase letters are treated different. Name of the variable should be descriptive of the value it holds.

13 Keywords in C Language Names reserved for specific purpose and cannot be used by the programmer. All data types are reserved as keywords Integer can be a variable name even though int is a part of integer.

14 Keywords in C Language auto default float register struct break do for
return switch case double goto short typedef char else if signed union const enum int sizeof unsigned continue extern long static volatile while

15 การตั้งชื่อตัวแปรและฟังก์ชั่นในภาษาซี
ตัวอย่างการตั้งชื่อที่ไม่ถูกต้อง 32deg ขึ้นต้นด้วยตัวเลข num 10 มีช่องว่างภายในชื่อ var-5 ใช้เครื่องหมาย – ค่าที่1 ไม่ใช่ภาษาอังกฤษ

16 การตั้งชื่อตัวแปรและฟังก์ชั่นในภาษาซี
ตัวอย่างการตั้งชื่อที่ถูกต้อง _32deg var5 WIDTH loop_counter status_of_file

17 Steps of Programming with C
Text Editor Compiler Linker *.C Source File *.OBJ Object File *.EXE Executable File


ดาวน์โหลด ppt INTRODUCTION TO C LANGUAGE

งานนำเสนอที่คล้ายกัน


Ads by Google