本文介绍了什么是“文字上的"?在C ++中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在阅读有关C ++的文献时,我会遇到文字"一词​​.我不清楚这个术语在C ++中到底意味着什么.

Often when reading literature about C++, I encounter the word "literal". It is a bit unclear to me what exactly this term means in C++.

推荐答案

文字是一些直接在代码中呈现的数据,而不是通过变量或函数调用间接呈现的数据.

A literal is some data that's presented directly in the code, rather than indirectly through a variable or function call.

以下是一些示例,每行一个:

Here are some examples, one per line:

42
128
3.1415
'a'
"hello world"

构成文字的数据不能由程序修改,但可以将其复制到变量中以供进一步使用:

The data constituting a literal cannot be modified by a program, but it may be copied into a variable for further use:

int a = 42;  // creates variable `a` with the same value as the literal `42`

这个概念绝不是C ++独有的.

文字"一词​​来自您已将数据 literally 写入您的事实程序,即完全按原样编写,而不是隐藏"在变量名后面.

The term "literal" comes from the fact that you've written data literally into your program, i.e. exactly as written, not "hidden" behind a variable name.

这篇关于什么是“文字上的"?在C ++中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 01:36