Fundamentals of C programming

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

Summary


WHAT ARE TOKENS

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

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


Identifier

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:


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

Operators

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:

Separators

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.

Literals

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)

    Note:
    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:
    1.45
    2.490E+002
    2.490e+003

  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

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: ` ~ ! @ # $ % ^ & * ( ) _ - + = { } [ ] | \ : ; “ ‘ < , > . ? /

COMMENTS IN C

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:


Labels: ,