KEMBAR78
Introduction to C programming | PPTX
INTRODUCTION TO C PROGRAMMING
• C language :
 Is system programming language.
 Is procedure-oriented programming language.
 Is also called mid level programming language.
 was developed in 1972 by Dennis Ritchie at bell laboratories of
AT&T(American Telephone & Telegraph), located in U.S.A.
 was developed to be used in UNIX Operating system.
FEATURES
• Simple
• Machine Independent or Portable
• Mid-level programming language
• structured programming language
• Rich Library
• Memory Management
• Fast Speed
• Pointers
• Recursion
• Extensible
FIRST PROGRAM OF LANGUAGE
PROGRAM :
#include <stdio.h>
#include <conio.h>
void main()
{
printf("Hello World");
getch();
}
OUTPUT :
Hello World
DESCRIBING THE PROGRAM
• #include <stdio.h> includes the standard input output library
functions. The printf() function is defined in stdio.h
• #include <conio.h> includes the console input output library
functions. The getch() function is defined in conio.h file
• void main()
The main() function is the entry point of every program in C
language. The void keyword specifies that it returns no value
• printf()
The printf() function is used to print data on the console
• getch()
The getch() function asks for a single character. Until you press any
key, it blocks the screen
INPUT OUTPUT FUNCTION
• There are two input output function of c language.
 printf() is used for output.
 It prints the given statement to the console.
 Syntax of printf() is given below:
printf(“format string”,arguments_list);
 Sample Format strings : %d(integer), %c(character), %s(string), %f(float) etc.
 scanf() is used for input.
 It reads the input data from console.
 Syntax of scanf() is given below:
 scanf(“format string”,argument_list);
DATA TYPES & KEYWORDS
• 4 types of data types
• A keyword is a reserved word. You cannot use it as a variable name,
constant name etc.
OPERATORS
• There are following types of operators to perform different
types of operations in C language.
 Arithmetic Operators
 Relational Operators
 Shift Operators
 Logical Operators
 Bitwise Operators
 Ternary or Conditional Operators
 Assignment Operator
 Misc Operator
CONTROL STATEMENTS
• if-else
 If statement
 If-else statement
 If else-if ladder
 Nested if
• switch
• loops
• do-while loop
• while loop
• for loop
• break
• continue
IF-ELSE IN C
SWITCH IN C
switch(expression) {
case constant-expression :
statement(s);
break; /* optional */
case constant-expression :
statement(s);
break; /* optional */
default : /* Optional */
statement(s);
}
LOOPS IN C
• Loops are used to execute a block of code or a part of program of
the program several times.
• Types of loops in C language:-
 do while
 It is better if you have to execute the code at least once
 while
 It is better if number of iteration is not known by the user.
 for
 It is good if number of iteration is known by the user.
CONTROL STATEMENTS continued…
• BREAK is used to break the execution of loop (while, do while and for) and
switch case.
• CONTINUE is used to continue the execution of loop (while, do while and
for). It is used with if condition within the loop.
FUNCTIONS IN C
• To perform any task, we can create function. A function can be
called many times. It provides modularity and code reusability.
• Advantage of function:-
 Code Reusability
 Code optimization
CALL BY VALUE
• In call by value, value being passed to the function is locally stored by the
function parameter in stack memory location. If you change the value of
function parameter, it is changed for the current function only. It will not
change the value of variable inside the caller method such as main().
• Output :
CALL BY REFERENCE
• In call by reference, original value is modified because we pass
reference (address).
• OUTPUT :
RECURSION IN C
• A function that calls itself, and doen't perform any task after
function call, is know as tail recursion. In tail recursion, we
generally call the same function with return statement.
ARRAY IN C
• Array in C language is a collection or group of elements (data). All
the elements of array are homogeneous(similar). It has
contiguous memory location.
• Declaration of array :
 data_type array_name[array_size];
• Types of array:-
 1-D Array
 2-D Array
• Advantage of array :
 Code Optimization
 Easy to traverse data
 Easy to sort data
 Random Access

Introduction to C programming

  • 1.
    INTRODUCTION TO CPROGRAMMING • C language :  Is system programming language.  Is procedure-oriented programming language.  Is also called mid level programming language.  was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T(American Telephone & Telegraph), located in U.S.A.  was developed to be used in UNIX Operating system.
  • 2.
    FEATURES • Simple • MachineIndependent or Portable • Mid-level programming language • structured programming language • Rich Library • Memory Management • Fast Speed • Pointers • Recursion • Extensible
  • 3.
    FIRST PROGRAM OFLANGUAGE PROGRAM : #include <stdio.h> #include <conio.h> void main() { printf("Hello World"); getch(); } OUTPUT : Hello World
  • 4.
    DESCRIBING THE PROGRAM •#include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h • #include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file • void main() The main() function is the entry point of every program in C language. The void keyword specifies that it returns no value • printf() The printf() function is used to print data on the console • getch() The getch() function asks for a single character. Until you press any key, it blocks the screen
  • 5.
    INPUT OUTPUT FUNCTION •There are two input output function of c language.  printf() is used for output.  It prints the given statement to the console.  Syntax of printf() is given below: printf(“format string”,arguments_list);  Sample Format strings : %d(integer), %c(character), %s(string), %f(float) etc.  scanf() is used for input.  It reads the input data from console.  Syntax of scanf() is given below:  scanf(“format string”,argument_list);
  • 6.
    DATA TYPES &KEYWORDS • 4 types of data types • A keyword is a reserved word. You cannot use it as a variable name, constant name etc.
  • 7.
    OPERATORS • There arefollowing types of operators to perform different types of operations in C language.  Arithmetic Operators  Relational Operators  Shift Operators  Logical Operators  Bitwise Operators  Ternary or Conditional Operators  Assignment Operator  Misc Operator
  • 8.
    CONTROL STATEMENTS • if-else If statement  If-else statement  If else-if ladder  Nested if • switch • loops • do-while loop • while loop • for loop • break • continue
  • 9.
  • 10.
    SWITCH IN C switch(expression){ case constant-expression : statement(s); break; /* optional */ case constant-expression : statement(s); break; /* optional */ default : /* Optional */ statement(s); }
  • 11.
    LOOPS IN C •Loops are used to execute a block of code or a part of program of the program several times. • Types of loops in C language:-  do while  It is better if you have to execute the code at least once  while  It is better if number of iteration is not known by the user.  for  It is good if number of iteration is known by the user.
  • 12.
    CONTROL STATEMENTS continued… •BREAK is used to break the execution of loop (while, do while and for) and switch case. • CONTINUE is used to continue the execution of loop (while, do while and for). It is used with if condition within the loop.
  • 13.
    FUNCTIONS IN C •To perform any task, we can create function. A function can be called many times. It provides modularity and code reusability. • Advantage of function:-  Code Reusability  Code optimization
  • 14.
    CALL BY VALUE •In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only. It will not change the value of variable inside the caller method such as main(). • Output :
  • 15.
    CALL BY REFERENCE •In call by reference, original value is modified because we pass reference (address). • OUTPUT :
  • 16.
    RECURSION IN C •A function that calls itself, and doen't perform any task after function call, is know as tail recursion. In tail recursion, we generally call the same function with return statement.
  • 17.
    ARRAY IN C •Array in C language is a collection or group of elements (data). All the elements of array are homogeneous(similar). It has contiguous memory location. • Declaration of array :  data_type array_name[array_size]; • Types of array:-  1-D Array  2-D Array • Advantage of array :  Code Optimization  Easy to traverse data  Easy to sort data  Random Access