pdf

c和指针课后题答案(完整版)

  • 1星
  • 日期: 2016-02-18
  • 大小: 298.92KB
  • 所需积分:0分
  • 下载次数:36
  • favicon收藏
  • rep举报
  • 分享
  • free评论
标签: C和指针课后答案

C和指针的配套课后题答案 高清

文档内容节选

Pointers On C Instructors Guide Pointers on CInstructors Guide i Contents 1 A Quick Start Chapter 1 7 Basic Concepts Chapter 2 11 Data Chapter 3 15 Statements Chapter 4 23 Operators and Expressions Chapter 5 29 Pointers Chapter 6 37 Functions Chapter 7 43 Arrays Chapter 8 55 Chapter 9 Strings Characters and Bytes 69 Chapter 10 Structures and Unions 75 Chapter 11 Dynamic Memory Allocation 79 Chapter 12 Using Structures and Pointers 87 Chapter 13 Advanced Pointer Topics 93 Chapter 14 ......

Pointers On C Instructor’s Guide Pointers on C—Instructor´s Guide i Contents 1 A Quick Start ........................................................................................................ Chapter 1 7 Basic Concepts ...................................................................................................... Chapter 2 11 Data ....................................................................................................................... Chapter 3 15 Statements ............................................................................................................. Chapter 4 23 Operators and Expressions .................................................................................... Chapter 5 29 Pointers .................................................................................................................. Chapter 6 37 Functions ............................................................................................................... Chapter 7 43 Arrays .................................................................................................................... Chapter 8 55 Chapter 9 Strings, Characters, and Bytes .............................................................................. 69 Chapter 10 Structures and Unions ........................................................................................... 75 Chapter 11 Dynamic Memory Allocation ................................................................................ 79 Chapter 12 Using Structures and Pointers ............................................................................... 87 Chapter 13 Advanced Pointer Topics ...................................................................................... 93 Chapter 14 The Preprocessor ................................................................................................... Chapter 15 Input/Output Functions .......................................................................................... 95 Chapter 16 Standard Library .................................................................................................... 119 Chapter 17 Classic Abstract Data Types ................................................................................. 129 Chapter 18 Runtime Environment ........................................................................................... 145 1 A Quick Start 1.1Questions 1. To make the program easier to read, which in turn makes it easier to maintain later. 3. It is easier to see what a named constant represents, if it is well named, than a literal constant, which merely displays its value. 4. "%d %s %g\n" 6. The programmer can put in subscript checks where they are needed; in places where the sub- script is already known to be correct (for example, from having been checked earlier), there is no overhead expended in checking it again. But the real reason they are omitted is the fact that sub- scripts are implemented as pointer expressions, which are described in Chapter 8. 7. More characters would be copied than are actually needed; however, the output_col would be updated properly, so the next range of characters would be copied into the output array at the proper place, replacing any extra characters from the preceding operation. The only potential problem is that the unbounded strcpy might copy more characters into the output array than it has room to hold, destroying some other variables. 1.2ProgrammingExercises 1. Watch the solutions for proper use of void declarations and a reasonable style. The first pro- gram is no place to begin learning bad habits. The program will compile and run on most sys- tems without the #include statement. /* ** Print the message "Hello world!" to the standard output. */ #include void main( void ) Solution 1.1 continued... 1 2 Chapter 1 A Quick Start { } printf( "Hello world!\n" ); Solution 1.1 hello_w.c 3. Many students will attempt to read the input file line by line, which is unnecessarily complicated. Other common errors are to forget to initialize the sum to -1, or to declare it an integer rather than a character. Finally, be sure the variable used to read the characters is an integer; if it is a character variable, the program will stop on systems with signed characters when the input con- tains the binary value 0377 (which, when promoted to an integer, is -1 and equal to EOF). Note that the overflow renders this program nonportable, but we don’t know enough yet to avoid it. /* ** This program copies its standard input to the standard output, and computes ** a checksum of the characters. */ The checksum is printed after the input. #include #include int main( void ) { int char c; sum = –1; /* ** Read the characters one by one, and add them to the sum. */ while( (c = getchar()) != EOF ){ putchar( c ); sum += c; } printf( "%d\n", sum ); return EXIT_SUCCESS; } Solution 1.3 checksum.c 4. The basis of this program is an array which holds the longest string found so far, but a second array is required to read each line. The buffers are declared 1001 characters long to hold the data plus its terminating NUL byte. The only tricky thing is the initialization to prevent garbage from being printed when the input is empty. /* ** Reads lines of input from the standard input and prints the longest line that ** was found to the standard output. It is assumed that no line will exceed Solution 1.4 continued... Pointers on C—Instructor´s Guide 3 ** 1000 characters. */ #include #include #define MAX_LEN 1001 /* Buffer size for longest line */ int main( void ) { char int char int input[ MAX_LEN ]; len; longest[ MAX_LEN ]; longest_len; /* ** Initialize length of the longest line found so far. */ longest_len = –1; /* ** Read input lines, one by one. */ while( gets( input ) != NULL ){ /* ** Get length of this line. ** longest line, save this line. */ len = strlen( input ); if( len > longest_len ){ If it is longer than the previous longest_len = len; strcpy( longest, input ); } } /* ** If we saved any line at all from the input, print it now. */ if( longest_len >= 0 ) puts( longest ); return EXIT_SUCCESS; } Solution 1.4 6. The statements /* ** Make sure we have an even number of inputs ... */ if( num % 2 != 0 ){ puts( "Last column number is not paired." ); longest.c
更多简介内容

推荐帖子

最全的电路测试流程
当一个电路板焊接完后,在检查电路板是否可以正常工作时,通常不直接给电路板供电,而是要按下面的步骤进行,确保每一步都没有问题后再上电也不迟。   连线是否正确   检查原理图很关键,第一个检查的重点是芯片的电源和网络节点的标注是否正确,同时也要注意网络节点是否有重叠的现象。另一个重点是原件的封装,封装的型号,封装的引脚顺
造物工场PCB PCB设计
TI博文--模拟开关和多路复用器基础参数介绍
本帖最后由 qwqwqw2088 于 2020-5-11 11:39 编辑      在测试测量相关应用中,模拟开关和多路复用器有着非常广泛的应用,例如运放的增益调节、ADC分时采集多路传感器信号等等。虽然它的功能很简单,但是仍然有很多细节,需要大家在使用的过程中注意。所以,在这里为大家介绍一下模拟开关和多路复用器的基础参数。 在开始介绍基础的参数之前,我们有必要介绍一下模拟开关和多路复用
qwqwqw2088 【模拟与混合信号】
CC2540 蓝牙低能耗 USB 软件狗参考设计
CC2540 USB 软件狗是演示如何使用具备 USB 功能的蓝牙低功耗 (BLE) 无线 MCU 的完整示例。此参考设计可用于在任何含 USB 主机的系统上启用蓝牙智能和物联网应用。   特性 简单的 BLE 至 USB 连接 - 将 BLE 添加到带 USB 的现有产品 包含调试接头、LED 和按钮 - 实现更快速的开发 它还可用作分析 BLE 协议以及软件和系统级调试的数据
fish001 【无线连接】
IL0389 电子纸(墨水屏)驱动
  项目网站 https://github.com/T-Wilko/MicroPython-IL0389-driver   ''' Copyright (c) 2020 Thomas Wilkinson Permission is hereby granted, free of charge, to any person obtaining a c
dcexpert 【MicroPython开源版块】
什么是输出阻抗?什么是阻抗匹配?
一、输出阻抗 在了解“阻抗匹配”这个问题之前,我们先来学习一下什么是“输出阻抗”? 在实际电路设计中,无论信号源、放大器或电源,都有输出阻抗的问题。 输出阻抗其实就是一个信号源的内阻。本来,对于一个理想的电压源(包括电源),内阻应该为 0,而对于一个理想电流源的阻抗应当为无穷大。人们比较较容易“忘记”输出阻抗。 下面,我们以电压源为例来讲这个问题。 现实中的电
火辣西米秀 【模拟与混合信号】
参加 TI.com.cn 测试, 可享受 9 折优惠!
分享给大家一个TI.com.cn的测试活动,参与可获TI购物9折优惠码!     TI 正在为新设计的TI.com.cn产品页面寻求反馈,并希望邀请您参加 30 分钟的电脑远程测试 。我们将非常感谢,如果您可以选择加入Analog 或者 EP 产品页面链接加入我们并安排时间与我们进行测试。   加入 Analog 产品页面测试   加入 EP产品页
eric_wang TI技术论坛

评论

登录/注册

意见反馈

求资源

回顶部

datasheet推荐 换一换

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版 版权声明

北京市海淀区知春路23号集成电路设计园量子银座1305 电话:(010)82350740 邮编:100191

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2020 EEWORLD.com.cn, Inc. All rights reserved
$(function(){ var appid = $(".select li a").data("channel"); $(".select li a").click(function(){ var appid = $(this).data("channel"); $('.select dt').html($(this).html()); $('#channel').val(appid); }) })