Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

C Tokens คืออะไร (Tokens ในภาษา C)


คำอธิบาย

Token คือหน่วยเล็กที่สุดของโปรแกรม C ที่มีความหมายต่อคอมไพเลอร์ โปรแกรม C ประกอบด้วยคำสั่ง และแต่ละคำสั่งประกอบด้วย Tokens Tokens เป็นบล็อกก่อสร้างพื้นฐานของโปรแกรม C

ประเภทของ Tokens

  • Keywords (คีย์เวิร์ด)
  • Identifiers (ตัวระบุ)
  • Operators (ออเปอเรเตอร์)
  • Special Symbols (สัญลักษณ์พิเศษ)
  • Constants (ค่าคงที่)
  • Strings (สตริง)
  • Data values (ค่าข้อมูล)

ตัวอย่างโปรแกรมพิมพ์ ASCII A-Z

#include <stdio.h>

int main() {
    int i;
    printf("ASCII ==> Character\n");
    for (i = 65; i <= 90; i++)
        printf("%d ==> %c\n", i, i);
    return 0;
}

Tokens ในโค้ดตัวอย่าง

  • #include - Preprocessor directive
  • stdio.h - Header name
  • int - Keyword
  • main - Identifier
  • () { } - Special symbols
  • i - Identifier (variable)
  • for ; <= ++ - Operators/Keywords
  • 65 90 - Integer constants
  • "ASCII ==> Character\n" - String literal