文档章节

<C Primer Plus> 1 ~ 6 章

乔棋
 乔棋
发布于 2017/08/01 22:52
字数 688
阅读 12
收藏 0

============================================================================

Note Why Input and Output Are Not Built In

Perhaps you are wondering why facilities as basic as input and output aren’t included auto- matically. One answer is that not all programs use this I/O (input/output) package, and part of the C philosophy is to avoid carrying unnecessary weight. This principle of economic use of resources makes C popular for embedded programming—for example, writing code for a chip that controls an automotive fuel system or a Blu-ray player.  

============================================================================

Syntax Errors  VS Semantic Errors 

Syntax Errors: You commit a syntax error when you don’t follow C’s rules. It’s analogous to a grammatical error in English. For instance, consider the following sentence: Bugs frustrate be can. This sentence uses valid English words but doesn’t follow the rules for word order, and it doesn’t have quite the right words, anyway. C syntax errors use valid C symbols in the wrong places. 

Semantic Errors: Semantic errors are errors in meaning. For example, consider the following sentence: Scornful derivatives sing greenly. The syntax is fine because adjectives, nouns, verbs, and adverbs are in the right places, but the sentence doesn’t mean anything. In C, you commit a semantic error when you follow the rules of C correctly but to an incorrect end.  

============================================================================

Bits, Bytes, and Words

The terms bit, byte, and word can be used to describe units of computer data or to describe units of computer memory. We’ll concentrate on the second usage here.

The smallest unit of memory is called a bit. It can hold one of two values: 0 or 1. (Or you can say that the bit is set to “off” or “on.”) You can’t store much information in one bit, but a com- puter has a tremendous stock of them. The bit is the basic building block of computer memory.

The byte is the usual unit of computer memory. For nearly all machines, a byte is 8 bits, and that is the standard definition, at least when used to measure storage. (The C language, how- ever, has a different definition, as discussed in the “Using Characters: Type char" section later in this chapter.) Because each bit can be either 0 or 1, there are 256 (that’s 2 times itself 8 times) possible bit patterns of 0s and 1s that can fit in an 8-bit byte. These patterns can be used, for example, to represent the integers from 0 to 255 or to represent a set of characters. Representation can be accomplished with binary code, which uses (conveniently enough) just 0s and 1s to represent numbers. (Chapter 15, “Bit Fiddling,” discusses binary code, but you can read through the introductory material of that chapter now if you like.)

A word is the natural unit of memory for a given computer design. For 8-bit microcomputers, such as the original Apples, a word is just 8 bits. Since then, personal computers moved up to 16-bit words, 32-bit words, and, at the present, 64-bit words. Larger word sizes enable faster transfer of data and allow more memory to be accessed. 

============================================================================

Integer Overflow 

/* toobig.c-exceeds maximum int size on our system */ 
#include <stdio.h>
int main(void)
{

    int i = 2147483647; 
    unsigned int j = 4294967295;

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

    printf("%u %u %u\n", j, j+1, j+2);

    return 0;

}

Here is the result for our system:

2147483647    -2147483648    -2147483647

4294967295    0    1 

The behavior described here is mandated by the rules of C for unsigned types. The standard doesn’t define how signed types should behave. The behavior shown here is typical, but you could encounter something different 

============================================================================

Why C automatically expands a type short value to a type int value when it's passed as an argument to a function?

The answer to this question is that the int type is intended to be the integer size that the computer handles most efficiently. So, on a computer for which short and int are different sizes, it may be faster to pass the value as an int. 

============================================================================

 

 

 

 

© 著作权归作者所有

乔棋
粉丝 0
博文 3
码字总数 688
作品 0
沙坪坝
程序员
私信 提问
C Primer Plus(5版)第8章编程题1_重定向实现

小伙伴们,对C语言编程有疑问的,可以加微信交流:poo_poo或者扫描我的头像,验证时请注明是“知友” 一、题目描述 本题是第8章编程题的第一道题,题目如下: 二、题目及思路分析 从题述来看...

石家的鱼
2017/07/11
0
0
C语言书籍资料汇总

我汇总出自己收藏的C语言方面的书籍资料,方便后期使用,或许你也用的到。 以下内容,有链接的都可以下载。 一、书籍 元老级别的书籍: C程序设计语言.pdf (c语言之父) C Primer plus 第5...

BjarneCpp
2017/11/06
0
0
学习C语言的教材

我的C语言是自学的,这些年看过不少教材。 下面,我对其中一些教材做个点评。 1. How to Think Like a Computer Scientist: C version 这是我读过最易懂的C语言教材。 虽然它只讲解最基本的语...

阮一峰
2011/09/18
0
0
Kotlin 资源大全 - 学 Kotlin 看这一篇教程就够了

目录 介绍 官网及文档 中文社区 教程 & 文章 开源库和框架 Demo 其他 介绍 为什么要做这个? 今天凌晨的 Google I/O 上,Google 正式宣布官方支持 Kotlin. 为了让大家更快了解和上手 Kotlin...

稀土君
2017/05/19
0
0
【C++】第1-2章 C++基础 知识总结

《C++ Primer Plus》第1-2章知识点总结 首先声明,本文总结内容均是在一定的C语言基础上进行的总结,因为第1-2章内容不多,所有知识点可能有些零散,不过都是刚学的容易忽略的知识点 C++融合...

qq_37792173
2017/09/19
0
0

没有更多内容

加载失败,请刷新页面

加载更多

vue v-html动态生成的html怎么加样式

1. v-html加样式 在vue开发中碰到需要动态生成html,并且需要有样式,这时候发现像往常一样写样式的时候不起作用,网上搜了一下,发现通过 v-html 创建的 DOM 内容不受作用域内的样式影响,但...

litCabbage
41分钟前
4
0
Appium+python自动化(三十三)- 测试环境和本地环境傻傻滴分不清楚-Remote(超详解)

  简介   在前边所有涉及启动app的时候有这样一行代码driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps),很多小伙伴们和同学们不知道这个ip和端口哪里来的,我...

开源仔
49分钟前
2
0
各种放大器电路之功率放大器的分析

  供给负载一定输出功率的放大器叫做功率放大器。它是收音机、扩音机或其他电子设备的末级,它推动扬声器发出声音,使电动机转动,使记录仪表动作等。功率放大器主要是考虑如何获得最大的输...

xyxyty
49分钟前
3
0
MySQL8.0.17 - Multi-Valued Indexes 简述

本文主要简单介绍下8.0.17新引入的功能multi-valued index, 顾名思义,索引上对于同一个Primary key, 可以建立多个二级索引项,实际上已经对array类型的基础功能做了支持 (感觉官方未来一定...

阿里云官方博客
今天
13
0
make4.1降级 make-3.81、2错误

在编译 make-3.82 的时候出现如下错误提示 glob/glob.c:xxx: undefined reference to `__alloca'` 修改 /glob/glob.c // #if !defined __alloca && !defined __GNU_LIBRARY__ # ifdef __GNUC......

Domineering
今天
19
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部