华清远见C语言学习笔记七

 

/*
 * test.c
 *
 *  Created on: Jun 29, 2012
 *      Author: 孙旭
 *      华清远见实验室
 */

/*******1********/
#include<stdio.h>
float * fun()
{
 float *i;
 float k=2.3;
 i=&k;
 return i;

}
int main()
{

 float *(*p)()=fun;
 float *q=p();       //另一种用法float *p=fun();
 printf("-----%f\n",*q);
 return 0;

 

/********2*******/
#include <stdio.h>
#include <stdlib.h>
int x = 100;
void f1()
{
 int x = 100;
 void *p = &x;
 printf("%d\n",*((int *)p));
}
//错误的函数写法
int * f2()
{
 int x = 100;
 return &x;
}

int * f3()
{
 return &x;
}

void * f4()
{
 printf("f4....\n");
 return &x;  //int *
}


int main(void) {
 void *p = f4();
 printf("%d\n",*((int *)p));

 void *(*p1)()=f4;
 void *pf4 = p1();

 printf("%d\n",*((int *)pf4));


 return EXIT_SUCCESS;
}

/*****3***/
#include<stdio.h>
int main()
{
 size_t d=-4;   //size_t是unsigned long int型
 unsigned int j=-5;
 int i;
 i=sizeof(d);
 printf("%d\n",j);
 printf("%d\n",d);
 printf("%d",i);  //4
 return 0;
}

/******4****/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct {
 char b[5];
 int e;
 char x[5];
 double f;   //doble 以4进行对齐
 int d;

}stu;
int main()
{
 int i=sizeof(stu);
 printf("%d",i);
 return 0;
}

/********5*******/
#include<stdio.h>
union std{

 char a;
 short s;
 double e;
 int c;
 char b[17];
 double f;
};
int main()
{
 int i=sizeof(union std);   // 在union中是以最长的对齐,但是double是以4对齐
 printf("%d",i);      //20
 return 0;
}

/*******6******/
#include <stdio.h>
#include <stdlib.h>

int main(void) {
 int a=1;
  static int b=a;   //static 初始化必须用常量
  printf("%d",b);   //initializer element is not constant
 return EXIT_SUCCESS;
}

/*******7******/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *test(char *strDest,const char *strSrc)   //实现strcpy函数的功能
{
 char *str=strDest;
 while((*strSrc!=NULL)&&(strSrc!='\0'))
  *strDest++=*strSrc++;
 *strDest='\0';
 printf("%s\n",str);
 return str;
}
int main()
{
 char a[20]="abfdgh";
 char *p="efg";
 printf("%s",test(a,p));
 return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值