9. ชนิดข้อมูลพื้นฐาน 255 0 1 unsigned char 18,446,744,073,709,551,615 0 8 unsigned long long +9,223,372,036,854,775,807 − 9,223,372,036,854,775,808 8 long long +2,147,483,647 -2,147,483,648 4 long +32,767 หรือ +2,147,483,647 -32,768 หรือ -2,147,483,648 2 หรือ 4 int 0 0 0 -32,768 -128 ค่าต่ำสุด 4,294,967,295 65,535 หรือ 4,294,967,295 65,535 +32,767 +127 ค่าสูงสุด 1 char 4 unsigned long 2 หรือ 4 unsigned int 2 unsigned short 2 short ขนาด ( ไบต์ ) การประกาศ
10.
11.
12.
13.
14.
15.
16.
17. %format ใน scanf และ printf %s char array[] สตริง %c char อักขระโดด %lf double %f float จำนวนมีทศนิยม %llu unsigned long long %lu unsigned long %u unsigned int %lld long long %ld long %d int จำนวนเต็ม %format ชนิดตัวแปร ชนิดข้อมูล
18. ตัวอย่างการใช้ scanf char name[20]; int age; printf("Enter your name and age: "); scanf("%s %d", name, &age); printf("Hello %s. You are %d years old.", name, age); Enter your name and age: Tony 38 Hello Tony. You are 38 years old. ผลลัพธ์ :
19.
20.
21.
22. โครงสร้าง if…else if ( condition ) { statement t1 ; statement t2 ; } else { statement f1 ; statement f2 ; } C Syntax Flowchart START END Statement f1 condition true false Statement t1 Statement f2 Statement t2
23.
24.
25.
26.
27.
28.
29. การทำงานของ for ลูป false update_stmt for ( init_stmt ; condition ; update_stmt ) { statement1 ; statement2 ; : statementN ; } START END condition true Statement1 StatementN init_stmt
34. การไหลของโปรแกรมเมื่อใช้ฟังก์ชัน int incr(int i) { int j; j = i + 1; return j; } int main() { int k, m = 4; k = incr(m); printf ("k = %d, m = %d", k, m); return 0; }
35.
36.
37.
38. ข้อผิดพลาดที่พบบ่อย #include <stdio.h> int main () { int i; scanf("%d", i); if (i = 0) puts("false"); else puts("true"); return 0; } ส่งค่า i ให้ scanf แทนที่จะส่งตำแหน่ง ใช้คำสั่งกำหนดค่า (=) แทนการเปรียบเทียบ (==)
39. ข้อผิดพลาดที่พบบ่อย #include <stdio.h> int main () { char s[10]; printf("Enter password: "); scanf("%s", s); if (s == "pass") puts("Correct password"); else puts("Incorrect password"); return 0; } ใช้ == เปรียบเทียบสตริงไม่ได้ ใช้ฟังก์ชัน strcmp() แทน