SlideShare a Scribd company logo
ZMZ JANUARY 2012




         PROGRAMMING 1
                   BEB14103

Lecture 1
        1
DATA TYPES
         Topic Outcomes
• The students are able to identify four
  standard types of data in C
• The students are able to declare the
  variables according to the data types
• The students are able to create C
  programs with various of data types

 2
INTRODUCTION
                         Data
                        types

    int         float           char   void

There are four basic data types :
    •   Int
    •   Float
    •   Char
    •   Void

3
INTEGER


• Integer is number without the fraction part
• Support three different sizes (1 byte, 2
  bytes and 4 bytes)
• An integer constant must have at least
  one digit
4
CONT..
• It must not have a decimal point
• It can be either positive or negative
• If no sign precedes an integer
  constant it is assumed to be positive
• No commas or blanks are allowed
  within an integer constant
• Examples :

    426   +782   -8000   -7605
5
CHAR
• The letters of the alphabet
• Most computers use the American Standard
  Code for Information Interchange (ASCII)
• The maximum length of a character constant
  can be 1 character
• Examples :
  • 'A'
  • 'I'
  • '5'
  • '='

    6
FLOAT


•       Number with a fractional part, such as 43.32
•       Support three different sizes of floating point data types: float,
        double and long double
•       Double provides twice the precision of float
•       Floats typically take up 4 bytes
•       Doubles takes up 8 bytes
•       Long double takes 10 bytes
    7
VOID
•       The void type has no values therefore we cannot
        declare it as variable as we did in case of integer
        and float.
•       The void data type is usually used with function
        to specify its type.
•       Like in in the first C program we declared
        “main()” as void type because it does not return
        any value.

    8
RANGE OF DATA TYPES IN C




9
VARIABLES
•        Variables are named memory
         locations that have a type.
•        Must be declared and defined
•        Declaration is used to name an
         object such as a variable
•        Definitions are used to create the
         object
•        A variable cannot be type void
    10
VARIABLE DECLARATION




11
CONT..
In order to use a variable in our program we must first
declare it

HOW? A declaration statement has the following format:

type variable name;
–type : what kind of data will be stored in that location
  (integer?character? floating point?)
–variable name: what is the name of the variable?
–semi-colon : indicates this is a statement!

int num_students; // declaration
num_students= 22; // initialization
 12
EXAMPLE 2.1
#include <stdio.h>
main()
{
  int num1, num2, sum;
  printf(“Enter one decimal number:”);
  scanf(“%d”, &num1);
  printf(“Enter another decimal number:”);
  scanf(“%d”, &num2);
  sum = num1 + num2;
  printf(“nSum of %d and %d is %d ”, num1, num2, sum);
  return 0;
}
 13
EXAMPLE 2.2
#include <stdio.h>
main()
{
  float area_rectangle, width, length;
  printf(“Enter the length:”);
  scanf(“%f”, &length);
  printf(“Enter the width:”);
  scanf(“%f”, &width);
  area_rectangle = length * width;
  printf(“nArea of the rectangular is %f ”, area_rectangle);
  return 0;
}
 14
EXAMPLE 2.3
#include <stdio.h>
main()
{
     double pi, height, radius, base, volume;
     pi = 3.142;
     printf(“Enter the height the cone:”);
     scanf(“%lf”, &height);
     printf(“Enter the radius of the cone:”);
     scanf(“%lf”, &radius);
     base = pi * radius * radius;
     volume = (1.0/3.0) * base * height;
     printf(“nThe volume of a cone is %f ”, volume);
     return 0;
}

    15
#define
/*You may also associate constant using #define preprocessor directive*/
#include <stdio.h>
#define pi 3.142
main()
{
     double height, radius, base, volume;
     printf(“Enter the height the cone:”);
     scanf(“%lf”, &height);
     printf(“Enter the radius of the cone:”);
     scanf(“%lf”, &radius);
     base = pi * radius * radius;
     volume = (1.0/3.0) * base * height;
     printf(“nThe volume of a cone is %f ”, volume);
     return 0;
}
    16
EXAMPLE 2.4
#include <stdio.h>

main()
{
char Letter;
Letter = 'x';
printf(“nThe letter is %c ”, Letter);
return 0;
}

 17
STANDARD OUTPUT
•   printf Function
    •   prints information to the screen
    •   requires two arguments
        • control string
        • conversion specifier

Example
• double angle = 45.5;
• printf(“Angle = %.2f degrees n”, angle);

Output:
• Angle = 45.50 degrees
STANDARD INPUT
•   scanf Function
    • inputs values from the keyboard
    • required arguments
       • control string
       • memory locations that correspond to
         the specifiers in the control string

Example:

•   double distance;
•   scanf("%lf", &distance);
SUMMARY
•    There are four standard data types can be use in
     C program which are:
     • Integer
     • Float
     • Char
     • Void
•    Everytime you want to use a variable, the
     declaration must be made
•    To associate the variables with the data types,
     you can use standard input and output function

    20
REFERENCE
Hanly, J. R. & Koffman, E. B (2001). C
Program Design for Engineers. Addison
Wesley Longman.

Deitel, P & Deitel H (2008). C How to
Program. Pearson Education Inc.




21

More Related Content

PPT
Constants in C Programming
PPT
C language basics
PDF
Python Programming
PPT
pointer, structure ,union and intro to file handling
PPTX
datatypes and variables in c language
PPT
Basic of c &c++
PPT
Basic concept of c++
Constants in C Programming
C language basics
Python Programming
pointer, structure ,union and intro to file handling
datatypes and variables in c language
Basic of c &c++
Basic concept of c++

What's hot (18)

PPT
Variables in C Programming
PPTX
What is identifier c programming
PPT
Data types and Operators
PPTX
Fundamentals of c programming
PPT
Introduction to C
PPTX
What is c
PDF
2 expressions (ppt-2) in C++
PPS
T02 a firstcprogram
PPTX
Constant and variacles in c
PPTX
Moving Average Filter in C
PPT
02a fundamental c++ types, arithmetic
PPT
Basics of C programming
PDF
SPL 5 | scanf in C
PPTX
Basic Input and Output
PPTX
C language basics
PPTX
C tokens
Variables in C Programming
What is identifier c programming
Data types and Operators
Fundamentals of c programming
Introduction to C
What is c
2 expressions (ppt-2) in C++
T02 a firstcprogram
Constant and variacles in c
Moving Average Filter in C
02a fundamental c++ types, arithmetic
Basics of C programming
SPL 5 | scanf in C
Basic Input and Output
C language basics
C tokens
Ad

Viewers also liked (9)

PDF
构建私有云计算平台的Eucalyptus架构分析
PPT
Pharmalinks Global Regulatory Partners
PPTX
Function creation and function call in c copy
PDF
基于云计算平台的移动Iptv系统设计及负载均衡技术研究
PPT
腾讯大讲堂25 企业级搜索托管平台介绍
PPTX
PDF
Hadoop开发者入门专刊
DOC
Ds program-print
PDF
基于Eucalyptus的教育知识服务体系模型研究(1)
构建私有云计算平台的Eucalyptus架构分析
Pharmalinks Global Regulatory Partners
Function creation and function call in c copy
基于云计算平台的移动Iptv系统设计及负载均衡技术研究
腾讯大讲堂25 企业级搜索托管平台介绍
Hadoop开发者入门专刊
Ds program-print
基于Eucalyptus的教育知识服务体系模型研究(1)
Ad

Similar to Zaridah lecture2 (20)

PPTX
PPTX
COM1407: Variables and Data Types
PPTX
Constant, variables, data types
PPT
C the basic concepts
PDF
Constants Variables Datatypes by Mrs. Sowmya Jyothi
PPTX
Lecture 2
PPTX
Data Type in C Programming
PPTX
Basic of Structered Programming in C psd
PPT
C++ data types
PPTX
2. Variables and Data Types in C++ proramming.pptx
PPTX
Module 1:Introduction
PPTX
Introduction to C language programming.pptx
PPTX
Data-Types-in-C-Programming.Programming.pptxProgramming.pptxpptx
PPT
CONSTANTS, VARIABLES & DATATYPES IN C
PPT
constants, variables and datatypes in C
DOCX
PPTX
TAPASH kumar das its my college pptasjhk
PPTX
Bsc cs i pic u-2 datatypes and variables in c language
PPT
C language ppt is a presentation of how to explain the introduction of a c la...
PPT
THE BASIC CONCEPTS OF C PROGRAMMINGPPT.PPT
COM1407: Variables and Data Types
Constant, variables, data types
C the basic concepts
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Lecture 2
Data Type in C Programming
Basic of Structered Programming in C psd
C++ data types
2. Variables and Data Types in C++ proramming.pptx
Module 1:Introduction
Introduction to C language programming.pptx
Data-Types-in-C-Programming.Programming.pptxProgramming.pptxpptx
CONSTANTS, VARIABLES & DATATYPES IN C
constants, variables and datatypes in C
TAPASH kumar das its my college pptasjhk
Bsc cs i pic u-2 datatypes and variables in c language
C language ppt is a presentation of how to explain the introduction of a c la...
THE BASIC CONCEPTS OF C PROGRAMMINGPPT.PPT

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Understanding_Digital_Forensics_Presentation.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Unlocking AI with Model Context Protocol (MCP)
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Electronic commerce courselecture one. Pdf
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing

Zaridah lecture2

  • 1. ZMZ JANUARY 2012 PROGRAMMING 1 BEB14103 Lecture 1 1
  • 2. DATA TYPES Topic Outcomes • The students are able to identify four standard types of data in C • The students are able to declare the variables according to the data types • The students are able to create C programs with various of data types 2
  • 3. INTRODUCTION Data types int float char void There are four basic data types : • Int • Float • Char • Void 3
  • 4. INTEGER • Integer is number without the fraction part • Support three different sizes (1 byte, 2 bytes and 4 bytes) • An integer constant must have at least one digit 4
  • 5. CONT.. • It must not have a decimal point • It can be either positive or negative • If no sign precedes an integer constant it is assumed to be positive • No commas or blanks are allowed within an integer constant • Examples : 426 +782 -8000 -7605 5
  • 6. CHAR • The letters of the alphabet • Most computers use the American Standard Code for Information Interchange (ASCII) • The maximum length of a character constant can be 1 character • Examples : • 'A' • 'I' • '5' • '=' 6
  • 7. FLOAT • Number with a fractional part, such as 43.32 • Support three different sizes of floating point data types: float, double and long double • Double provides twice the precision of float • Floats typically take up 4 bytes • Doubles takes up 8 bytes • Long double takes 10 bytes 7
  • 8. VOID • The void type has no values therefore we cannot declare it as variable as we did in case of integer and float. • The void data type is usually used with function to specify its type. • Like in in the first C program we declared “main()” as void type because it does not return any value. 8
  • 9. RANGE OF DATA TYPES IN C 9
  • 10. VARIABLES • Variables are named memory locations that have a type. • Must be declared and defined • Declaration is used to name an object such as a variable • Definitions are used to create the object • A variable cannot be type void 10
  • 12. CONT.. In order to use a variable in our program we must first declare it HOW? A declaration statement has the following format: type variable name; –type : what kind of data will be stored in that location (integer?character? floating point?) –variable name: what is the name of the variable? –semi-colon : indicates this is a statement! int num_students; // declaration num_students= 22; // initialization 12
  • 13. EXAMPLE 2.1 #include <stdio.h> main() { int num1, num2, sum; printf(“Enter one decimal number:”); scanf(“%d”, &num1); printf(“Enter another decimal number:”); scanf(“%d”, &num2); sum = num1 + num2; printf(“nSum of %d and %d is %d ”, num1, num2, sum); return 0; } 13
  • 14. EXAMPLE 2.2 #include <stdio.h> main() { float area_rectangle, width, length; printf(“Enter the length:”); scanf(“%f”, &length); printf(“Enter the width:”); scanf(“%f”, &width); area_rectangle = length * width; printf(“nArea of the rectangular is %f ”, area_rectangle); return 0; } 14
  • 15. EXAMPLE 2.3 #include <stdio.h> main() { double pi, height, radius, base, volume; pi = 3.142; printf(“Enter the height the cone:”); scanf(“%lf”, &height); printf(“Enter the radius of the cone:”); scanf(“%lf”, &radius); base = pi * radius * radius; volume = (1.0/3.0) * base * height; printf(“nThe volume of a cone is %f ”, volume); return 0; } 15
  • 16. #define /*You may also associate constant using #define preprocessor directive*/ #include <stdio.h> #define pi 3.142 main() { double height, radius, base, volume; printf(“Enter the height the cone:”); scanf(“%lf”, &height); printf(“Enter the radius of the cone:”); scanf(“%lf”, &radius); base = pi * radius * radius; volume = (1.0/3.0) * base * height; printf(“nThe volume of a cone is %f ”, volume); return 0; } 16
  • 17. EXAMPLE 2.4 #include <stdio.h> main() { char Letter; Letter = 'x'; printf(“nThe letter is %c ”, Letter); return 0; } 17
  • 18. STANDARD OUTPUT • printf Function • prints information to the screen • requires two arguments • control string • conversion specifier Example • double angle = 45.5; • printf(“Angle = %.2f degrees n”, angle); Output: • Angle = 45.50 degrees
  • 19. STANDARD INPUT • scanf Function • inputs values from the keyboard • required arguments • control string • memory locations that correspond to the specifiers in the control string Example: • double distance; • scanf("%lf", &distance);
  • 20. SUMMARY • There are four standard data types can be use in C program which are: • Integer • Float • Char • Void • Everytime you want to use a variable, the declaration must be made • To associate the variables with the data types, you can use standard input and output function 20
  • 21. REFERENCE Hanly, J. R. & Koffman, E. B (2001). C Program Design for Engineers. Addison Wesley Longman. Deitel, P & Deitel H (2008). C How to Program. Pearson Education Inc. 21