Learning C Language
Dr. D. R. Gholkar
M.Com, MCM, MBA (Finance)
Ph. D (Entrepreneurship Development)
Mo. N0. 9011355151
Deep C
HISTORY OF PROGRAMMING LANGUAGE
 Machine Language
 Assembly Language
 High Level Language
Language Translators
Compiler
Interpreter
INTRODUCTION TO C LANGUAGE
 What is C ?
 C is Programming Language
 C is a General Purpose Programming language
 C is a Procedure Oriented Language
 C is a Structured Language
 C is a Middle Level Language
 C is a Superset Language of all the Programming
Language
HISTORY OF C LANGUAGE
ALGOL 60
(BY AN INTERNATIONAL COMMITTEE, 1960) IT WAS TOO ABSTRACT &
TOO GENERAL
CPL
(BY CAMBRIDGE & LONDON UNIVERSITY,
1963)
DROWBACKS/SHORTCOMMINGS
BCPL
HARD TO LEARN & DIFFICULT
TO IMPLEMENT
B
(MARTIN RICHARDS AT
CAMBRIDGEUNIVERSITY, 1967 )
(KEN THOMSON AT BELL LABS, 1970)
TOO LESS POWERFULL &
TOO LESS SPECIFIC
MACHINE DEPENDENT &
TYPELESS
C
(DENNIS RITCHE AT BELL LABS, 1972
IMPORTANCE OF C LANGUAGE
 FLEXIBILITY
 POWERFULL
 SMALL SIZE
 MODULAR DESIGN
 PORTABILITY
 HIGH LEVEL STRUCTURED LANGUAGE FEATURES
 LOW LEVEL FEATURES
 USE OF POINTERS
 EASY TO LEARN
 EASY TO DEBUG
 EFFICIENCY ( EASY TO EXECUTE )
 EASY TO USE
 RELIABLE
 CREATING A SOURCE CODE
 COMPILING THE SOURCE CODE
 LINKING THE SOURCE CODE
 RUNNING THE EXECUTABLE CODE
WRITING & EXECUTING A C PROGRAM
EDITOR
WRITTEN C PROGRAM
PRE
PROCESSOR
COMPILER
PRE-PROSSED CODE
COMPILATION
OBJECT
CODE
LINKER
EXECUTABLE
CODE
Linking
.OBJ
FILE
.EXE
FILE
START
TYPE THE PROGRAM
COMPILER SOURCE CODE
SYNTAX
ERROR
LINK THE PROGRAM
EXECUTE
LOGICAL
ERROR
STOP
WRITTEN
C CODE
EDIT PROGRAMME
LIBRARY +
OBJECT
PROGRAMME
CORRECT
I/O
DATA
SOURCE
PROGRAMME FILE.C
OBJECT
PROGRAMME
NO
NO
YES
FILE.OBJ
EXECUTABLE
CODE
FILE.EXE
Fig: Flowchart of execution of c
programme
STRUCTURE OF C PROGRAMME
DOCUMENTATION SECTION1
LINK SECTION
DEFINATION SECTION
GLOBAL DECLARATION
SECTION
MAIN () SECTION
2
3
4
5
OPTIONAL
COMPULSORY
OPTIONAL
OPTIONAL
COMPULSORY
{
Declarative part
Executable part
}
C TOCKENS
KEYWORDS
OPERATORS
IDENTIFIERS CONSTANTS VARIABLES
PRIMARY/
DERIVED
STRUCTURED
USER
DEFINED
EMPTY
DATA SET
1. Int
2. Flot
3. Char
4. double
1. Array
2. Structure
3. Union
4. pointer
1. enum 1. void
DATA TYPES
Fundamental Data Types
Data Types Description Size ( In Bytes ) Range
Int An integer number 2 bytes -32768 to 32767
Float A single precision
floating point number
4 bytes -2147483648 to
2147483647
Char A single character 1 byte -128 to 127
Double A double precision
floating point number
8 byte 1.7 e-308 to 1.7 e+308
Void Empty data type 0 Valueless
1. ARITHMETIC OPERATORS 5 + - * / %
2. RELATIONAL OPERATORS 6 < > <= >= == !=
3. LOGICAL OPERATORS 3 && || !
4. ASSIGNMENT OPERATORS 1 =
5. INCREMENT & DECREMENT OPERATORS 2++ --
6. CONDITIONAL OPERATORS ? : / if else
7. BITWISE OPERATORS 6 & | << >> ~
8. OTHER OPERATORS 7 , sizeof() typecast() & * [] ()
OPERATORS
1. Null Statement  ; on line
2. Expression Statement  assignment/function call
3. Compound Statement { }
4. Selection Statement  condition check if if else
5. Iteration Statement  Iteration while do while for
6. Jump Statement  go to break continue
7. Labeled Statement  xx
STATEMENT
Def: Computer can take the decision but taking a decision for computer statement is
required.
SELECTION/DECISION MAKING STATEMNET
 If
 If …..else
 Nested if …. Else
 If else ladder
 Switch statement
ITERATIVE / LOOPING STATEMENT
 While Loop
 Do….while Loop
 For Loop
1. While Loop
 Entry controlled loop / top tested loop
 Syntax :
 Initialization;
 While ( Test_condition)
 {
 Body of the while loop;
 }
2. Do….while Loop
 Exit controlled loop / bottom tested loop
 Syntax :
 Initialization;
 Do
 {
 Body of the do loop;
 }
 While (Test_condition);
3. For Loop
 Most powerful, flexible & commonly used Loop
 Top tested
 Syntax :
 For(initialization; test_condition; incr/decr)
 {
 Body of the for loop
 }
Jumping statement
 Break statement : whole program terminated
 Continue statement : that particular stat is terminated
 Goto statement
Array
Definition: Array is the collection of similar type of data elements.
Types of Array
1. One dimensional array
2. Two dimensional array / matrix
3. Multi dimensional array
More than one values can be stored in a variable of a similar type.
Array declaration does following things:
 The name of the array
 The type of the array
 The dimension of the array
 The size of the array
 For ex:
 int a[10];
 int a[2] [2];
 int a[2] [3] [3];
Handling of C character set
 Reading & writing string
 Combining string together - strcat
 Copying one string to another – strcpy
 Comparing string for equality – strcmp
 Calculating length of string – strlen
Def : A string is an array of characters terminated by a special character Null
(‘0’)
1.Combining string together
 /* strcat demo */
 Void main()
 {
 Char str1[ ] = “Bill”;
 Char str2[] = “Gates”;
 Strcat (str1, “ “);
 Strcat (str1, str2);
 Printf(“n%s”, str1);
 }
 Otuput :
 Bill Gates
2. Copying string together :
 Void main()
 {
 Char str1[ ]= “BCA”;
 Char str2[ ]= “BBA”;
 Char str3[ ];
 Strcpy(str3,str1);
 Strcat(str3,str2);
 Printf(%s”,str3);
 Output :
 BCABBA
3.Comparing string together:
 Void main()
 Char city1[ ]= “Bombay”;
 Char city2[ ]= “Osmanabad”;
 Int i,j;
 i=strcmp(city1,city2);
 j=strcmp(city2,city2);
 Printf(“%d”, i);
 Printf(%d”,j);
 }
B=66
O=79
Output:
-13
13
4.Calculating the length of string :
 Void main()
 {
 Int I;
 Char city[]= “Osmanabad”;
 i=strlen(city);
 Printf(“%d”,strlen(city));
 }
 Output:
 9
Def: A structure is a collection of different
types of data types grouped together under
a single name. Each variable within the
structure is called a member. The name
given to the structure is called structure
tag.
Syntax :
 Struct tag
 {
 Member1;
 Member2;
 .
 .
 Membern;
 };
 Struct tag instance;
For Ex:
Struct student
{
Char name[20];
Int roll no;
Int marks;
};
Struct student s;
Instance is the structure variable used to initialize the structure
Def: A UNION is a collection of different
types of data types grouped together under
a single name. Each variable within the
union is called a member. The name given
to the union is called union tag.
Syntax :
 union tag
 {
 Member1;
 Member2;
 .
 .
 Membern;
 };
 union tag instance;
For Ex:
union student
{
Char name[20];
Int roll no;
Int marks;
};
unioin student s;
Instance is the structure variable used to initialize the structure
Pointer
 Pointer is an important part of the c language which
provide a powerful flexible way to manipulate the data.
 Reason for using the pointer:
 1. accessing the variable defined outside of the
function.
 2. more efficient in handling data tables.
 3. reduce the length of the program
 4. reduce the complexity
 5. pointer increase the execution speed.
Def: Pointer is the variable which store the address of the
next variable.
FUNCTION
 A function is named- accessed by name
 A function is independent-perform the task on its
own
 Specific task
 It will return the value to the calling program.
Def : A function is a self-contained block of statement
that perform a specific well defined task and may
return the value to the calling program.
TYPES OF FUNCTION
Library function
User defined function
1. Library function
 1.<stdio.h> = printf() & scanf()
 2.<conio.h> = clrscr() & getch()
 3.<math.c> = pow(), exp() & sqrt()
 4.<graphic.c> = circle(), setcolor() & bar()
LIBRARY FILES FUNCTIONS
2. User Defined Functions
 For ex :
 Main()
 {
 /* call to func1()*/
 Func1();
 ----
 ----
 /* call to func2()*/
 Func2();
 ----
 ----
 }
Func1()
{
-----
func3();
}
Func2()
{
-----
-----
}
Func3()
{
----
----
}
THANK YOU, VERY MUCH
END

C language by Dr. Gholkar D. R.

  • 1.
    Learning C Language Dr.D. R. Gholkar M.Com, MCM, MBA (Finance) Ph. D (Entrepreneurship Development) Mo. N0. 9011355151
  • 2.
  • 3.
    HISTORY OF PROGRAMMINGLANGUAGE  Machine Language  Assembly Language  High Level Language
  • 4.
  • 6.
    INTRODUCTION TO CLANGUAGE  What is C ?  C is Programming Language  C is a General Purpose Programming language  C is a Procedure Oriented Language  C is a Structured Language  C is a Middle Level Language  C is a Superset Language of all the Programming Language
  • 7.
    HISTORY OF CLANGUAGE ALGOL 60 (BY AN INTERNATIONAL COMMITTEE, 1960) IT WAS TOO ABSTRACT & TOO GENERAL CPL (BY CAMBRIDGE & LONDON UNIVERSITY, 1963) DROWBACKS/SHORTCOMMINGS BCPL HARD TO LEARN & DIFFICULT TO IMPLEMENT B (MARTIN RICHARDS AT CAMBRIDGEUNIVERSITY, 1967 ) (KEN THOMSON AT BELL LABS, 1970) TOO LESS POWERFULL & TOO LESS SPECIFIC MACHINE DEPENDENT & TYPELESS C (DENNIS RITCHE AT BELL LABS, 1972
  • 8.
    IMPORTANCE OF CLANGUAGE  FLEXIBILITY  POWERFULL  SMALL SIZE  MODULAR DESIGN  PORTABILITY  HIGH LEVEL STRUCTURED LANGUAGE FEATURES  LOW LEVEL FEATURES  USE OF POINTERS  EASY TO LEARN  EASY TO DEBUG  EFFICIENCY ( EASY TO EXECUTE )  EASY TO USE  RELIABLE
  • 9.
     CREATING ASOURCE CODE  COMPILING THE SOURCE CODE  LINKING THE SOURCE CODE  RUNNING THE EXECUTABLE CODE WRITING & EXECUTING A C PROGRAM EDITOR WRITTEN C PROGRAM PRE PROCESSOR COMPILER PRE-PROSSED CODE COMPILATION OBJECT CODE LINKER EXECUTABLE CODE Linking .OBJ FILE .EXE FILE
  • 10.
    START TYPE THE PROGRAM COMPILERSOURCE CODE SYNTAX ERROR LINK THE PROGRAM EXECUTE LOGICAL ERROR STOP WRITTEN C CODE EDIT PROGRAMME LIBRARY + OBJECT PROGRAMME CORRECT I/O DATA SOURCE PROGRAMME FILE.C OBJECT PROGRAMME NO NO YES FILE.OBJ EXECUTABLE CODE FILE.EXE Fig: Flowchart of execution of c programme
  • 11.
    STRUCTURE OF CPROGRAMME DOCUMENTATION SECTION1 LINK SECTION DEFINATION SECTION GLOBAL DECLARATION SECTION MAIN () SECTION 2 3 4 5 OPTIONAL COMPULSORY OPTIONAL OPTIONAL COMPULSORY { Declarative part Executable part }
  • 12.
  • 13.
    PRIMARY/ DERIVED STRUCTURED USER DEFINED EMPTY DATA SET 1. Int 2.Flot 3. Char 4. double 1. Array 2. Structure 3. Union 4. pointer 1. enum 1. void DATA TYPES
  • 14.
    Fundamental Data Types DataTypes Description Size ( In Bytes ) Range Int An integer number 2 bytes -32768 to 32767 Float A single precision floating point number 4 bytes -2147483648 to 2147483647 Char A single character 1 byte -128 to 127 Double A double precision floating point number 8 byte 1.7 e-308 to 1.7 e+308 Void Empty data type 0 Valueless
  • 15.
    1. ARITHMETIC OPERATORS5 + - * / % 2. RELATIONAL OPERATORS 6 < > <= >= == != 3. LOGICAL OPERATORS 3 && || ! 4. ASSIGNMENT OPERATORS 1 = 5. INCREMENT & DECREMENT OPERATORS 2++ -- 6. CONDITIONAL OPERATORS ? : / if else 7. BITWISE OPERATORS 6 & | << >> ~ 8. OTHER OPERATORS 7 , sizeof() typecast() & * [] () OPERATORS
  • 16.
    1. Null Statement ; on line 2. Expression Statement  assignment/function call 3. Compound Statement { } 4. Selection Statement  condition check if if else 5. Iteration Statement  Iteration while do while for 6. Jump Statement  go to break continue 7. Labeled Statement  xx STATEMENT Def: Computer can take the decision but taking a decision for computer statement is required.
  • 17.
    SELECTION/DECISION MAKING STATEMNET If  If …..else  Nested if …. Else  If else ladder  Switch statement
  • 18.
    ITERATIVE / LOOPINGSTATEMENT  While Loop  Do….while Loop  For Loop
  • 19.
    1. While Loop Entry controlled loop / top tested loop  Syntax :  Initialization;  While ( Test_condition)  {  Body of the while loop;  }
  • 20.
    2. Do….while Loop Exit controlled loop / bottom tested loop  Syntax :  Initialization;  Do  {  Body of the do loop;  }  While (Test_condition);
  • 21.
    3. For Loop Most powerful, flexible & commonly used Loop  Top tested  Syntax :  For(initialization; test_condition; incr/decr)  {  Body of the for loop  }
  • 22.
    Jumping statement  Breakstatement : whole program terminated  Continue statement : that particular stat is terminated  Goto statement
  • 23.
    Array Definition: Array isthe collection of similar type of data elements. Types of Array 1. One dimensional array 2. Two dimensional array / matrix 3. Multi dimensional array More than one values can be stored in a variable of a similar type.
  • 24.
    Array declaration doesfollowing things:  The name of the array  The type of the array  The dimension of the array  The size of the array  For ex:  int a[10];  int a[2] [2];  int a[2] [3] [3];
  • 25.
    Handling of Ccharacter set  Reading & writing string  Combining string together - strcat  Copying one string to another – strcpy  Comparing string for equality – strcmp  Calculating length of string – strlen Def : A string is an array of characters terminated by a special character Null (‘0’)
  • 26.
    1.Combining string together /* strcat demo */  Void main()  {  Char str1[ ] = “Bill”;  Char str2[] = “Gates”;  Strcat (str1, “ “);  Strcat (str1, str2);  Printf(“n%s”, str1);  }  Otuput :  Bill Gates
  • 27.
    2. Copying stringtogether :  Void main()  {  Char str1[ ]= “BCA”;  Char str2[ ]= “BBA”;  Char str3[ ];  Strcpy(str3,str1);  Strcat(str3,str2);  Printf(%s”,str3);  Output :  BCABBA
  • 28.
    3.Comparing string together: Void main()  Char city1[ ]= “Bombay”;  Char city2[ ]= “Osmanabad”;  Int i,j;  i=strcmp(city1,city2);  j=strcmp(city2,city2);  Printf(“%d”, i);  Printf(%d”,j);  } B=66 O=79 Output: -13 13
  • 29.
    4.Calculating the lengthof string :  Void main()  {  Int I;  Char city[]= “Osmanabad”;  i=strlen(city);  Printf(“%d”,strlen(city));  }  Output:  9
  • 30.
    Def: A structureis a collection of different types of data types grouped together under a single name. Each variable within the structure is called a member. The name given to the structure is called structure tag.
  • 31.
    Syntax :  Structtag  {  Member1;  Member2;  .  .  Membern;  };  Struct tag instance; For Ex: Struct student { Char name[20]; Int roll no; Int marks; }; Struct student s; Instance is the structure variable used to initialize the structure
  • 32.
    Def: A UNIONis a collection of different types of data types grouped together under a single name. Each variable within the union is called a member. The name given to the union is called union tag.
  • 33.
    Syntax :  uniontag  {  Member1;  Member2;  .  .  Membern;  };  union tag instance; For Ex: union student { Char name[20]; Int roll no; Int marks; }; unioin student s; Instance is the structure variable used to initialize the structure
  • 34.
    Pointer  Pointer isan important part of the c language which provide a powerful flexible way to manipulate the data.  Reason for using the pointer:  1. accessing the variable defined outside of the function.  2. more efficient in handling data tables.  3. reduce the length of the program  4. reduce the complexity  5. pointer increase the execution speed. Def: Pointer is the variable which store the address of the next variable.
  • 35.
    FUNCTION  A functionis named- accessed by name  A function is independent-perform the task on its own  Specific task  It will return the value to the calling program. Def : A function is a self-contained block of statement that perform a specific well defined task and may return the value to the calling program.
  • 36.
    TYPES OF FUNCTION Libraryfunction User defined function
  • 37.
    1. Library function 1.<stdio.h> = printf() & scanf()  2.<conio.h> = clrscr() & getch()  3.<math.c> = pow(), exp() & sqrt()  4.<graphic.c> = circle(), setcolor() & bar() LIBRARY FILES FUNCTIONS
  • 38.
    2. User DefinedFunctions  For ex :  Main()  {  /* call to func1()*/  Func1();  ----  ----  /* call to func2()*/  Func2();  ----  ----  } Func1() { ----- func3(); } Func2() { ----- ----- } Func3() { ---- ---- }
  • 39.
    THANK YOU, VERYMUCH END