Summer 4

写出以下程序的运行结果

#include<stdio.h>
#include<stdlib.h>
#define F(X,Y) ((X)+(Y))

//1
#if 0
int main()
{
	char a[20];
	char *p1 = (char *)a;
	char *p2 = (char *)(a + 5);
	int n = p2 - p1;
	printf("%d\n", n);
	system("pause");
	return 0;
}
  n的值为5 
#endif

//2
#if 0
int main()
{
	int a = 3, b = 4;
	printf("%d\n", F(a++, b++));// 输出结果为 7
	system("pause");
	return 0;
}
#endif

//3
#if 0
int main()
{
	int x;
	printf("%d\n", x=5>1+2&&2 || 2*4<4-!0); //x的值为1
    system("pause");
    return 0;
}
#endif

//4
#if 0
int main()
{
	int i = 1, sum = 0;
	while (i<10)
	{
		sum = sum + 1;
		i++;
	}
	printf("i=%d,sum=%d", i, sum); //i=10,sum=9
	system("pause");
	return 0;
}
#endif

//5
#if 0
#pragma pack(4) /*编译选项, 表示4字节对齐 平台:VS2013. 语言:C语言*/
int main(int argc,char*argv[])
{
	struct tagTest1
	{
		short a;
		char d;
		long b;
		long c;
	};

	struct tagTest2
	{
		long b;
		short c;
		char d;
		long a;
	};

	struct tagTest3
	{
		short c;
		long b;
		char d;
		long a;
	};

	struct tagTest1 stT1;
	struct tagTest2 stT2;
	struct tagTest3 stT3;

	printf("%d %d %d", sizeof(stT1), sizeof(stT2), sizeof(stT3));// 12 12 16
	system("pause");
	return 0;
}
#endif

//6
#if 0
enum ENUM_A
{
	X1,
	Y1,
	Z1=5,
	A1,
	B1
};

enum ENUM_A enumA = Y1;
enum ENUM_A enumB = B1;

int main()
{
	printf("%d,%d", enumA, enumB); //enumA=1, enumB=7
	system("pause");
	return 0;
}
#endif

//8
int fun(int x,int y)
{
	static int m = 0;
	static int i = 2;
	i += m + 1;
	m = i + x + y;
	return m;
}

void main()
{
	int j = 4;
	int m = 1;
	int k;
	k = fun(j, m);
	printf("%d\n", k); //8
	k = fun(j, m);
	printf("%d\n", k);//17
	system("pause");
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值