C Program to print the values stored in identifiers.

An identifier in C is a name given to a variable, function, array, structure, or any other user-defined item. Identifiers follow strict rules in C: they must start with a letter or underscore, can contain letters, digits, and underscores, must not be a reserved keyword, and are case-sensitive. This last point — case sensitivity — is a common source of bugs for beginners coming from case-insensitive languages.

Identifier Rules in C

Rule Valid example Invalid example Why invalid
Must start with a letter or _ count, _total 1count Starts with a digit
May contain letters, digits, _ first_name2 first-name Hyphen is not allowed
Must not be a C keyword integer_val int, return Reserved keywords
Case-sensitive sum, Sum, SUM (three distinct names)
No spaces total_count total count Space is a delimiter, not part of a name
Length counter_loop_index Compiler-dependent (C89: 31 chars significant) Beyond limit, names may be truncated

C Program: Identifiers and Case Sensitivity

/* C identifiers: naming rules, case sensitivity, underscore
 * Compile: gcc -ansi -Wall -Wextra identifiers.c -o identifiers */
#include <stdio.h>

int main(void)
{
    /* Case sensitivity: sum, Sum, and SUM are three distinct variables */
    int sum   = 10;
    int Sum   = 20;
    int SUM   = 30;

    /* Underscore is a valid identifier character */
    int first_name_length = 5;
    int _private_count    = 99;

    printf("sum   = %d\n", sum);
    printf("Sum   = %d\n", Sum);
    printf("SUM   = %d\n", SUM);
    printf("All three are different identifiers.\n\n");

    printf("first_name_length = %d\n", first_name_length);
    printf("_private_count    = %d\n", _private_count);
    printf("Underscores are valid in identifier names.\n");

    return 0;
}

How to Compile and Run

gcc -ansi -Wall -Wextra identifiers.c -o identifiers
./identifiers

Sample Output

sum   = 10
Sum   = 20
SUM   = 30
All three are different identifiers.

first_name_length = 5
_private_count    = 99
Underscores are valid in identifier names.

Code Explanation

  • Three variables sum, Sum, SUM — the C compiler treats each as a completely separate variable with a separate memory location. Assigning 10 to sum does not affect Sum or SUM. This is the critical point: C is case-sensitive at the language level, unlike SQL or early BASIC dialects.
  • Underscore in identifiers — the underscore _ is treated as a letter, so first_name_length is a single valid identifier. This is the conventional separator in C’s snake_case naming style (as opposed to camelCase used in Java or JavaScript).
  • Leading underscore convention_private_count starts with an underscore. This is valid but there is a convention: names starting with a single underscore followed by a lowercase letter are reserved for file-scope names by the implementation. Names starting with double underscores or underscore followed by uppercase (like __count or _Count) are reserved for the compiler. In application code, prefer names that do not start with underscores.
  • No keyword clashes — you cannot use int, if, for, return, void, char, or any other C keyword as an identifier. The compiler will give a syntax error.

C Keywords You Cannot Use as Identifiers

C89/C90 has 32 reserved keywords:

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

C99 adds: inline, restrict, _Bool, _Complex, _Imaginary.

What This Program Teaches

  • Case sensitivity is a C fundamental — every variable name, function name, and macro you write is case-sensitive. A typo that changes a capital to lowercase creates a new identifier, not a compile error — only a linker error if the name doesn’t exist, which can be confusing to diagnose.
  • Naming conventions matter — use lowercase_with_underscores for variables and functions (e.g., first_name, calculate_sum), UPPERCASE_WITH_UNDERSCORES for macros (e.g., MAX_SIZE), and PascalCase or UPPER for structs depending on project style. Consistency prevents accidental shadowing and makes code readable.
  • Meaningful names prevent bugs — variables named x, x1, X for three different values are almost impossible to distinguish at a glance. Names like width, height, area make the program self-documenting and prevent accidental variable mix-ups.
  • Identifier length limits — C89 guarantees only the first 31 characters of an identifier are significant for external names (linker-visible). Internal identifiers (local variables) may be longer. In practice, modern compilers support much longer identifiers, but extremely long names are still bad style.

Related Programs

Recommended book:
The C Programming Language — Kernighan & Ritchie (India) |
(US)
 | 
C Programming: A Modern Approach — K.N. King (India) |
(US)

Practice what you learned: C Aptitude Questions — or try our C Programming Quiz App on Android.

2 comments on “C Program to print the values stored in identifiers.

  • Alfred Tabisola says:

    Recently i got a blogspot intended for my mixtapes that I uploaded but when I actually search my DJ name (even complete url), it shouldn’t appear in the google search. Does it take about a week for this to appear or do I have to pay to get it to come up?.

    Reply

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>