มีสี่คลาสการจัดเก็บข้อมูลในภาษาการเขียนโปรแกรม C ซึ่งมีดังนี้ -
- อัตโนมัติ
- ภายนอก
- คงที่
- ลงทะเบียน
ตัวแปรอัตโนมัติ / ตัวแปรในเครื่อง
คีย์เวิร์ดเป็นแบบอัตโนมัติ สิ่งเหล่านี้เรียกอีกอย่างว่าตัวแปรท้องถิ่น
ขอบเขต
- ขอบเขตของตัวแปรโลคัลมีอยู่ในบล็อกที่มีการประกาศ
- ตัวแปรเหล่านี้ถูกประกาศภายในบล็อก
- ค่าเริ่มต้น:ค่าขยะ
อัลกอริทึม
อัลกอริทึมได้รับด้านล่าง −
START Step 1: Declare and initialize auto int i=1 I. Declare and initialized auto int i=2 I. declare and initialized auto int i=3 II. print I value//3 II Print I value //2 Step 2: print I value STOP
ตัวอย่าง
ต่อไปนี้เป็นโปรแกรม C สำหรับ คลาสการจัดเก็บอัตโนมัติ −
#include<stdio.h>
main ( ){
auto int i=1;{
auto int i=2;{
auto int i=3;
printf ("%d",i)
}
printf("%d", i);
}
printf("%d", i);
} ผลลัพธ์
ผลลัพธ์ระบุไว้ด้านล่าง −
3 2 1
พิจารณาโปรแกรมอื่นสำหรับคลาสการจัดเก็บอัตโนมัติ
ตัวอย่าง
#include<stdio.h>
int mul(int num1, int num2){
auto int result; //declaration of auto variable
result = num1*num2;
return result;
}
int main(){
int p,q,r;
printf("enter p,q values:");
scanf("%d%d",&p,&q);
r = mul(p, q);
printf("multiplication is : %d\n", r);
return 0;
} ผลลัพธ์
ผลลัพธ์ระบุไว้ด้านล่าง −
Run 1: enter p,q values:3 5 multiplication is : 15 Run 2: enter p,q values:6 8 multiplication is : 48