当前位置:网站首页>Constant knowledge explanation of C language
Constant knowledge explanation of C language
2022-07-27 02:24:00 【Guangguangzi】
Constant
C Language includes Constant and Variable , Let's talk about it today C Constant in language .
Constants are divided into the following :
(1) Literal constants : Usually written directly Invariant quantity ( It can be an integer , Floating point numbers , character , character string )
#include<stdio.h>
int main()
{
123456; // Literal constants
5.21; // Literal constants
‘a’; // Literal constants
"abcd"; // Literal constants
return 0;
}(2)const Embellished Constant variable ( As the name suggests, it has the characteristics of variables, but it is still a constant )
#include<stdio.h>
int main()
{
const int a = 5;
a = 6;// here a The value of will not change ,a Is a variable but in const Under the decoration of ,a The value of determines , Cannot change , For constant .
int m[a] = {0,1,2,3};//a Here we have the properties of variables , This is the wrong expression definition array in some compilers
}(3)#define Defined Identifier constant ( Macro definition , Define before the main function )
#include<stdio.h>
#define PI 3.14
#define MAX 10
int main()
{
int a = 0;
a = PI*PI; //PI The value of can be directly used
int arr[MAX] = {0};//MAX It's a constant 10
printf("%d",a);
printf("%d",arr[1]);
return 0;
}(4) Enumeration constants ( There is a fixed format , Common in general life Gender , Three primary colors And so on , You can use enumeration )
enum SEX // Gender can be divided into men and women It can be counted
{
nan, // Enumerating combinations of constants here nan The default is 0, first (nv Or in the first )
nv // The default is 1
};
int main()
{
printf("%d\n", nan); // Output is 0
printf("%d\n", nv); // Output is 1
return 0;
}That's all C The constant knowledge of language is explained .
Ask for three company , Pay attention !
边栏推荐
- First acquaintance with C language (1)
- (the most detailed in History) codeforces round 805 (Div. 3) e Split Into Two Sets
- Lecture 3 - GPIO input / output library function usage and related routines
- C语言——第一个程序、打印、变量和常量
- Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
- HCIP-第五天-OSPF扩展配置实验
- HandsomeForum学习论坛
- C language -- nesting of relational and logical operators, if statements, switch statements, and branch structures
- HCIP-第二天
- Golang implements TCP chat room
猜你喜欢

【C语言】阶乘实现

数字集成电路:CMOS反相器(一)静态特性

(前缀和/思维)Codeforces Round #806 (Div. 4)F. Yet Another Problem About Pairs Satisfying an Inequality

静态路由综合实验

Hcip first day static routing comprehensive experiment
NPM reports an error, error: eperm: operation not permitted, MKDIR

OSPF static experiment

RS-485总线通信应用

C语言——关系运算符和逻辑运算符、if语句、switch语句、分支结构的嵌套

HCIP-第六天-OSPF静态大实验
随机推荐
C language - value range of data type and basic data type
Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
有趣的C语言
ESP8266Wi-Fi接入云平台
(前缀和/思维)Codeforces Round #806 (Div. 4)F. Yet Another Problem About Pairs Satisfying an Inequality
记录第N次SQL异常
Full company mGRE and star topology mGRE
C language - assignment operator, compound assignment operator, self increasing and self decreasing operator, comma operator, conditional operator, goto statement, comment
静态路由实验配置
HCIP-第一天
The basic configuration of static routing (planning of IP address and configuration of static routing) realizes the accessibility of the whole network.
【C语言】阶乘实现
NAT网络地址转换协议-拓扑实验
Codeforces Round #810 (Div. 2), problem: (B) Party
HCIP-第二天
C language - array, string handler, strlen, strcpy and strncpy, strcat and strncat, StrCmp and strncmp
数字集成电路:MOS管器件章(二)
Open the door of programming
Today, let's talk about escape characters [cute new version]
First knowledge of C language (2)