c陷阱与缺陷第一章——Lexical Pitfalls

1.3 Greedy lexical analysis

Maximal munch strategy

The way to convert a C program to tokens is to move from left to right, taking the longest possible token each time.

a---b means a -- - b

Nested comments

#include<stdio.h>
int main(void)
{
	char *s = "this is a /*nested comments*/!";
	puts(s);
	int n = /*/*/2*/**/3;
	printf("%d\n", n);
	return 0;
}

output:

this is a /*nested comments*/!
6

So, the C compiler doesn’t allow nested comments.

Character ‘yes’

if

char c = 'yes';

then

c = 's';

C Primer Plus 学习笔记——第三章 Data and C

Exercise 1.4 What does a+++++b mean?

It means a ++ ++ + b
However, the result of a++ is not an lvalue and hence is not acceptable as an operand of ++.

发布了120 篇原创文章 · 获赞 2 · 访问量 5806

猜你喜欢

转载自blog.csdn.net/Lee567/article/details/103217855