This document discusses the printf function in C and how it can print the ASCII value of a character. It demonstrates code that declares a character variable ch with the value 'A' and uses printf with the %d format specifier to print the ASCII value of ch, which is 65. The document explains that printf treats ch as an integer when using %d, printing the underlying ASCII value rather than the character itself.
This document discusses the printf function in C and how it can print characters. It demonstrates code that declares a character variable ch with the value 'A' and prints it using printf("%d", ch), which prints the ASCII value of A, 65, since %d expects an integer but ch contains a character. The document explains that ch contains the character A, not the ASCII value, but printf treats it as an integer for printing purposes.
This document discusses the printf function in C and how it can print the ASCII value of a character. It demonstrates code that declares a character variable ch with the value 'A' and uses printf with the %d format specifier to print the ASCII value of ch, which is 65. The document explains that printf treats ch as an integer when using %d, printing the underlying ASCII value rather than the character itself.
This document discusses the printf function in C and how it can print characters. It demonstrates code that declares a character variable ch with the value 'A' and prints it using printf("%d", ch), which prints the ASCII value of A, 65, since %d expects an integer but ch contains a character. The document explains that ch contains the character A, not the ASCII value, but printf treats it as an integer for printing purposes.
9. คำำสั่งควบคุมวนซำ้ำแบบ while
while เป็นคำำสั่งให้มีกำรทำำซำ้ำเป็นรอบ ๆ (loop) ลักษณะ
กำรทำำงำนทำำนองเดียวกับคำำสั่ง for แต่ต่ำงกันตรงที่ไม่ทรำบ
จำำนวนรอบที่แน่นอน แต่ต้องมีเงื่อนไขที่เป็นเท็จจึงจะออกจำกคำำสั่ง
while ได้มิฉะนั้นจะมีปัญหำที่โปรแกรมทำำงำนแบบวนซำ้ำแบบไม่มีที่
สิ้นสุด (endless loop)
11. กำรเขียนคำำสั่งวนซำ้ำแบบ do while
do while เป็นคำำสั่งให้มีกำรทำำซำ้ำเป็นรอบ ๆ (loop)
ลักษณะกำรทำำงำนทำำนองเดียวกับคำำสั่ง while แต่ต่ำงกันตรงที่คำำ
สั่งนี้จะมีกำรทำำงำนตำมคำำสั่งไป 1 รอบ ก่อนที่จะทดสอบเงื่อนไข
ถ้ำเงื่อนไขที่เป็นจริงจะทำำงำนต่อไป ถ้ำเงื่อนไขเป็นเท็จจึงจะออก
จำกคำำสั่ง do while คำำสั่งนี้ก็เช่นเดียวกันจะต้องกำำหนดให้มี
โอกำสที่เงื่อนไขเป็นเท็จได้ มิฉะนั้นจะมีปัญหำที่โปรแกรมทำำงำน
แบบวนซำ้ำแบบไม่มีที่สิ้นสุด (endless loop) กรณีที่เงื่อนไขเป็นเท็จ
เพียงอย่ำงเดียวจะมีกำรทำำงำน 1 รอบ ก่อนออกจำกกำรทำำซำ้ำ