Chapter 3 : Data and C - Review Questions

本文深入探讨了C语言中的数据类型选择,包括int、float、char等的使用场景,以及long变量相较于int的优势。同时,解析了不同类型常量的表示方法,如整数、浮点数、字符常量等,并详细说明了它们在声明和printf函数中的格式规范。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Which data type would you use for each of the following kinds of data(sometimes more than one type could be appropriate)?

a. The population of East Simpleson

b. The cost of a movie on DVD

c. The most common letter in this chapter

d. The number of times that the letter occurs in this chapter

a. int  b. float  c. char  d. int

2.    Why would you use a type  long  variable instead of type  int ?  

one reason is that long may accommodate larger numbers than int on your system; another reason is that if you do need to handle larger values, you improve portability by using a type guaranteed to be at least 32 bits on all systems.

3.    What portable types might you use to get a 32-bit signed integer, and what would the rationale be for each choice?    

To get exactly 32 bits, you could user int32_t, provided it was defined for your system. To get the smallest type that could store at least 32 bits, use int_least32. And to get the type that would provide the fastest computations for 32 bits, choose int_fast32_t.

4.    Identify the type and meaning, if any, of each of the following constants: 

a.    '\b'      

b.    1066      

c.    99.44

d.    0XAA

e.    2.0e30

a. char constant(but stored as type int)

b. int constant

c. double constant

d. unsigned int constant, hexadecimal format

e. double constant

6.    Identify the data type (as used in declaration statements) and the  printf()  format specifier for each of the following constants: 

Constant

Type

Specifier

a. 12

int

%d

b. 0X3

unsigned int

%#x

c. ‘C’

char(really int)

%c

d. 2.34E07

double 

%f

e. '040'

char(really int)

%c

f. 7.0

double

%f

g. 6L

long

%ld

h 6.0f

float

%f

i 0x5.b6p12

float

%a

     
   7.    Identify the data type (as used in declaration statements) and the  printf()  format specifier for each of the following constants (assume a 16-bit  int ):  
 

Constant

Type

Specifier

a. 012

unsigned int

%#o

b. 2.9e05L

long double

%Le

c. 's'

char(really int)

%c

d. 100000

long

%ld

e. '\n'

char(really int)

%c

f. 20.0f

float

%f

g. 0x44

unsigned int

%x

h. -40

int 

%d

8.    Suppose a program begins with these declarations: 

int imate = 2;  
long shot = 53456;  
char grade = 'A';  
float log = 2.71828;   

Fill in the proper type specifiers in the following  printf()  statements: 

printf("The odds against the %__ were %__ to 1.\n", imate, shot);  
printf("A score of %__ is not an %__ grade.\n", log, grade); 

%d %ld

%f  %c

9. Suppose that  ch  is a type  char  variable. Show how to assign the carriage-return character to  ch  by using an escape sequence, a decimal value, an octal character constant, and a hex character constant. (Assume ASCII code values.)    

ch = '\r';
ch = 13;
ch = '\015';
ch = '\xd';

11.    Identify what each of the following escape sequences represents: 

a.    \n    

b.    \\      

c.    \"    

d.   \t

a. A newline character

b. A backslash character

c. A double quotation character

d. A tab character

转载于:https://www.cnblogs.com/chintsai/p/10291567.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值