ประเภทของตัวแปร
• ตัวแปรเดี่ยว คือตัวแปรที่ขณะใดขณะหนึ่ง จะเก็บข้อมูลได้ค่าเดียว
เช่น – char ch1; – int x;
• ตัวแปรชุด คือตัวแปรที่เก็บข้อมูลประเภทเดียวกัน ได้หลายค่า
เช่น – int num[ ] = {5, 7, 1, 18, 20}; – float f[10];
การประกาศตัวแปรแบบ Structure
struct Camera {
char series[20];
char brand[10];
float Price;
char type[20];
float effective;
float weight;
char type_picture[10];
char Memory_type[10];} ;
struct Camera product={"DST","SONY",5990.00,"compact", 10,135,"JPEG","Memory stick"}; การประกาศตัวแปรเป็นตัวแปรโครงสร้างชนิด Camera จากรูปตัวอย่าง เป็นตัวแปรซึ่งมีชนิดข้อมูลเป็นข้อมูลแบบโครงสร้างชนิดใหม่ที่เรากำหนดขึ้นเองโดยใน 1 ตัวแปร สามารถเก็บข้อมูล series (รุ่น) , brand (ยี่ห้อ) ,Price (ราคา), type (ชนิดของกล้อง), effective (ความละเอียด), weight (น้ำหนัก), type_picture (ชนิดของรูปภาพ), Memory_type (ชนิดของความจำ)
Homework
struct car{
char brand[30];
char series[30];
int door;
int wheel;
char oil[10];
char License[10];
char gears[10];
char color[20];
struct CAR=
{"Honda","Civic 94","3","Blue","4","Automatic","Bensil","po1234"};