Introduction to C Programming Md. Imran Hossain Showrov (showrovsworld@gmail.com) 6 1
Outline  The C Character Set  Identifiers  Keywords  Data Types  Variables  Expressions  Statements  Declarations
Objective  This lecture will cover the basic elements used to construct simple C Statements.These elements include the C character set, identifiers and keywords, data types, constants, variables etc.
The C Character Set  C uses  The upper case letters (A to Z)  The lower case letters (a to z)  Certain special characters  The Standard requires that an alphabet of 96 symbols is available for C as follows
Writing First Program of C Format of main() function
Writing First Program of C (cont..) #include <stdio.h> main() { printf(“Welcome to C programmingn”); } Output:
Writing First Program of C (cont..)  First line of this program uses # as a compiler directive.  Second line uses a special word main, which denotes the starting point for execution of the program.All programs start their execution from main.  { refers start and } refers end of the main.  printf is an output statement used to display any message on the screen.  n represents new line.
Identifiers  Identifiers are names that are given to various program elements such as variables, functions and arrays.  Identifiers consists of letters, digits and underscore character (_), in any order, But the first character must be a letter.
Identifiers (cont..)  The following names are valid identifiers: x y12 sun_1 _temperature names area tax_rate TABLE  The following names are not valid identifiers: 4th The first character must be a letter “x” Illegal characters (“) order-no Illegal character (-) error flag Illegal character (blank space)
Keywords  Keywords are reserve words that have standard, predefined meaning un C.  It can only be used for their intended purpose.  It cannot be used as programmer-defined identifiers.
Keywords (cont..)
Data Types  Data types are declarations for memory locations or variables that determine the characteristics of the data that may be stored and the methods (operations) of processing that are permitted involving them.  C supports several data types
Data Types (cont..) Data Type Description Example int integer quantity 12, 96 etc. char single character A, b, 0 etc. float floating-point number 12.666428 double double- precision floating point number 12.6664287277 62776
Variables  A variable is an identifier that is used to represent some specific type of information within the designated portion of the program.  Example: – int a, b, c; – char d; – a = 3; – b= 5; – c = a + b;
Expressions  An expression represents a single data item, such as a number or a character.  The expression may consist of a single entry, such as a constant.  Expression can also represent logical conditions that are either true or false.  Example: ● a + b ● x = y ● x <= y ● x == y ● c = a + b ● ++i
Statements  A statement causes the computer to carry out some action.  There are three different classes of statements in C 1. Expression statement 2. Compound statement 3. Control statement  Example: a = 3; c = a + b; ++i;
Declarations  A declaration associates a group of variables with a specific data types.  All variables must be declared before they can appear in executable statements.  A declaration of a data type, followed by one or more variable names, ending with semicolon.  Example:  int a, b, c;  float root1, root2;  char flag, text[80];
Example 1 #include<stdio.h> main() { int sum, a =10, b = 20; sum = a+b; printf(“%dn”, sum); }
Example 1 (cont..) Inside the main function:  Identifiers:  Here, sum, a, b is an identifier.  Keywords:  Here, int is a keyword  Data Type:  Data type of sum, a, b is int  Variable:  Here, sum, a, b are variables.  Expression:  sum = a + b ;
Lecture 6- Intorduction to C Programming

Lecture 6- Intorduction to C Programming

  • 1.
    Introduction to CProgramming Md. Imran Hossain Showrov (showrovsworld@gmail.com) 6 1
  • 2.
    Outline  The CCharacter Set  Identifiers  Keywords  Data Types  Variables  Expressions  Statements  Declarations
  • 3.
    Objective  This lecturewill cover the basic elements used to construct simple C Statements.These elements include the C character set, identifiers and keywords, data types, constants, variables etc.
  • 4.
    The C CharacterSet  C uses  The upper case letters (A to Z)  The lower case letters (a to z)  Certain special characters  The Standard requires that an alphabet of 96 symbols is available for C as follows
  • 5.
    Writing First Programof C Format of main() function
  • 6.
    Writing First Programof C (cont..) #include <stdio.h> main() { printf(“Welcome to C programmingn”); } Output:
  • 7.
    Writing First Programof C (cont..)  First line of this program uses # as a compiler directive.  Second line uses a special word main, which denotes the starting point for execution of the program.All programs start their execution from main.  { refers start and } refers end of the main.  printf is an output statement used to display any message on the screen.  n represents new line.
  • 8.
    Identifiers  Identifiers arenames that are given to various program elements such as variables, functions and arrays.  Identifiers consists of letters, digits and underscore character (_), in any order, But the first character must be a letter.
  • 9.
    Identifiers (cont..)  Thefollowing names are valid identifiers: x y12 sun_1 _temperature names area tax_rate TABLE  The following names are not valid identifiers: 4th The first character must be a letter “x” Illegal characters (“) order-no Illegal character (-) error flag Illegal character (blank space)
  • 10.
    Keywords  Keywords arereserve words that have standard, predefined meaning un C.  It can only be used for their intended purpose.  It cannot be used as programmer-defined identifiers.
  • 11.
  • 12.
    Data Types  Datatypes are declarations for memory locations or variables that determine the characteristics of the data that may be stored and the methods (operations) of processing that are permitted involving them.  C supports several data types
  • 13.
    Data Types (cont..) DataType Description Example int integer quantity 12, 96 etc. char single character A, b, 0 etc. float floating-point number 12.666428 double double- precision floating point number 12.6664287277 62776
  • 14.
    Variables  A variableis an identifier that is used to represent some specific type of information within the designated portion of the program.  Example: – int a, b, c; – char d; – a = 3; – b= 5; – c = a + b;
  • 15.
    Expressions  An expressionrepresents a single data item, such as a number or a character.  The expression may consist of a single entry, such as a constant.  Expression can also represent logical conditions that are either true or false.  Example: ● a + b ● x = y ● x <= y ● x == y ● c = a + b ● ++i
  • 16.
    Statements  A statementcauses the computer to carry out some action.  There are three different classes of statements in C 1. Expression statement 2. Compound statement 3. Control statement  Example: a = 3; c = a + b; ++i;
  • 17.
    Declarations  A declarationassociates a group of variables with a specific data types.  All variables must be declared before they can appear in executable statements.  A declaration of a data type, followed by one or more variable names, ending with semicolon.  Example:  int a, b, c;  float root1, root2;  char flag, text[80];
  • 18.
    Example 1 #include<stdio.h> main() { int sum,a =10, b = 20; sum = a+b; printf(“%dn”, sum); }
  • 19.
    Example 1 (cont..) Insidethe main function:  Identifiers:  Here, sum, a, b is an identifier.  Keywords:  Here, int is a keyword  Data Type:  Data type of sum, a, b is int  Variable:  Here, sum, a, b are variables.  Expression:  sum = a + b ;