Variable Rules in C

Previous
Next

Rules for constructing variable names

  • A Variable name consists of any combination of alphabets, digits and underscores.
  • The length of identifier may be up to 31 characters but only the first 8 characters are significant by compiler.
  • The first character of the variable name must either be alphabet or underscore. It should not start with the digit.
  • No commas and blanks are allowed in the variable name.
  • No special symbols other than underscore are allowed in the variable name.
  • We need to declare the type of the variable name before making use of that name in the program.
  • Lower case variables and upper case variables of same name treat differently (case sensitive).
  • Variable name should not match with a keyword, because keywords are the reserved words to do their own tasks such as do, while, int, for…….

C Identifiers

  • “Identifiers” or “symbols” are the names you supply for variables, types, functions, and labels in your program.
  • Identifier names must differ in spelling and case from any keywords.
  • You cannot use keywords as identifiers; they are reserved for special use.
  • A special kind of identifier, called a statement label, can be used in goto statements.
  • The first character of an identifier name must be a non-digit.

Keywords:

  • Keywords are the system defined identifiers.
  • All keywords have fixed meanings that do not change.
  • White spaces are not allowed in keywords.
  • Keyword may not be used as user definer identifier.
  • It is strongly recommended that keywords should be in lower case letters.

There are totally 32(Thirty Two) keywords used in a C programming.

intfloatdoublelong
shortsignedunsignedconst
ifelseswitchbreak
defaultdowhilefor
registerexternstaticstruct
typedefenumreturnsizeof
gotounionautocase
voidcharcontinuevolatile

Escape Sequence Characters in C: C supports some special escape sequence characters that are used to do special tasks. Some of the escape sequence characters are as follow:

SymbolMeaning
\nNew line (Line break)
\bBackspace
\tHorizontal Tab
\fForm feed
\aAlert (alerts a bell)
\rCarriage Return
\vVertical Tab
\?Question Mark
\’Single Quote
\”Double Quote
\\Backslash
\0Null
Previous
Next

Add Comment

Courses Enquiry Form