C Language Introduction


C Language is said to be the mother of programming language, Denis Ritchie is the original inventor of it. He wanted to develop a general purpose Operating System, but no such programming language was there.

Therefore, Dennis Ritchie (1941-2011) has decided to develop general purpose programming language and he invented C language. Later he develop Unix operating system using C language.

Features of C Language

  • Procedural language
  • Structured language
  • Easy to learn (simple)
  • Fast & Efficient
  • Modularity
  • Rich Libraries (inbuilt functions)
  • Easy to extend
  • Machine Independent or portable (unlike assembly)
  • It can handle low-level activities

Few facts about C Language

  • C was invented to write an operating system called UNIX.
  • C is a successor of B language which was introduced around the early 1970s.
  • The language was formalized in 1988 by the American National Standard Institute (ANSI).
  • Today’s C is the most widely used and popular System Programming Language.
  • The UNIX OS was totally written in C.
  • Today’s most popular Linux and RDBMS MySQL have been written in C.

C character set

  • Letters
    • Alphabet : Uppercase A…Z Lowercase a…z
  • Digits
    • All decimal digits: 0…9
  • Special Characters
    • : ; ! ” # % & ‘ ( ) * + , – . / : ; < = > ? [ \ ] ^ _ { | }
  • White Spaces
    • Blank Space, Horizontal tab, Carriage return, New line, form feed

Keywords or Reserved words → 32

    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

C Tokens → smallest unit in a ‘C’ program

  • Keywords
  • Constants
  • Strings
  • Identifiers & Variables
  • Operators

Main Function

  1. Main function -> Starting point of a C program
  2. Pair of parenthesis -> to indicate the function
  3. Open Curley -> Starting of main function (brace)
  4. Close Curley -> Ending of main function (brace)
  5. printf function to generate output
  6. String arguments to printf function for output
  7. Body of main function
main function
main function

What is #Include ?

// syntax
# include <header_file_name.h>

// example
# include <stdio.h>
  • The #include is also known pre-processor directive.
  • It is used to include header files (library functions) to a C program.
  • The #include is the directive that instructs the compiler to find the file <filename.h” (<stdio.h> for example) and include in the current source file.
  • stdio.h means “standard input and output” and “.h” means it is a header file rather than C source file which have “.c” extension.
  • List of Headers files

What is Comment ?

  • Comments provide clearness to the source code allowing others to better understand code.
  • Comments in source code are not executed as part of the program.
  • Comments can be placed anywhere in the program.
  • Single Line Comments
    • Create comments for single line.
    • begins with // (double slash).
  • Multiline Comments
    • Comments are placed within /* and */ character sequences and may span any number of lines.

Single line comments

# include <stdio.h>  // includes the stdio.h file

void main()
    // start of main {
    // body of main

    printf ("www.raviroza.com");    
    // above will output the text
    // end of main with }

Multiline comments

Welcome to the tutorial of C Language 
Author : Ravi R Oza

What is Variable ?

  • Variable is data name that stores a value of a specific type.
  • Each variable has a specific type such as int, chat, float or double.

Data Types in C Language

Data TypeDescriptionMemory
intInteger quantity2 bytes
chatSingle character1 byte
floatFloating point number4 bytes
doubleDouble-precision floating point number8 bytes

Rules for declaring Variables

1Variables name must start with a lowercase later (alphabet) or underscore (_).
2No spaces are allowed in variables names.
3Except underscore (_), no other symbol are allowed in variable names.
4No keywords (reserved words) are allowed as variable names.

Input & Output in C

In C language there library function to perform Input & Output, lets discuss them. printf() function -> output/display text or variables in console screen (monitor). scanf() function -> input/scan values/variables from user using standard input (key board)

Output in C : printf() function

Example :

#include <stdio.h>    
void main()
    int age = 5;
    float weight = 930.25;
    double int_rate = 8.09;
    char gender = 'm'

    // Displays the text to screen
    printf("C Programming");

    // Display/output int variable
    printf("\n\nAge is = %d", age);

    // Display/output float variable
    printf("\nWeight is  = %f\n", weight);

    // Display/output double variable
    printf("\nInterest Rate is = %lf", int_rate);

    // Display/output char variable
    printf("\nGender is = %c", gender);

%d bloggers like this: