Lesson 3: C Basics For Beginners Tutorial- Identifiers and Keywords

In this post you can find the short, simple and clear explanations of C basic concepts that are necessary to do a simple C program.
Before that it is recommended to see How to compile and Run C program? as a recap.

Programs for Beginners:

How to write C Programs?

  • C programming statement is not a simple and normal statements of English language.
  • Each and every word in a C program must obey certain rules called syntax.
  • Then only a C program can be completely compiled and the specific operation will be performed to get the right output.
  • To construct a perfect C program, we must know the basic elements that are necessary to construct each C statement.
  • These basic elements are combined to form comprehensive C program components.
  • Lets see about those basic elements of C in detail…

Basic elements to construct a C statement:

 The basic elements of a C statement are:
1. Character Set.
2. Identifiers and keywords.
3. Datatypes.
4. Constants.
5. Variables.
6. Arrays.
7. Declarations.
8. Expressions.
9. Statements.

C Character Set:

  • The character sets are the building blocks to form basic programming elements in C.
  • Some of the examples of basic programming elements are constants, variables, operators, expressions..etc.,
  • The character sets used in C programming are:
    1. Uppercase letters A-Z.
    2. Lowercase letters a-z.
    3. Digits 0-9.
    4. special characters (such as + , _ , { , } etc…).
    5. Escape sequences:
    While using some special characters like space, newline, horizontal tab we should represent them as b, n, t respectively. These character sets are called escape sequences.

Identifiers :

  • The various program elements such as variables, functions and arrays are called as identifiers.
  • The name given to the identifier contain enough characters that its meaning is readily apparent.

Rules to be an identifier:

1. Identifiers can be letters or digits of any order but the first character must be a letter.
2. Both upper-case and lower-case letters can be used. But mostly the lower-case is preferred.
3. The upper and lower case letters are not equivalent.i.e., an upper-case letter  and lower case letters are not interchangeable. i.e.,  case-sensitive.
4. The underscore, “_” can be used as a letter. It is often used in the middle of an identifier. It can also be used in the beginning of the identifier.
5. An identifier can be long (more than 8 characters). But some C conventions can accept only first 8 characters of an identifier.
Example identifiers:
names, x, y,  x10, _temp…etc.

keywords:

  • Certain reserved words that have standard and a predefined meaning in C are called keywords.
  • All the keywords must be in lowercase letters.
  • These keywords can used only for certain intended purpose.
  • These keywords cannot be used as programmer defined identifiers.
  • Some of the keywords for you reference:
    Example: auto, break, int, char, if…etc.,
  • These keywords may slightly vary depending upon the compilers.
  • We can use same names in uppercase as identifiers and in lowercase as keywords.
  • There are some reference manuals are available to have a complete list of keywords used by different compilers.

Consider the following example program and try to differentiate identifiers and keywords:

Output:

Enter values of a and b to add:
3 4
sum of 3 and 4 is 7.

Identifiers used in the above program are:
a, b, c, %d, &a, &b, &c

Keywords used in the above program are:
int, printf, scanf, void, main.

Thanks for reading… Please leave your comments below…

You may also like...

Leave a Reply

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