Data Type.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

1 Lecture 7  Fundamental data types in C  Data type conversion:  Automatic  Casting  Character processing  getchar()  putchar()  Macros on ctype.h.
Fungsi Risanuri Hidayat, Ir., M.Sc.. Functions C usually consist of two things: instance variables and functions. All C programs consist of one or more.
Structure of a C program
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Lab 10 rRepresentation And Conversion of Numeric Types l Difference between Numeric Types l Automatic conversion of Data types l Explicit Conversion of.
1 Fundamental Data Types. 2 Declaration All variables must be declared before being used. –Tells the compiler to set aside an appropriate amount of space.
Fundamental data types
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Lecture 2: Topics Bits and Bytes Primitive Types Casting Strings Boolean expressions.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Operator Overloading and Type Conversions
C Tokens Identifiers Keywords Constants Operators Special symbols.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 3: Introduction to C: Input & Output, Assignments, Math functions.
Fundamental Data Types, Operators and Expressions Kernighan/Ritchie: Kelley/Pohl: Chapter 2 Chapter 2, 3.
Data Type. Syntax Rules Recap keywords breakdoubleifsizeofvoid caseelseintstatic..... Identifiers not#me123th scanfprintf _idso_am_igedd007 Constant ‘a’‘+’
CS115 FALL Senem KUMOVA-METİN1 The Fundamental Data Types CHAPTER 3.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
1 Lexical Elements, Operators, and the C System. 2 Outline Characters and Lexical Elements Syntax Rules Comments Keywords Identifiers Constants String.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Sudeshna Sarkar, IIT Kharagpur 1 I/O in C + Misc Lecture –
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Introduction to ‘c’ language
Data types Data types Basic types
Chap. 2. Types, Operators, and Expressions
Tokens in C Keywords Identifiers Constants
Functions, Part 2 of 2 Topics Functions That Return a Value
CS 108 Computing Fundamentals Notes for Thursday, September 14, 2017
C Short Overview Lembit Jürimägi.
I/O in C + Misc Lecture Sudeshna Sarkar, IIT Kharagpur.
Fundamental Data Types
CMSC 104, Section 4 Richard Chang
INTRODUCTION c is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs.
Chapter 2 - Data Types and Storage Classes
Data Type.
Computer Science 210 Computer Organization
Lexical Elements, Operators, and the C Cystem
Conversions of the type of the value of an expression
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Lexical Elements, Operators, and the C Cystem
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
Lectures on Numerical Methods
Variables in C Declaring , Naming, and Using Variables.
Introduction to Programming
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Fundamental Data Types
Programming Language C Language.
Data Type.
Module 2 Variables, Data Types and Arithmetic
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Data Type

Syntax Rules Recap keywords Identifiers Constant String Constants break double if sizeof void case else int static ..... Identifiers not#me 123th scanf printf _id so_am_i gedd007 Constant 12 2.72 ‘a’ ‘+’ String Constants “a string of text” “a”

Operators int a=1, b=2, c=3; int i; i = (a, b, c); /* c */ i = (a += 2, a + b); i = a += 2, a + b;

Fundamental Data Types all variables must be declared before they are used other types (array, pointer, structure, union) are derived from the fundamental data types

Data Types and Sizes sizes are machine dependant float short and int are at least 16 bits long is at least 32 bits short <= int <= long float typically 4 bytes (32bits) double is 8 bytes floating arithmetic is NOT always exact refer <float.h> <limits.h>

Characters assume a single byte for a character even though it is represented as int 256 distinct characters are possible

Character Types ANSI C provides three types of char int char is either one of the followings signed char -128~127 unsigned char 0~255 int 16 bits for small/old computers 32 bit for your computers what if overflow occurs depends on the CPU

Floating Numbers IEEE 754 floating point standard: Single precision: (sign)(significand)*2exp 8 bit exponent (0~127) = (-63~64) 23 bit significand 1 bit sign Double precision: (11, 52, 1)

Data Type Definition typedef typedef char uppercase; typedef int Inches, Feet; uppercase FirstChar; Inches length, width;

sizeof( ) operator returns the number of bytes guaranteed because some sizes are machine dependent guaranteed

getchar( ) and putchar( ) defined in <stdio.h> getchar() reads in a character putchar() writes out a character to/from the standard device

Mathematical Functions #include <math.h> #include <stdio.h> int main(void) { double x; printf("\n%s\n%s\n%s\n\n", "The square root of x and x raised", "to the x power will be computed.", "---"); while (1) { /* do it forever */ printf("Input x: "); scanf("%lf", &x); if (x >= 0.0) printf("\n %15s %22.15e \n %15s %22.15e \n %15s %22.15e \n\n", "x = ", x, "sqrt(x) = ", sqrt(x), "pow(x, x) = ", pow(x, x)); else printf("\n Sorry, your number must be nonnegative.\n\n"); } return 0; many mathematical functions are available from the math library include <math.h> link with the library “ gcc –lm code.c”

Arithmetic Conversions Some data types are converted automatically in an expression and on an assignment int op int short op short => int int op float => float Some rules small one is converted to a large one float op long long op double int op float

Automatic Conversions on an assignment d = i; i is converted to the type of d

Cast you can force explicit conversions (double) i (long) (‘A’ + 1.0) f = (float) ( (int) d + 1) * (double)(x = 77));