The C Programming language之1

本文讲述了作者重新学习C语言的初衷,介绍了《The C Programming Language》一书的重要性,并通过Hello, World!程序实例,详细解析了C语言的基础语法与编译流程。

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

今天突然间准备重新学习一下C语言,动机是因为最近想学学嵌入式,百度了解一下嵌入式之后发现,C语言对于嵌入式的学习非常重要,所以准备重新系统的学习一下。

为什么要选择The C Programming language?

因为这本书是由C语言的设计者Dennis M. Ritchie和著名计算机科学家Brian W. Kernighan编写,其他的自不必说!

Getting Started

hello, world

程序:

#include<stdio.h>
int main(void)
{
	printf("hello,world\n");
}

1、关于编译器的问题

原著上使用的UNIX系统,本来想安装一个UNIX虚拟机,但是对于UNIX系统一窍不通,不会用,所以放弃。借鉴了C语言入门经典一书中的windows上的C语言编译器,Pelles C,我直接传上来,省的大家去百度了!

下载地址:https://download.youkuaiyun.com/download/thebestleo/10643098

2、关于程序本身的解读

1)、C程序是有函数和变量组成的,所谓函数就是操作运算,所谓变量就是操作运算时用于存储有关的值。

2)、C程序中必须包含一个main函数,main函数是程序的起点。

3)、函数之间传递变量是通过函数调用及函数参数来实现的。(函数参数就是函数名后面括号中的变量)。

函数调用之前要指定函数所在文件位置,如程序中的#include<stdio.h>,表明要调用的函数包含在stdio.h文件中,(stdio.h是C语言标准库)。你还可以包含你自己写的一些函数。

4)、程序中的\n是一个转义字符,表示空格,C语言中有很多转移字符,使用的时候请自行查表。

课后习题:

1、如果程序中遗漏include会出现什么问题?

程序如下:

int main(void)
{
	printf("hello,world\n");
}

运行结果:

在我的系统中该程序是可以运行的,但是这并不代表程序是正确的,这种情况可能是由于编译器本身问题,所以程序才可以运行,如果换成别的系统或者别的编译器,很大可能编译不会通过

2、在printf函数中包含/C字符,观察运行结果。

1)、在字符串中插入\c

程序如下:

#include<stdio.h>
int main(void)
{
	printf("hello\c,world\n");
}

运行结果如下:

2)、将转义字符\n改成\c

程序如下:

#include<stdio.h>
int main(void)
{
	printf("hello,world\c");
}

结果如下:

程序没有出现编译错误,但是出现了警告提示,编译器没有识别/c,直接把它当做字符C输出了!

警告如下:C:\Users\Admin\Documents\Pelles C Projects\1.1\1.0.c(4): warning #2176: Unrecognized character escape sequence '\c'.

The C programming Language By Brian W. Kernighan and Dennis M. Ritchie. Published by Prentice-Hall in 1988 ISBN 0-13-110362-8 (paperback) ISBN 0-13-110370-9 目录结构: Contents Preface Preface to the first edition Introduction Chapter 1: A Tutorial Introduction Getting Started Variables and Arithmetic Expressions The for statement Symbolic Constants Character Input and Output File Copying Character Counting Line Counting Word Counting Arrays Functions Arguments - Call by Value Character Arrays External Variables and Scope Chapter 2: Types, Operators and Expressions Variable Names Data Types and Sizes Constants Declarations Arithmetic Operators Relational and Logical Operators Type Conversions Increment and Decrement Operators Bitwise Operators Assignment Operators and Expressions Conditional Expressions Precedence and Order of Evaluation Chapter 3: Control Flow Statements and Blocks If-Else Else-If Switch Loops - While and For Loops - Do-While Break and Continue Goto and labels Chapter 4: Functions and Program Structure Basics of Functions Functions Returning Non-integers External Variables Scope Rules Header Files Static Variables Register Variables Block Structure Initialization Recursion The C Preprocessor File Inclusion Macro Substitution Conditional Inclusion Chapter 5: Pointers and Arrays Pointers and Addresses Pointers and Function Arguments Pointers and Arrays Address Arithmetic Character Pointers and Functions Pointer Arrays; Pointers to Pointers Multi-dimensional Arrays Initialization of Pointer Arrays Pointers vs. Multi-dimensional Arrays Command-line Arguments Pointers to Functions Complicated Declarations Chapter 6: Structures Basics of Structures Structures and Functions Arrays of Structures Pointers to Structures Self-referential Structures Table Lookup Typedef Unions Bit-fields Chapter 7: Input and Output Standard Input and Output Formatted Output - printf Variable-length Argument Lists Formatted Input - Scanf File Access Error Handling - Stderr and Exit Line Input and Output Miscellaneous Functions String Operations Character Class Testing and Conversion Ungetc Command Execution Storage Management Mathematical Functions Random Number generation Chapter 8: The UNIX System Interface File Descriptors Low Level I/O - Read and Write Open, Creat, Close, Unlink Random Access - Lseek Example - An implementation of Fopen and Getc Example - Listing Directories Example - A Storage Allocator Appendix A: Reference Manual Introduction Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage Preprocessor Grammar Appendix B: Standard Library Input and Output: <stdio.h> File Operations Formatted Output Formatted Input Character Input and Output Functions Direct Input and Output Functions File Positioning Functions Error Functions Character Class Tests: <ctype.h> String Functions: <string.h> Mathematical Functions: <math.h> Utility Functions: <stdlib.h> Diagnostics: <assert.h> Variable Argument Lists: <stdarg.h> Non-local Jumps: <setjmp.h> Signals: <signal.h> Date and Time Functions: <time.h> Implementation-defined Limits: <limits.h> and <float.h> Appendix C: Summary of Changes
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值