By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 971 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

why underscore is exception while declaring the variable in c

P: 1
we can't use the special characters in c while declaring the variable.but we use the special character underscore for declaring the variable.
Mar 22 '17 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 9,197
The underscore was to be used only by programmers developing the C system functions. Regular developers were not to use it at all.

This way if your variable name matched a system variable all would be well because the system variable had a leading underscore while yours did not.

Of course, this doesn't work too well because it relies on humans to follow rules. The problem is resolved in C++ by using namespaces.
Mar 22 '17 #2

Expert 100+
P: 2,396
There are a number of reserved identifier patterns. The following list comes from the C99 Standard. By now there may be more reserved patterns. The compiler does not typically warn if you are using a reserved identifier.

Always reserved.
Allowed only for automatic variables.
Allowed only for static or automatic variables.
Allowed only if you don't include the specified header file.
E[0-9A-Z][any] (errno.h)
LC_[A-Z][any] (locale.h)
SIG_[A-Z][any] (signal.h)
SIG[A-Z][any] (signal.h)
wcs[a-z][any] (wchar.h)
Mar 23 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.