Keywords and Identifiers in C

In this lesson, you will learn about Keywords and identifiers in C. Keywords, or reserved words, are used in the C language as part of the syntax. Identifiers are the names in a C program, such as variables, functions, constants, arrays, etc.

C Keywords

In C, there are keywords or reserved words that are part of the program for a purpose, such as the ‘if’ keywords, which he used for an ‘if’ condition statements. Generally, there are 32 keywords; these keywords cannot be utilized to name a function, a variable, an array, etc.

List of Keywords in C

Below are all the Keywords in C, listed in alphabetical order.

auto break case char
const continue default do
double else enum extern
float for goto if
int long register return
short signed sizeof static
struct switch typedef union
unsigned void volatile while

Keywords in C and their Usage

auto, signed, const, extern, register, unsigned – used to define a variable.

break – used to break out a loop or case statement.

continue – used to perform the next iteration in ‘for’, ‘white’, and ‘do-while loops, skipping the rest of the current iteration statements.

enum – used to define an enumerator.

for, while, do – used to define loops.

goto– used to jump to a specific statement in the code.

if, else, switch, case, default – Used for decision control.

int, float, char, double, long – datatypes that are used during variable or function declaration.

return – used to return a value.

sizeof – used to know the size of an object.

struct, typedef – used in structures

union – used to define a collection of variables that share the same memory location and memory storage.

void – to define a function as a void function.

volatile – Volatile tells the compiler not to optimize anything associated with a volatile variable

C Identifiers

Identifiers in C are the name that programmers come up with for variables, functions, arrays, etc. They are a collection of alphanumeric strings that must begin with an alphabet or an underscore. For Example, Students, _Students, are valid identifiers in C.

Type of Identifiers in C

In the C Programming language, there are two types of identifiers.

  • Internal identifier
  • External identifier

Internal Identifier: An internal Identifier type is used within a class or function scope and cannot be used in the external linkage. An example of an Internal Identifier is a local variable.

External Identifier: An External Identifier is used for external linkage, suck as global variables, and public functions.

Rules of identifiers in C

  • Identifiers are case sensitive; for example, the identifiers var1 and Var1 are not the same.
  • Identifiers can be constructed with upper or lowercase alphabetic characters and can contain numbers (0 to 9), the dollar sign ($), and the underscore (_)
  • blank space of commas cannot be part of identifiers.
  • Identifiers cannot begin with a number.
  • Identifiers cannot be the same as a keyword. For Example, ‘short’ cannot be used as an identifier.
  • identifiers cannot be more than 31 characters in length
  • Use the camelCase or PascalCase naming convention for better readability.

 

Good naming Convention: StudentRecords. customerOrder
bad naming convention: Studentrecord, cutomerorder

Now we have learned about Keywords and Identifiers, Let’s move to the next lesson!

Back to: Learn C Programming > Overview of C

Leave a Reply

Your email address will not be published. Required fields are marked *