ข้อจำกัดของ C เมื่อเทียบกับภาษาอื่น
- ไม่รองรับ OOP: inheritance, polymorphism, encapsulation, data abstraction
- ตรวจสอบ error แบบ batch (หลัง compile เสร็จ) ไม่ใช่ line-by-line
- ไม่มี namespace
- Data abstraction ระดับต่ำ จัดการข้อมูลใหญ่ไม่ได้ดี
- ไม่มี exception handling
- ไม่มี constructor/destructor
- แก้ปัญหา real-world ได้ไม่ครบถ้วน
- ความปลอดภัยต่ำกว่าภาษาสมัยใหม่
โครงสร้างพื้นฐานของโปรแกรม C
/* documentation section */
preprocessor directives
global declaration
main() {
local declaration
executable statements
}
return_type function_name(arguments) {
local declaration
executable statements
}
ตัวอย่างโปรแกรม: หาเส้นรอบวงวงกลม
/* Author: Tutorialspoint
Aim: Program for finding circumference of circle */
#include <stdio.h>
#include <conio.h>
#define PI 3.1415
main() {
float c, r;
clrscr();
printf("enter radius of circle: ");
scanf("%f", &r);
c = 2 * PI * r;
printf("Circumference = %f", c);
getch();
}
ผลลัพธ์
Enter radius of circle r = 4
Circumference of circle c = 25.132000