2012年9月5日

通过函数完成对结构体变量的输入和输出

摘要: 1/*结构体变量和结构体指针变量作为函数参数传递的问题2通过函数完成对结构体变量的输入和输出。3*/45#include<stdio.h>6#include<string.h>789structStudent10{11intage;12charsex;13charname[100];14};//分号不能少1516voidInputStudent(structStudent*);17voidOutputStudent(structStudentss);181920intmain(void)21{22structStudentst;2324InputStudent(& 阅读全文

posted @ 2012-09-05 22:47 Your Song 阅读(3288) 评论(1) 推荐(0) 编辑

结构体的赋值和初始化与取出结构体变量中的成员

摘要: 1/*结构体的赋值和初始化*/23#include<stdio.h>45structStudent6{7intage;8floatscore;9charsex;10};1112intmain(void)13{14structStudentst={80,66.6,'F'};//定义同时就赋值15structStudentst2;//下一行不能写一句类似于st2={10,88,'M'};的语句,除非定义时就赋值。16st2.age=10;17st2.score=88;18st2.sex='M';1920printf("%d,%f 阅读全文

posted @ 2012-09-05 22:10 Your Song 阅读(7561) 评论(0) 推荐(0) 编辑

动态内存可跨函数使用

摘要: 1#include<stdio.h>23voidf(int**q)4{5inti=5;6//*q=i;errro因为*q=i;等价于p=i;这样写是错的。7//*q等价于p,q和**q都不等于p89*q=&i;//p=&i;10}1112intmain()13{14int*p;1516f(&p);17printf("*p=%d\n",*p);//本语句语法上没有问题,但逻辑上有问题。想想!!能运行,编译器有问题18//。1920return0;2122}23/*24在Vc++6.0中显示的结果是:25=================== 阅读全文

posted @ 2012-09-05 20:52 Your Song 阅读(189) 评论(0) 推荐(0) 编辑

多级指针

摘要: 1#include<stdio.h>23intmain(void)4{5inti;6i=10;7int*p;8int**q;9int***r;1011p=&i;12q=&p;13r=&q;1415printf("%d,%d,%d\n",i,*p,**q,***r);161718return0;19}20/*21在Vc++6.0中显示的结果是:22===============================================2310,10,1024======================================= 阅读全文

posted @ 2012-09-05 14:12 Your Song 阅读(98) 评论(0) 推荐(0) 编辑

初学动态内存分配

摘要: 1/*2动态内存分配3传统数组的缺点:41,数组长度必须事先制定,且只能是常整数,不能是变量。5例子:67inta[5]//ok8intlen=5;inta[len]//error9102,传统形式定义的数组,该数组的内存程序员无法手动释放。11知道函数运行结束时,数组的空间才会被系统释放。1213143,数组的长度不能在函数运行过程中动态地扩充货缩小1516174,A函数定义的数在A函数运行期间可以被其他函数调用,1819为什么需要动态分配内存20动态数组很好得解决了传统数组的缺陷21传统数组也叫静态数组2223*/24#include<stdio.h>25#include< 阅读全文

posted @ 2012-09-05 10:11 Your Song 阅读(155) 评论(0) 推荐(0) 编辑

2012年9月4日

变量地址举例

摘要: 1#include<stdio.h>23voidoutArr(int*pArr,intlen)4{5inti;6pArr[1]=100;//此时pArr[1]等价于*(pArr+1)等价于a[1]等价于*(a+1);78for(i=0;i<len;i++)9printf("%d\n",pArr[i]);1011}1213intmain(void)14{15inta[3]={1,2,3};16outArr(a,3);1718return0;19}20/*21在Vc++6.0中显示的结果是:22================================= 阅读全文

posted @ 2012-09-04 21:15 Your Song 阅读(227) 评论(0) 推荐(0) 编辑

数组指针的赋值与输出问题

摘要: 1#include<stdio.h>23voidf(int*pArr,intlen)4{5inti;67for(i=0;i<len;i++)8printf("%d",*(pArr+i));9printf("\n");101112}//该函数实现对数组中的值的输出。1314intmain(void)15{16inta[5]={1,2,3,4,5};17intb[6]={-1,90,45,35,54,22};18intc[100]={1,31,34,11};1920f(a,5);//a是int*类型21f(b,6);22f(c,100);2 阅读全文

posted @ 2012-09-04 19:01 Your Song 阅读(968) 评论(0) 推荐(0) 编辑

2012年9月3日

形参和实参理解 数组指针的两个例子

摘要: 1/*基本类型指针_1*/2#include<stdio.h>34intmain(void)5{6int*p;//等价于int*p;也等价于int*p;7inti=5;8charch='A';910p=&i;//*p以p的内容为地址的变量11//p=&ch;//error类型不一致12//p=ch;//error13*p=99;14printf("i=%d,*p=%d\n",i,*p);15 1617return0;18}19/*在Vc++6.0中显示的结果是:20================================= 阅读全文

posted @ 2012-09-03 22:54 Your Song 阅读(283) 评论(0) 推荐(0) 编辑

经典指针程序,互换两个数字

摘要: 1#include<stdio.h>2voidhuhuan_1(int,int);3voidhuhuan_2(int*,int*);4voidhuhuan_3(int*,int*);567intmain(void)8{9inta=3;10intb=5;1112huhuan_1(a,b);13printf("a=%d,b=%d\n",a,b);1415huhuan_2(&a,&b);//写成huhuan(*p,*q);或者huhuan(a,b);都是错误的16printf("a=%d,b=%d\n",a,b);1718huhua 阅读全文

posted @ 2012-09-03 13:53 Your Song 阅读(265) 评论(0) 推荐(0) 编辑

指针理解

摘要: 1#include<stdio.h>23intmain(void)4{56inti=5;7int*p;8int*q;9p=&i;10q=p;//注意:不能写成*q=p;或者*q=*p或者p=q;1112printf("*q=%d,q=%d\n",*q,q);1314return0;15} 阅读全文

posted @ 2012-09-03 13:02 Your Song 阅读(145) 评论(0) 推荐(0) 编辑

导航