C++
有点郁闷,就看看了C|++
看的更闷。
// XStudy.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
struct CacheData{
char* cacheItemKey;
char* cacheItem;
int size;
} CP[16],*All;
typedef struct _myinfo_detail
{
long Number;
char Type[256];
} MyInfoDetail, * LPMyInfoDetail;
typedef struct _myinfo
{
long Count;
LPMyInfoDetail MyList;
} MyInfo, * LPMyInfo;
int stringLenght(const char* itemP)
{
int ic=0;
while( (*(itemP++))!='/0')
ic++;
return ic;
};
void pointerTest()
{
//内存分配与回收
char* cacheItem={"wwwStudyezCom" };
char* itemData={"this is a Time To Send4You Test !"};
int size= stringLenght(cacheItem);
printf("%d/r/n",size);
size=sizeof(CP);
printf("%d/n",size );
printf("%s/r/n",cacheItem);
for(int i=0;i<16;i++){
CP[i].cacheItem = "juust a test " ;
CP[i].cacheItemKey ="dasfa";
CP[i].size =stringLenght(CP[i].cacheItemKey);
printf("%d/n",CP[i].size );
}
char buffer[50];
double source = -3.1415;
_gcvt_s(buffer,25,source,20);
printf("缓冲区的长度:%d/n",sizeof(buffer));
printf( "source: %f buffer: '%s'/n", source, buffer );
printf("ALL1:%d/n",sizeof(All));
All=CP;
printf("ALL2:%d/n",sizeof(All));
int len=sizeof(CP)/sizeof(CacheData);
printf("SP:%d/n",len);
int ip=0;
while(ip<len){
printf("%d: %s/n",ip ,( *All++).cacheItem);
printf("%d: %s/n",ip,( CP+ip)->cacheItemKey);
ip++;
}
}
void allocTest()
{
MyInfo myinfo;
int size=sizeof(MyInfoDetail)*10;
myinfo.MyList =(LPMyInfoDetail)malloc(size);
myinfo.Count=10;
for(int i=0;i<myinfo.Count;i++)
{
myinfo.MyList[i].Number=i;
}
printf("Hello World!/n");
}
//第一中用法 一样
int const iAge=4;
const int iPage=4;//意义同上
int age=10;
//指针常量
int const *iPint=&iAge; //Right: &iPage;
//常量指针,
int * const iC= &age;// Error: int * const iC=&iAge;
const int *iP;
//函数指针
void (*pFun)();
typedef void (*Callback)();
int _tmain(int argc, _TCHAR* argv[])
{
// iAge=5; error:C3892
//iPage=4;
iPint=&age;//Error::*iPint=10; (*iPint是常量)
*iC=20;
printf("%d",iAge);
iP=&age;
/*
*iP=age;
*/
//函数指针
pFun =&allocTest;
pFun();
Callback cb=&pointerTest;
cb();
return 0;
}