字符串使用、函数指针、内存分配

#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;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值