Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE240 Lecture 07

CSE240 Lecture 07

Introduction to Programming Languages
Data types in C
(202009)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

January 07, 2017
Tweet

Transcript

  1. jgs CSE 240 Introduction to Programming Languages Lecture 07: Data

    types in C Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. jgs Previously …

  3. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 3 jgs

    Output printf (control sequence, expressions); • The control sequence includes a constant string to be printed, e.g., "Result: ", and control symbols to be used to convert variables from their numeric values that are stored in the computer to printing format. • The expressions is the list of expressions whose values are to be printed out. Each expression is separated by a comma. This is optional. // Java int x = 5; float y = 10.3f; System.out.println("hello " + x + " bye " + y); // C int x = 5; float y = 10.3; printf("hello %d bye %f", x, y);
  4. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 4 jgs

    #include <stdio.h> void main () { int i, n = 5; printf("Hi, please enter an integer: "); // input: scanf (control sequence, &variable1, ... &variablen); // &variable: address of the variable. scanf("%d", &i); // input function if (i > n) n = n + i; else n = n - i; printf("i = %d, n = %d\n", i, n); //output function } Input
  5. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 5 jgs

    Control Statements These that you know, work in the same way § for, while, do/while § if/else, switch But, there are not boolean values. Zero is false and any other number is true. The following program is correct and print “Hello”
  6. jgs Primitive Data Types

  7. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 7 jgs

    Primitive Data Types and Modifiers C defines five basic types § int - integer, a whole number. § float - floating point value i.e., a number with a fractional part. § double - a double-precision floating point value. § char - a single character. § void - valueless special purpose type which we will examine closely in later sections. C++ will add • bool – boolean values Primitive types can be modified using one or more of these modifiers § signed, § unsigned, § short, § long
  8. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 8 jgs

    Type Guaranteed minimum range ³ bits char -127 to 127 or 0 to 255 8 signed char -127 to 127 8 unsigned char 0 to 255 8 int -32,768 to 32,767 16,32 signed int same as int 16,32 unsigned int 0 to 65,535 16,32 short int -32,768 to 32,767 16 signed short int same as short int 16 unsigned short int unsigned int 16 long int ±2,147,483,647 32 signed long int same as long int 32 unsigned long int 0 to 4,294,967,295 32 float 6 decimal digits of precision 32 double 10 decimal digits of precision 64 long double 10 decimal digits of precision 64 bool (C++ only) true/false 1 (8) Basic Data Types and Ranges in C
  9. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 9 jgs

    Type Guaranteed minimum range ³ bits char -127 to 127 or 0 to 255 8 signed char -127 to 127 8 unsigned char 0 to 255 8 int -32,768 to 32,767 16,32 signed int same as int 16,32 unsigned int 0 to 65,535 16,32 short int -32,768 to 32,767 16 signed short int same as short int 16 unsigned short int unsigned int 16 long int ±2,147,483,647 32 signed long int same as long int 32 unsigned long int 0 to 4,294,967,295 32 float 6 decimal digits of precision 32 double 10 decimal digits of precision 64 long double 10 decimal digits of precision 64 bool (C++ only) true/false 1 (8) Basic Data Types and Ranges in C
  10. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 10 jgs

    Basic Data Types and Ranges in C Type Guaranteed minimum range ³ bits char -127 to 127 or 0 to 255 8 signed char -127 to 127 8 unsigned char 0 to 255 8 int -32,768 to 32,767 16 signed int same as int 16 unsigned int 0 to 65,535 16 short int -32,768 to 32,767 16 signed short int same as short int 16 unsigned short int unsigned int 16 long int ±2,147,483,647 32 signed long int same as long int 32 unsigned long int 0 to 4,294,967,295 32 float 6 decimal digits of precision 32 double 10 decimal digits of precision 64 long double 10 decimal digits of precision 64 bool (C++ only) true/false 1 (8) unsigned int x = 65000; int x = 32767;
  11. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 11 jgs

    Type Guaranteed minimum range ³ bits char -127 to 127 or 0 to 255 8 signed char -127 to 127 8 unsigned char 0 to 255 8 int -32,768 to 32,767 16 signed int same as int 16 unsigned int 0 to 65,535 16 short int -32,768 to 32,767 16 signed short int same as short int 16 unsigned short int unsigned int 16 long int ±2,147,483,647 32 signed long int same as long int 32 unsigned long int 0 to 4,294,967,295 32 float 6 decimal digits of precision 32 double 10 decimal digits of precision 64 long double 10 decimal digits of precision 64 bool (C++ only) true/false 1 (8) Basic Data Types and Ranges in C
  12. Javier Gonzalez-Sanchez | CSE240 | Spring 2018 | 12 jgs

    Questions
  13. jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez, Ph.D.

    javiergs@asu.edu Fall 2021 Copyright. These slides can only be used as study material for the class CSE240 at Arizona State University. They cannot be distributed or used for another purpose.