12. ฟังก์ชัน printf : รหัสแบ็กสแลช
12
รหัสแบ็กสแลช อักขระ
a bell (กระดิ่ง )
b backspace
t แท็บตามแนวนอน
n ขึ้นบรรทัดใหม่
v แท็บตามแนวตั้ง
f ขึ้นหน้าใหม่
r ปัดแคร่
” อัญประกาศ
’ อะโพสโตรฟิ
? เครื่องหมายคาถาม
แบ็กสแลช
0 นัล
22. ฟังก์ชัน Scanf : ตัวอย่ำง
22
int num;
scanf(“%d”,&num);
printf(“the value in num variable is %d”,num);
char str[80];
printf(“Enter a string : ”);
scanf(“%s”,str);
printf(“Here ‘s your string : %s”, str);
23. #include < stdio.h >
void main ( ) {
int years;
printf (“How long have you been here? ”);
scanf (“%d”, &years);
printf (“You’ve been here for %d years.”, years);
printf (“tReally?”);
}
23
How long have you been here? 20
You’ve been here for 20 years. Really?
25. ฟังก์ชัน getchar : ตัวอย่ำง
25
#include “stdio.h”
void main ( ) {
char ch;
ch = getchar();
printf(“The Character you typed is %cn”, ch);
}
d
The Character you typed is d
27. ฟังก์ชัน getch : ตัวอย่ำง
27
#include “stdio.h”
#include “conio.h”
void main ( ) {
char ch;
ch = getch();
printf(“The Character you typed is %cn”, ch);
}
The Character you typed is d
29. ฟังก์ชัน gets : ตัวอย่ำง
29
#include “stdio.h”
void main ( ) {
char str[51];
gets(str);
printf(“The Message you typed is %sn”, str);
}
test
The Message you typed is test
34. ความแตกต่างของเครื่องหมาย = และ ==
o เครื่องหมาย = เป็ นตัวกาหนดค่า
o เครื่องหมาย == เป็ นเครื่องหมายเปรียบเทียบ
ตัวอย่างเช่น
หมายถึง เป็ นการกาหนดค่าให้กับตัวแปร point
ให้มีค่าเท่ากับ 44
หมายถึง เป็ นการตรวจสอบว่าค่า point มีค่า
เท่ากับ 44 หรือไม่
นิพจน์กาหนดค่า
point = 44;
point == 44;
35. เครื่องหมายและนิพจน์เปรียบเทียบแบบ
ตรรกศาสตร์
&& หมายถึง และ (and)
| | หมายถึง หรือ (or)
! หมายถึง ไม่ (not)
ตัวอย่างเช่น
จะได้ค่าความจริงเป็ นจริงก็ต่อเมื่อ a และ
b เป็ นจริงทั้งคู่
จะได้ค่าความจริงเป็ นเท็จก็ต่อเมื่อ a และ
b เป็ นเท็จทั้งคู่
เครื่องหมายและนิพจน์แบบตรรกศาสตร์
a && b
a || b