#include "stdafx.h"
#include <stdlib.h>
#include <windows.h>
//函数指针
int plus(int a, int b) {
return a + b;
}
int minus(int a, int b) {
return a - b;
}
int plus2(int *a, int *b) {
return *a + *b;
}
int minus2(char * a, char *b) {
return 0;
}
int main(){
int result;
int c = 3;
int d = 5;
int(*calc)(int a, int b);
int(*calc2)(void *a, void *);
int * p(int a, int b);
//calc = plus;
calc = minus;
result = calc(3, 5);//-2
calc2 = (int(*)(void *, void *))plus2;
result = calc2(&c, &d);//8
system("pause");
return 0;
}
//内存分配
// 40.3M
//40M 手动分配,0.3M 哪来的? 程序的二进制文件
void mem(){
}
int main(){
//40M的数组
//栈溢出
int t = 1000;
int aa[10];
int ab[100];
/*while (1){
mem();
Sleep(2000);
}*/
int *a = (int *)malloc(sizeof(int)* 1024 * 1024);
if (a == NULL)
{
printf("内存不够,请温柔\n");
}
a[0] = 5;
*a + 1;
printf("%d\n", sizeof(a));
printf("%#x", a);
char *ch = (char *)malloc(sizeof(char)* 1024);
ch + 1;
a = (int *)malloc(sizeof(int)* 1024 * 1024 * 2);
free(a);
a = NULL;
printf("a address: %#x,", a);
// 如果不进行a = NULL;那么,a 就是一个野指针
system("pause");
}
int main() {
int * b = (int *)calloc(4, 100 * sizeof(int));
if (b == NULL)
{
printf("内存不够,请温柔\n");
}
//printf("%d\n", sizeof(a));
printf("%#x", b);
system("pause");
return 0;
}
字符串使用、函数指针、内存分配
最新推荐文章于 2023-11-06 08:00:00 发布