c语言类型表达式运算符,c语言类型、运算符与表达式(含解析).doc

c语言类型、运算符与表达式(含解析)

类型、运算符与表达式

实验内容:

基本数据类型及运算符、表达式的应用

(1) 逗号表达式一

#include "stdio.h"

main()

{

int a,b;

b=((a=3*5,a*4),a+5);

printf("a=%d,b=%d\n",a,b);

}

运行结果:a=15,b=20

(2) 逗号表达式一

#include "stdio.h"

main()

{

int a,b;

a=3*5,a*4;

b= (a=3*5,a*4);

printf("a=%d,b=%d\n",a,b);

}

运行结果:a=15,b=60

(3) 阅读以下程序,当输入数据的形式为:25,13,10(注:表示回车),则正确的输出结果为 A 。

main()

{ int x,y,z;

scanf(“%d%d%d”,&x,&y,&z);

printf(“x+y+z=%d\n”,x+y+z);

}

A) x+y+z=48 B) x+y+z=35 C) x+z=35 D) 不确定值

(4) 自增算符应用

#include "stdio.h"

main()

{

int i=3;

printf("%d,%d \n",i,i++);

}

运行结果:3,3

(5) 强制类型转换

#include "stdio.h"

main()

{

float x ;

int i;

x=3.6;

i=(int)x;

printf("x=%f,i=%d\n ",x,i);

}

运行结果:X=3.6,I=3

(6)字符型变量

#include "stdio.h"

main()

{

char d=’a’;

char c=97;

printf("c=%c \n",c);

printf("d=%d \n",d);

}

运行结果:c=a,d=97

(7)小写字符为大写字符

#include "stdio.h"

main()

{

char c1,c2;

c1='a';

c2 ='b';

c1=c1-32;

c2=c2-32;

printf("%c,%c \n",c1,c2);

}

运行结果:A,B

(8)常量应用一

#include "stdio.h"

#define PRICE 30

main()

{

int num,total;

num=10;

total=num*PRICE;

printf("total=%d \n",total);

}

运行结果:total=300

(9) 以下的输出结果。

main()

{ int i;

i=-4;

printf(“\ni:dec=%d,oct=%o,hex=%x \n”,i,i,i);

}

运行结果:i:dec=-4,oct=37777777774,hex=fffffffc

main()

{ int x=1,y=2;

printf(“x=%d y=%d * sum * =%d\n”,x,y,x+y);

printf(“10 Squared is : %d\n”,10*10);

}

运行结果:x=1,y=2*sum*=3

(10)下面程序错在哪里:

Main()

{

float k;

scanf("%d",k);

printf("%f",k);

}

正确的程序:main()

{

float k;

scanf("%d",&k);

printf("%f",k);

}

(11) 选择题

1. 若x、i、j、k都是int型变量,则计算下面表达式后,x的值为 C 。

x=(i=4,j=16,k=32)逗号后面作为整个表达式

A) 4B) 16C) 32D) 52

2. 下列四组选项中,均不是C语言关键字的选项是 A 。

A) define IF小写的才是 type

B) getc char printf

C) includecasescanf

D) whilegopow

3. 下列四组选项中,均是不合法的用户标识符的选项是 C 。

A) W P_0 do

B) b-a goto int

C) floatla0_A

D) -123abcTEMP

4. 下列四组选项中,均是合法转义字符的选项是 A 。

A) ‘\”’‘\\’‘\n’

B) ‘\’‘\017’‘\”’

C

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值