当前位置: 代码迷 >> 综合 >> 指针基础应用的测试
  详细解决方案

指针基础应用的测试

热度:89   发布时间:2024-01-15 04:21:03.0

好久不写,指针都忘了,写个简单的小程序测试一下。

--------------------------

功能:输入3个数,然后输出,最后三个变量都归零。

--------------------------

程序运行和编译的环境:

ubuntu 12.04.2LTS ; Linux  3.5.0-36-generic ; gcc version 4.6.3; Vi IMproved 7.3 

//Pointer tests#include <stdio.h>
#include <stdlib.h>typedef struct{int num1;int num2;
}Test;void main(){//Define the right type of pointer!!int i,j,test,*p;Test *q;Test tmp;printf ("Input the test number:");scanf ("%d",&test);p=&test;printf ("The number is %d\n",*p);printf ("Input the tmp.num1:");scanf ("%d",&tmp.num1);printf ("Input the tmp.num2:");scanf ("%d",&tmp.num2);printf ("Here's the tmp.num1.num2:");q=&tmp;printf ("%d %d\n",q->num1,q->num2);printf ("Clean the data...");*p=0;q->num1=0;q->num2=0;printf ("\n%d %d %d\n",test,q->num1,q->num2);printf ("END!\n");getchar();
}


  相关解决方案