Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the scope and life cycle of variables in C language?

Shulou Source: shulou.com Published: 2022-06-01 10:24:02 10月03日 Update

This article is about the scope and life cycle of variables in C. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Scope and life cycle scope of variables

Scope, programming concept: Generally speaking, a name used in a piece of code is not always available, and the scope of the code that limits the availability of the name is the scope of the name.

The scope of a local variable is the local scope in which the variable is located.

The scope of global variables is the entire project.

life cycle

The life cycle of a variable refers to the time period between the creation of the variable and the destruction of the variable

The life cycle of a local variable is: the in-scope life cycle begins and the out-of-scope life cycle ends.

The life cycle of a global variable is: the life cycle of the entire program.

constant literal constant

const modified constant variable

#define Defined identifier constants

enumeration constant

String Initial String

"Hello C Travels.\ n"

This string of characters enclosed in double quotes is called a String literal, or simply a string. (Use character arrays to store strings)

Note: The end of a string is an escape character of\0. \0 is an end flag when calculating string length and does not count as string content.

library function

escape character

written examination questions

escape character list

\? Used when writing consecutive question marks to prevent them from being parsed into three-letter words\'used to represent character constants'\"used to represent double quotes inside a string\\used to represent a backslash to prevent it from being interpreted as an escape sequence character.\ a warning character, beep\b backspace\n newline\t horizontal tab\v vertical tab\dddddd indicates 1 to 3 octal digits. For example: \130 X\xdddd represents 2 hexadecimal digits. For example: 0 Comments

Unneeded code in the code can be deleted directly or commented out

Some of the code is difficult to understand, you can add a comment text

annotation style

C-style comments/* xxxx */

Defect: Cannot nest comments

C++ style comments//xxxxxx

You can comment on one line or more.

Thank you for reading! About "what is the scope and life cycle of variables in C language" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Character variable function period life string comment code constant escape language content name local program style global tab quotation mark number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia OPPO Reno macOS Redmi