Lecture02(Constants, variable & data types) June 15, 2010 Today's Outline Data Types C Tokens Keywords & Identifiers Constants Variables The four C scopes Type Qualifiers Storage Class Specifiers Md. Mahbub Alam Structured Programming Language 1 (CSE-1121)
C Tokens Token: Smallest individual units in C program are known as token. e.g. Keywords - int, break, for, struct etc Identifiers - count, amount etc Constants - 10, 5.5, -7.5 etc Strings - “DUET”, “1st Year” etc Operators - +, -, *, / Special Symbols - [] {} etc Md. Mahbub Alam Structured Programming Language 2 (CSE-1121)
C Data Types All C compiler supports 5 foundational data types, namely integer(int), floating-point(float), double precision floating-point (double), character(char), & void. Data Type Size (bits) char 8 int 16 or 32 float 32 double 64 void type either explicitly declares a function as returning no value or creates generic pointers. Md. Mahbub Alam Structured Programming Language 3 (CSE-1121)
C Keywords All keywords have fixed meanings & these meanings can not be changed. Serve as basic building blocks for program statements. All keyword must be written in lowercase letters. • Flow control (6) - if, else, return, switch, case, default • Loops (5) - for, do, while, break, continue • Common types (5) - int, float, double, char, void • Structures (3) - struct, typedef, union • Counting and sizing things (2) - enum, sizeof • Rare but still useful types (7) - extern, signed,unsigned, long, short, static, const • Evil keywords which we avoid (1) - goto • Others (3) - auto, register, volatile Md. Mahbub Alam Structured Programming Language 4 (CSE-1121)
C Identifiers In C, the names of variables, functions, labels & various other user- defined items are called identifiers. Rules for identifiers: • First character must be an alphabet or underscore and subsequent characters must be either letter, digits, or underscore. • Only 31 characters are significant. • Can not be the same as a C keywords & should not have the same name as functions that are in C library. • Must not contain white space. Md. Mahbub Alam Structured Programming Language 5 (CSE-1121)
Variables A variable is a named location in memory that is used to hold a value that can be modified by the program. All variable must be declared before they can be used. Format: type varable_name; e.g. int count; Variable name must be meaningful to reflect its function or nature. Variable initializations Format: type variable_name = constant; Where variables to be declared: - Inside function (local variables) - In the definition of function parameters (Formal parameters) - Outside of all functions (global variables) Md. Mahbub Alam Structured Programming Language 6 (CSE-1121)
Constants Constants refers to fixed values that do not change during program execution. Constants can be of any type of the basic types. Constants are also called literals. int 10, 135, -23 Example: long int 5678349L unisigned int 580U unisigned long int 9845464UL float 120.25f long double 1020.75L character constants ‘D’ string “DUET” HEX 0x80 Octal 016 Md. Mahbub Alam Structured Programming Language 7 (CSE-1121)
Backslash Character Constants Backslash character constants are used in output functions. Also known as escape sequence Code Meaning b Backspace n New line f Form feed r Carriage return t Horizontal tab v Vertical tab ” Double quote ’ Single quote Backslash a Alert ? Question mark 0 Null Md. Mahbub Alam Structured Programming Language 8 (CSE-1121)
Any Question? Md. Mahbub Alam Structured Programming Language 9 (CSE-1121)
Thank You All Md. Mahbub Alam Structured Programming Language 10 (CSE-1121)

Lecture02(constants, variable & data types)

  • 1.
    Lecture02(Constants, variable &data types) June 15, 2010 Today's Outline Data Types C Tokens Keywords & Identifiers Constants Variables The four C scopes Type Qualifiers Storage Class Specifiers Md. Mahbub Alam Structured Programming Language 1 (CSE-1121)
  • 2.
    C Tokens Token: Smallestindividual units in C program are known as token. e.g. Keywords - int, break, for, struct etc Identifiers - count, amount etc Constants - 10, 5.5, -7.5 etc Strings - “DUET”, “1st Year” etc Operators - +, -, *, / Special Symbols - [] {} etc Md. Mahbub Alam Structured Programming Language 2 (CSE-1121)
  • 3.
    C Data Types All C compiler supports 5 foundational data types, namely integer(int), floating-point(float), double precision floating-point (double), character(char), & void. Data Type Size (bits) char 8 int 16 or 32 float 32 double 64 void type either explicitly declares a function as returning no value or creates generic pointers. Md. Mahbub Alam Structured Programming Language 3 (CSE-1121)
  • 4.
    C Keywords All keywords have fixed meanings & these meanings can not be changed. Serve as basic building blocks for program statements. All keyword must be written in lowercase letters. • Flow control (6) - if, else, return, switch, case, default • Loops (5) - for, do, while, break, continue • Common types (5) - int, float, double, char, void • Structures (3) - struct, typedef, union • Counting and sizing things (2) - enum, sizeof • Rare but still useful types (7) - extern, signed,unsigned, long, short, static, const • Evil keywords which we avoid (1) - goto • Others (3) - auto, register, volatile Md. Mahbub Alam Structured Programming Language 4 (CSE-1121)
  • 5.
    C Identifiers InC, the names of variables, functions, labels & various other user- defined items are called identifiers. Rules for identifiers: • First character must be an alphabet or underscore and subsequent characters must be either letter, digits, or underscore. • Only 31 characters are significant. • Can not be the same as a C keywords & should not have the same name as functions that are in C library. • Must not contain white space. Md. Mahbub Alam Structured Programming Language 5 (CSE-1121)
  • 6.
    Variables Avariable is a named location in memory that is used to hold a value that can be modified by the program. All variable must be declared before they can be used. Format: type varable_name; e.g. int count; Variable name must be meaningful to reflect its function or nature. Variable initializations Format: type variable_name = constant; Where variables to be declared: - Inside function (local variables) - In the definition of function parameters (Formal parameters) - Outside of all functions (global variables) Md. Mahbub Alam Structured Programming Language 6 (CSE-1121)
  • 7.
    Constants Constantsrefers to fixed values that do not change during program execution. Constants can be of any type of the basic types. Constants are also called literals. int 10, 135, -23 Example: long int 5678349L unisigned int 580U unisigned long int 9845464UL float 120.25f long double 1020.75L character constants ‘D’ string “DUET” HEX 0x80 Octal 016 Md. Mahbub Alam Structured Programming Language 7 (CSE-1121)
  • 8.
    Backslash Character Constants Backslashcharacter constants are used in output functions. Also known as escape sequence Code Meaning b Backspace n New line f Form feed r Carriage return t Horizontal tab v Vertical tab ” Double quote ’ Single quote Backslash a Alert ? Question mark 0 Null Md. Mahbub Alam Structured Programming Language 8 (CSE-1121)
  • 9.
    Any Question? Md. MahbubAlam Structured Programming Language 9 (CSE-1121)
  • 10.
    Thank You All Md.Mahbub Alam Structured Programming Language 10 (CSE-1121)