Fundamentals of C programming

Before we dive deep inside C programming there are few thing that must be known prior.


Tokens are the smallest individual elements of a program. Tokens are the basic building blocks of any program.
For example let’s consider this English paragraph

“ Programming in C is really very interesting! I am programming since I was 14. ”

The above paragraph is made of several basic fundamentals things. Can you figure out all those fundamentals things?
Actually the paragraph contains
13 words
2 digits
13 blank spaces
2 special character (Exclamation mark and full stop)
These are the basic building blocks of any English paragraph. Likewise five fundamental things are used to construct any simple or complex program that are keywords, identifiers, operators, separators, literals.


Keywords are the reserved words whose meaning is pre-defined by the programming language specification. They convey some special meaning in the programming.
Let’s take an example of C keyword: int in C is used to declare an integer type variable. C has total 32 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


In programming we need some data to work upon, since program without data is worthless. And if we have defined some data in memory then there must be some easiest way to access them later.
As the name sounds Identifier might be used for identifying something. Yes you are right, identifiers are used for identifying various programming elements (they might be some variables, or some function or any other programming element). Or in simple words Identifiers are the name given to various programming element.

There are some rules that must be followed by an identifier:

  • It must not be a keyword.
  • It can contain alphabets a-z A-Z, digits 0-9, and underscore _ symbol.
  • It must not contain any special character other than_.
  • It must begin with an alphabet or underscore _ symbol.

Examples of some valid identifiers: num, num1, _num1, first_name, _name_
Examples of some invalid identifiers: 1num, first name, email@id, name.


Operators are symbols given to any mathematical or logical operation. C language provides a rich set of operators. There are basically seven types of operators in C:
  • Arithmetic operator + - * / %
  • Assignment operator =
  • Relational operator > < >= <= == !=
  • Logical operator && || !
  • Bitwise operator >> << & | ^ ~
  • Increment/Decrement operator ++ --
  • Conditional/Ternary operator ?:
  • Miscellaneous operator sizeof()


Separators are used for separating various programming element from one another. Separators in programming are as vital as they are in English paragraphs, as I don’t think anyone could ever read an English sentence clearly without separator (Spaces) and punctuation marks. Various types of separators used in C programming are:

. , : ; ( ) { } [ ] White spaces (Space, \t, \n)
Amongst all semicolon ; is the most important one as you will find everywhere in all C programs. Semicolon ; is used to terminate any C statement and is also used for separating one statement from another.


In programming we often need some values that do not change throughout the program called constants. These constant values are also referred as Literals. There are basically four types of literals in C:
  1. Integer literal

    Integer constants are called as integer literal. In C we can define an integer literal in various types:
    22 (Decimal value)
    22u (Unsigned decimal value)
    22L (Long decimal value)
    22uL (Unsigned long decimal value)

    07 (Signed Octal value)
    07u (Unsigned octal value)
    07l (Signed long Octal value)
    07ul (Unsigned long octal value)

    0xf (Signed hexadecimal value)
    0xfl (Signed hexadecimal long value)
    0xfu (Unsigned hexadecimal value)
    0xful (Unsigned hexadecimal long value)

    For defining any Octal constant prefix the constant with 0 and followed by octal value.
    For defining any Hexadecimal constant prefix the constant with 0x followed by hexadecimal value.
    For defining any unsigned value suffix the value with u or U.
    For defining any long value suffix the value with l or L.
    For defining any unsigned long value suffix the value with ul, uL, Ul or UL.

  2. Float literal

    Float constants are called as float literal. Float literal are used to define any fractional value. In C we can define float literal in various ways:

  3. Character literal

    In C any character constant is defined within single quotes ‘ ‘. A character literal can be of any type it can be an ASCII character, Escape sequence character or Unicode character constant. Valid examples of C character literals are:
    ‘A’ (ASCII character constant) View all ASCII character codes
    ‘\t’ (Escape sequence character constant) View all Escape sequence character
    ‘\u0B31’ (Unicode character constant)
  4. String literal

    String is a sequence of characters. In C we define a string constant inside double quote “ “. Some valid examples of string constants in C are:
    “Hello, World!”
    “I love programming\n”


C character set defines the valid set of alphabets, digits and special characters that are allowed in C. C character set consists of:
Alphabets: a-z A-Z
Digits: 0-9
Special characters: ` ~ ! @ # $ % ^ & * ( ) _ - + = { } [ ] | \ : ; “ ‘ < , > . ? /


C language provides a rich support to add inline documentation of program code to enhance the readability of the program. Comments are used to add short description about the program or code. A C program which is poorly written but well commented can be easily debugged. C language provides two types of comment style:
  • Single line comments

    Single line comments begin with // and everything written after that in the same line will not be compiled by the compiler.

    Example: C program demonstrating Single line comment
    #include <stdio.h>
    //This is a the main function
    int main()
        //This line will print Hello, World on console.
        printf(“Hello, World!”);
        return 0;
  • Multiline comments

    When compared to single line comments multiline comments can span across multiple lines. Multiline comments begin with /* and ends with */ everything between /* */ will not be compiled by the compiler.

    Example: C program demonstrating multiline comment
    #include <stdio.h>
    int main()
        int a = 10, b = 20;
        /* This line computes the sum of a,b and prints on the console */
        printf(“SUM = %d”, a+b);
        return 0;

Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment