What are the naming styles of C user identifiers?
C language identifier naming rules: consist of letters, numbers and underscores. The first character must be a letter or underscore and is case sensitive. The naming styles include camel, underlined and Hungarian nomenclature. It is recommended to use a concise and clear camel nomenclature, but team consistency is more important. Naming should be based on the name and avoid using meaningless identifiers. Naming style has nothing to do with performance, and the main purpose is to improve code readability and maintainability.
C language user identifier naming, this thing looks simple, but in fact there are many ways. If you don't understand, the code you wrote is like a pot of stew, and you will be overwhelmed when you look back. In this article, let’s talk about the naming of this identifier so that you can feel more at ease when writing code.
Let’s talk about the conclusion first: There are no mandatory regulations for naming C language identifiers, but there are good habits that are conventional. Following these habits can make your code clearer, easier to maintain, and better reflect your programming literacy. Don't follow? Then your code is waiting for your teammates to complain about!
Basic knowledge, we need to lay the groundwork
In C language, identifiers are the names you give to variables, functions, structures, etc. Remember, an identifier can only consist of letters, numbers, and underscores, and the first character must be a letter or underscore. Case sensitive, myVar
and myvar
are two different identifiers. You must keep this rule in mind, otherwise the compiler will report you an error without mercy.
Core: Naming style, this is the key
Let’s analyze several common naming styles one by one:
- Camel Case: capitalize the initial letter of a word, such as
myVariable
,userName
. This style looks more comfortable and is more commonly used. But be careful whether the first letter of the first word should be capitalized depends on the specific situation. - Underscore nomenclature (Snake Case): Words are connected by underscores, such as
my_variable
anduser_name
. This style is also quite popular in C language, especially in some large projects, with high clarity. However, with too many underscores, it looks a bit cumbersome. - Hungarian Nomenclature (Hungarian Notation): Prefixes the variable name to represent the variable type, such as
int iAge
,char *szName
. This method was common in early C programming, but it has been gradually eliminated because the type information compiler already knows that adding prefixes seems redundant and it is also troublesome to maintain. Unless you have a particularly strong need for type checking of your code, it is not recommended.
Code examples to make you more intuitive
Hump style:
<code class="c">#include <stdio.h> int main() { int studentAge = 20; char studentName[50] = "John Doe"; printf("Student age: %d, Name: %s\n", studentAge, studentName); return 0; }</stdio.h></code>
Underlined:
<code class="c">#include <stdio.h> int main() { int student_age = 20; char student_name[50] = "John Doe"; printf("Student age: %d, Name: %s\n", student_age, student_name); return 0; }</stdio.h></code>
Advanced usage, and some pitfalls
There is actually no absolute good or bad choice in naming style. The key lies in the consistency of the team and the readability of the code. Once you choose a style, stick to it, don't use hump for a while, or underscore for a while, which will make your code look messy.
In addition, naming should be done to see the name and know the meaning. Do not use meaningless identifiers such as a
, b
, and c
, unless they are used as temporary variables in some very simple algorithms. Good naming can greatly improve the readability and maintainability of the code.
Performance optimization? This has nothing to do with the naming style
Naming style has little impact on performance, mainly to improve the readability and maintainability of the code. Don't think about improving performance by modifying the naming style, it's a pure waste of time.
Best practices, my experience
I personally recommend the camel nomenclature, which is concise and clear and easy to read. But in some places where types need to be emphasized, the underline nomenclature is also good. The most important thing is to maintain consistency within the team and stick to it after choosing a style. Remember, the code is written for people to read, not for compilers to read. Only clear and easy-to-understand code can reduce bugs and improve efficiency. This is the kingly way!
The above is the detailed content of What are the naming styles of C user identifiers?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Bitcoin’s price ranges from $20,000 to $30,000. 1. Bitcoin’s price has fluctuated dramatically since 2009, reaching nearly $20,000 in 2017 and nearly $60,000 in 2021. 2. Prices are affected by factors such as market demand, supply, and macroeconomic environment. 3. Get real-time prices through exchanges, mobile apps and websites. 4. Bitcoin price is highly volatile, driven by market sentiment and external factors. 5. It has a certain relationship with traditional financial markets and is affected by global stock markets, the strength of the US dollar, etc. 6. The long-term trend is bullish, but risks need to be assessed with caution.

The top ten cryptocurrency exchanges in the world in 2025 include Binance, OKX, Gate.io, Coinbase, Kraken, Huobi, Bitfinex, KuCoin, Bittrex and Poloniex, all of which are known for their high trading volume and security.

Currently ranked among the top ten virtual currency exchanges: 1. Binance, 2. OKX, 3. Gate.io, 4. Coin library, 5. Siren, 6. Huobi Global Station, 7. Bybit, 8. Kucoin, 9. Bitcoin, 10. bit stamp.

The top ten cryptocurrency trading platforms in the world include Binance, OKX, Gate.io, Coinbase, Kraken, Huobi Global, Bitfinex, Bittrex, KuCoin and Poloniex, all of which provide a variety of trading methods and powerful security measures.

MeMebox 2.0 redefines crypto asset management through innovative architecture and performance breakthroughs. 1) It solves three major pain points: asset silos, income decay and paradox of security and convenience. 2) Through intelligent asset hubs, dynamic risk management and return enhancement engines, cross-chain transfer speed, average yield rate and security incident response speed are improved. 3) Provide users with asset visualization, policy automation and governance integration, realizing user value reconstruction. 4) Through ecological collaboration and compliance innovation, the overall effectiveness of the platform has been enhanced. 5) In the future, smart contract insurance pools, forecast market integration and AI-driven asset allocation will be launched to continue to lead the development of the industry.

The top ten digital currency exchanges such as Binance, OKX, gate.io have improved their systems, efficient diversified transactions and strict security measures.

Recommended reliable digital currency trading platforms: 1. OKX, 2. Binance, 3. Coinbase, 4. Kraken, 5. Huobi, 6. KuCoin, 7. Bitfinex, 8. Gemini, 9. Bitstamp, 10. Poloniex, these platforms are known for their security, user experience and diverse functions, suitable for users at different levels of digital currency transactions

Bitcoin’s price fluctuations today are affected by many factors such as macroeconomics, policies, and market sentiment. Investors need to pay attention to technical and fundamental analysis to make informed decisions.
