#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<stddef.h>
struct p{
int n;
float f;
};
int main()
{
struct p *sptr;
printf("sizeof *char: %d\n", sizeof(char*));
printf("sizeof *int: %d\n", sizeof(int*));
printf("sizeof *float: %d\n", sizeof(float*));
printf("sizeof *double: %d\n", sizeof(double*));
printf("sizeof *struct: %d\n", sizeof(sptr));
return 0;
}
#include<stdio.h>
#include<stddef.h>
#include<string.h>
int main(void)
{
char str[] = "Hello world!";
char *pstart = str;
char *pend = str + strlen(str);
ptrdiff_t difp = pend - pstart;
printf("%d\n", difp);
return 0;
}
/* Types for `void *' pointers. */ #if __WORDSIZE == 64 # ifndef __intptr_t_defined typedef long int intptr_t; # define __intptr_t_defined # endif typedef unsigned long int uintptr_t; #else # ifndef __intptr_t_defined typedef int intptr_t; # define __intptr_t_defined # endif typedef unsigned int uintptr_t; #endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#define ID_STR_LEN 12
#define NAME_STR_LEN 10
typedef struct student
{
char id[ID_STR_LEN];
char name[NAME_STR_LEN];
uint8_t age;
}student;
student * create_student()
{
student *stu = (student *)malloc(sizeof(student));
if (stu == NULL)
return NULL;
memset(stu, 0, sizeof(student));
return stu;
}
void *free_student(student *stu)
{
if (stu)
free(stu);
return 0;
}
static void init_student(student * stu)
{
assert(stu);
const char *id = "2013112210";
const char *name = "Anker";
uint8_t age = 21;
memcpy(stu->id, id, strlen(id));
memcpy(stu->name, name, strlen(name));
stu->age = age;
}
static int handle_student(intptr_t handle)
{
if (handle == 0)
{
return -1;
}
student *stu = (student*)handle;
printf("id: %s\n", stu->id);
printf("name: %s\n", stu->name);
printf("age: %u\n", stu->age);
return 0;
}
int main(void)
{
student *stu;
stu = create_student();
init_student(stu);
//将指针转换为intptr_t类型
intptr_t handle = (intptr_t)stu;
handle_student(handle);
free_student(stu);
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有