Home > Common Problem > body text

What is the use of declaring variables in C language?

清浅
Release: 2020-09-10 13:21:15
Original
7074 people have browsed it

The function of declaring variables in C language is: you can establish a variable symbol table to avoid miswriting the variable name; the data type of the variable can determine how much memory space the system allocates and determine the value range of the variable, etc.

What is the use of declaring variables in C language?

【Recommended course: C Language Tutorial

Why do we need to declare variables first in C language? What is the use of declaring variables? Next, I will introduce it to you in detail in the article, I hope it will be helpful to you.

The role of declaring variables:

(1) Establish variable symbol table

By declaring variables, the compiler can create a variable symbol table, so The compiler knows very well how many variables are used in the program and the type of each variable. Whether undeclared variables are used, the compiler can find out during compilation. This helps the programmer write the wrong variable name due to negligence.

(2) The data type of the variable indicates how much memory space the system allocates

(3) The data type of the variable indicates how the system interprets the value in the storage space

Same Numeric values, different types will have different interpretations. Int occupies 4 bytes, and float also occupies 4 bytes. It is also a binary number stored in the memory, and this binary number has no identification to distinguish whether it is an int or a float. How to differentiate? It is distinguished by the data type of the variable. Because the declaration establishes the variable symbol table, the system knows how to interpret the variable.

(4) The data type of the variable determines the value range of the variable

The above is the detailed content of What is the use of declaring variables in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!