LoadRunner腳本編寫(4)

發表于:2015-09-21來源:uml.org.cn作者:不詳點擊數: 標簽:loadrunner
* 自動(auto)變量 函數中的局部變量,如不專門的聲明為static存儲類別,都是動態地分配存儲空間的。 * 靜態(static)聲明局部變量 有時希望函數中的局部變量

  * 自動(auto)變量

  函數中的局部變量,如不專門的聲明為static存儲類別,都是動態地分配存儲空間的。

  * 靜態(static)聲明局部變量

  有時希望函數中的局部變量的值在函數調用結束后不消失而保留,這時就應該指定局部變量為“靜態局部變量”,用static關鍵字。

  * 寄存器(register)變量

  為了提高效率,C語言允許把局部變量的值放在CPU中的寄存器中,這種變量叫“寄存器變量”,用關鍵字register變量。

static int c;

int prime(register int number) //判斷是否為素數
{
register int flag=1;
auto int n;
for (n=2;n<number/2 && flag==1;n++) {
if (number % n==0) flag=0;
return(flag);

}
}

demo(int a) //static、auto變量的演示函數
{
auto int b=0;
int d;
static c=3;
b=b+1;
c=c+1;
lr_output_message("demo()函數中的d=%d",d);
lr_output_message("demo()函數中的static c=%d",c);
return a+b+c;

}
Action(){
int a=2,i; //變量聲明

for (i=0;i<3;i++) {
lr_output_message("demo()函數部分第%d運行情況如下:",i+1);
lr_output_message("函數demo運行結果為:%d",demo(a));
lr_output_message("-------------------\n\r");
}

//判斷13是否為素數,并輸出提示信息
if (prime(13)==0)
lr_output_message("13不是素數!");
else
lr_output_message("13是素數!");

lr_output_message("c=%d",c); //輸入變理的值


return 0;
}

  素數:指大于1的自然數,除了1和它本身不能被其它數整除的數。prime()函數部分主要用來判斷傳入的數是否是素數。demo()函數用來做static和auto類型的變量演示。Action()函數用于調用與輸入結果。

  運行結果:

Starting iteration 1.
Starting action Action.
Action.c(31): demo()函數部分第1運行情況如下:
Action.c(22): demo()函數中的d=51446257
Action.c(23): demo()函數中的static c=4
Action.c(32): 函數demo運行結果為:7
Action.c(33): -------------------

Action.c(31): demo()函數部分第2運行情況如下:
Action.c(22): demo()函數中的d=51446257
Action.c(23): demo()函數中的static c=5
Action.c(32): 函數demo運行結果為:8
Action.c(33): -------------------

Action.c(31): demo()函數部分第3運行情況如下:
Action.c(22): demo()函數中的d=51446257
Action.c(23): demo()函數中的static c=6
Action.c(32): 函數demo運行結果為:9
Action.c(33): -------------------

Action.c(40): 13是素數!
Action.c(42): c=0
Ending action Action.
Ending iteration 1.

  指針

  指針是C語言中廣泛使用的一種數據類型,指針可以使我們的程序變得非常靈活,但也讓不少程序員頭痛,一不小心就會使程序出錯。

  指針一般指向一個函數或一個變量。在使用一個指針時,一個程序既可以直接使用這個指針所儲存的內存地址,又可以使用這個地址里儲存的變量或函數的值。

  有一本很厚小說,為了便于讀者找到某一段內容,我們會給某一段內容起一個小標題并標注上頁數。這樣找起來就非常方便了。那在內存中,小標題頁數就相當于內存單元的指針,具體的小說內容就是內存單元的內容。

Action(){
int score[5]={100,98,78,55}; //一維數組
int *p=score; //一維數組指針
int sixnum[2][3]={{1,2,3},{4,5,6}}; //二維數組
int (*p1)[3]; //二維數組指針
int i,j; //定義兩個變量

for (i=0;i<=4;i++) {
lr_output_message("score[%d]=%d",i,score[i]); //以下標形式標識數組
lr_output_message("*(p++)=%d",*(p++)); //以指針方式輸出數組
}
lr_output_message("--------------------------");

p=score;
for (i=0;i<=4;i++) {
lr_output_message("score[%d]=%d",i,score[i]); //以下標形式標識數組
lr_output_message("*(p+%d)=%d",*(p+i)); //以指針方式輸出數組
}
lr_output_message("--------------------------");

p1=sixnum;
for (i=0;i<=1;i++) {
for (j=0;j<=2;j++) {
lr_output_message("sixnum[%d][%d]=%d",i,j,sixnum[i][j]); //以下標形式標識數組
lr_output_message("*(*(p1+%d)+%d)=%d",*(*(p1+i)+j)); //以指針方式輸出數組
}

}

return 0;
}

原文轉自:http://www.uml.org.cn/Test/201303151.asp

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97