/*
* 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;
}