C programing

  • View

  • Download

Embed Size (px)


The E-book is used to students who wants to learn a very basic things in C

Text of C programing

  • Mahira Banu


  • C Programming Tutorial


    Introduction a) History and Usages

    b) Keywords

    c) Identifiers

    d) Variables and Constants

    e) Programming Data Types

    f) Input and Output

    g) Programming Operators

    Decision and Loops a) IfIf else and Nested If else

    b) C Programming Loops

    c) Break and Continue

    d) Switch..case Statement

    e) go to function

    C Functions a) User Defined

    b) Function Recursion

    c) Storage class

    Arrays a) One Dimensional Array

    b) Multi dimensional Array

    Pointers a) Pointers and Function


    Structure and Union a) Union

    Advance Functions in C a.) Enumeration

    b.) Pre-processor

    c.) Library Function

  • Chapter 1


    a.) History

    C is a general purpose, structured programming language. It was

    developed by Dennis Ritchie in 1970 in BELL Lab.

    C Programming is widely used in the Programming world for to

    develop all the advanced applications. This tutorial will use you to learn all the

    basic things in the C Programming.

    Advantages of C:

    Flexible Highly portable Easily extended by the user Faster and Efficient Include number of Built-In-function

    Disadvantages of C:

    No runtime checking It is very executable to fixed bugs

    Application of C:

    Unix completely developed by C Many desktop application developed by C Used to solve mathematical functions It is used to implement different OS.

    Getting Started with C:

    For clear understanding we have to run all the basic concepts, In order

    to run programs we need compiler, compiler will change the source code to

    object code and create executable files. For practical uses we install the basic

    compiler Turbo C/ Advanced compiler Codelite.

    Character Set:

    Character set are the set of alphabets, numbers and some special

    characters which is valid in C.

  • Alphabets:

    Upper Case: A to Z

    Lower Case: a to z


    0 to 9

    Special characters:

    Here some of the special characters used in C

    > < $ ,

    # ^

    } { ( )

    b.) Keyword:

    Keyword is the reserved words used in programming. Each keyword has fixed meaning and it cannot be changed by any users.

    Ex: int money;

    Here int is a keyword.

    Keyword is a case-sensitive and all keyword must be in lower case.

    Keywords in C Language

    auto double int struct

    break else long switch

    case enum register typedef

    char extern return union

    continue for signed void

    do if static while

    default goto sizeof volatile

    const float short unsigned

  • c.) Identifiers:

    Identifiers are name given to C entities such as structures, keywords

    or functions etc Identifiers are unique name given to the C entities which is

    used to identify during the execution.

    Ex: int money;

    Here money is an identifier. Identifier can be in Upper or Lower

    case. It can be start with digits or _.

    d.) Variables and constants:


    Variables are used to store memory location in system memory,

    each variable have unique identifiers.

    Ex: int num;

    num is a variable for integer type.

    Variable didnt contain case sensitive, it may be start with underscore or digits.


    Constants are the term which cannot be changed during the execution of the

    program. It may be classified into following types:

    Character Constant:

    Character constant are the constant which used in single quotation

    around characters. For example: a, I, m, F.

    Floating Point constant:

    It may be numerical form that maybe fractional or exponential


    Ex: -0.012

    1.23 etc

    Integer Constant:

    Integers constant are the numeric constants without any floating

    point/exponential constant or character constant. It classified into 3 types:

    o Octal digits: 0,1,2,3,4,5,6,7

    o Decimal Digits: 0,1,2,3,4,5,6,7,8,9

    o Hexadecimal digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H

  • Escape Sequence

    Sometimes it is necessary to use newline, tab etc so we have to use

    / which is known as Escape sequence.

    Escape Sequences

    Escape Sequences Character

    \b Backspace

    \f Form feed

    \n Newline

    \r Return

    \t Horizontal tab

    \v Vertical tab

    \\ Backslash

    \' Single quotation mark

    \" Double quotation mark

    \? Question mark

    \0 Null character

    String Constant:

    Which are enclosed in double quote mark. For example


    Enumeration Constant:

    Keyword enum is used to declare enumeration. For example

    enum color{yellow,white,green}

    here the variable name is yellow,white,green are the enumeration constant

    which having values 0,1,2 respectively.

    e.) Programming Data types

    Data types in C are classified into 2 types:

    1. Fundamental data types

    2. Derived Data Types

    Syntax for Data types: Data type variable name;

  • Classifications of Fundamental Data types

    Integer Type: Keyword int is used for declaring with integer types

    Floating Types: Keyword float and double are used for declaring the floating


    Character Types: keyword char is used for declaring the variables of character


    Classifications of Derived Data types





    Qualifiers: It is used to alter the meaning of base data types to yield a new data


    f.) Input/output:

    The C Program input and output functions are printf() and scanf()

    Printf() its used to provide output to the users

    Scanf() its used to taken input from the users.

    Examples for I/O function


    Void main();


    int c;

    printf(enter the number c);



    return 0;


    Here printf() is used to display the output .

  • Scanf() is ask the value from the user & denotes that the address of the C and

    value stored in the number.

    Stdio represent standard input output function which is the library function

    #include is used to paste the code from the header when it is required.

    g.) Programming Operators:

    Operators are a symbol which operates on a value or variable. For Example:

    + is an operator which is used for a addition.

    Operators in C programming

    Arithmetic operators(+,-,%,*)

    Increment and Decrement operators(a++,++a,a--,--a)

    Assignment operators(+=,a+=b is equal to a=a+b)

    Relational operators(==,=)

    Logical operators(&&,||)

    Conditional operators (?,: its used to making decision)

    Bitwise operators(&,| etc)

  • Chapter-2

    Decision and loops

    a.) If, Ifelse, Nested Ifelse.

    This Statement is used to execute the programming by one

    time decision i.e. execute one code and ignore one code.

    If Statement

    It executes the statement if the test expression is true.


    if (test expression)


    // statement to be executed when the test expression is true


    If..else Statement

    This statement is used when the programmer is want to execute one

    statement if the test expression is true or executes other expression if the test

    expression is false.


  • if (test expression)


    Statement to be execute when expression is true;




    Statement to be executed when it is false;


    Nested if else statement

    This statement is used when the programmers need more than one


    The nested statement is work by step by step if first statement is true it never

    enter t the 2nd

    statement when it is wrong it will go to the next expression. This

    will used by programmers when they need to check more than one expression.


    if(test expression)


    execute if expression is true; }

  • else if( test expression 1)


    execute when expression 0 is false and 1 is true;


    else if (test expression 2)


    execute when expression