#include<stdio.h>
int main(){
int var_eternity=10;
int *p;
p=&var_eternity;
printf("var_eternity变量的地址:%p\n",p);
return 0;
}
#include<stdio.h>
int main(){
int var=20;
int *p;
p=&var;
printf("var变量的地址:%p\n",&var);
printf("p变量存储的地址:%p\n",p);
printf("p变量的值:%d\n",p);
return 0;
}
#include<stdio.h>
int main(){
int *ptr=NULL;
printf("ptr 的地址是:%p\n",ptr);
return 0;
}
ptr++;
#include<stdio.h>
const int MAX=3;
int main(){
int var[]={
10,100,1000};
int i,*ptr;
ptr=var;
for(i=0;i<MAX;i++){
printf("存储地址:var[%d]=%p\n",i,ptr);
printf("存储值:var[%d]=%d\n",i,*ptr);
ptr++;
}
return 0;
}
#include<stdio.h>
const int MAX=3;
int main(){
int var[]={
10,100,1000};
int i,*ptr;
ptr=&var[MAX-1];
for(i=MAX;i>0;i--){
printf("存储地址:var[%d]=%p\n",i-1,ptr);
printf("存储值:var[%d]=%d\n",i-1,*ptr);
ptr--;
}
return 0;
}
#include<stdio.h>
const int MAX=3;
int main(){
int var[]={
10,100,1000};
int i=0,*ptr;
ptr=&var[MAX-1];
while(ptr<=&var[MAX-1])
{
printf("存储地址:var[%d]=%p\n",i,ptr);
printf("存储值:var[%d]=%d\n",i,*ptr);
ptr++;
i++;
}
return 0;
}
#include<stdio.h>
const int MAX=3;
int main(){
int var[]={
10,100,1000};
int i,*ptr[MAX];
for(i=0;i<MAX;i++){
ptr[i]=&var[i];
}
for(i=0;i<MAX;i++){
printf("Vaule of var[%d]=%d\n",i,*ptr[i]);
}
return 0;
}
#include<stdio.h>
const int MAX=4;
int main(){
const char *name[]={
"hello","world","ok","thank",};
for(int i=0;i<MAX;i++){
printf("Value of name[%d]=%s\n",i,name[i]);
}
return 0;
}
int **var;
#include<stdio.h>
int main(){
int V;
int *pt1;
int **pt2;
V=100;
pt1=&V;
pt2=&pt1;
printf("var=%d\n",var);
printf("pt1=%p\n",pt1);
printf("*pt1=%d\n",*pt1);
pritnf("pt2=%p\n",pt2);
printf("*pt2=%d\n",*pt2);
return 0;
}
#include<stdio.h>
#include<time.h>
void getSeconds(unsigned long *par)
{
*par=time(NULL);
return ;
}
int main(){
unsigned long sec;
getSeconds(&sec);
printf("Number of seconds:%ld\n",sec);
return 0;
}
#include<stdio.h>
double getAverage(int *arr,int size){
int i,sum=0;
double avg;
for(i=0;i<size;i++)
{
sum+=arr[i];
}
avg=(double)sum/size;
return avg;
}
int main(){
int balance[5]={
1,2,3,4,5};
double avg;
avg=getAverage(balance,5);
printf("Average value is:%.1f\n",avg);
return 0;
}
int *myFunction(){
...
...
}
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int *getRandom(){
static int r[10];
int i;
srand((unsigned)time(NULL));
for(i=0;i<10;i++){
r[i]=rand();
printf("%d\n",r[i]);
}
return r;
}
int main(){
int *p;
int i;
p=getRandom();
for(i=0;i<10;i++){
printf("*(p+[%d]):%d\n",i,*(p+i));
}
return 0;
}