Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the understanding and understanding of several constants in C language

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to understand and understand several constants in C language. the content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

What is the constant of C language?

A constant is a quantity whose value cannot be changed while the program is running. Constants in C language can be divided into direct constants and symbolic constants. Constants are divided into: literal constants, const-modified constants, # define-defined identifier constants, enumeration constants.

2. Explain respectively 1. Literal constant

Literal constant: a value that is entered directly into the program.

For example, in myAge=19; myAge is a variable of type int, while 26 is a literal constant.

For example, float price=18.8;price is a float type variable, while 18.8 is a literal variable.

Constant variables modified by 2.const

Const defines a variable, not a constant, but the value of this variable is not allowed to change is a constant! With a type. There is type checking at compile time.

Example: const int n is called const modification constant, const modification constant in C language only limits the variable n can not be changed directly, but n is essentially a variable, so it is called constant.

Identifier variables defined by 3.#define

Define defines constants without types and only makes simple character substitutions. It works during precompilation, and there is no type checking.

4. Enumeration constant

Enumeration constants can create a new type and then define new type variables, defining the values of those variables as a set of possible values.

If there is no special instruction, the enumeration constant starts at 0 by default and increases by 1 in turn.

A few notes about enumerations:

The ① enumeration value is a constant, not a variable. You cannot assign a value to it with an assignment statement in the program.

② can only assign enumerated values to enumerated variables, not the values of elements directly.

The above is the understanding and understanding of several constants in C language. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report