Data Types in C: Understanding Variables and Operations, Slides of Computer Science

An overview of data types in c programming language, including built-in and derived data types, rules for constructing identifiers, and examples of using fundamental and derived data types. Learn about int, char, float, double, pointers, arrays, strings, structures, and more.

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dheeraj
dheeraj ๐Ÿ‡ฎ๐Ÿ‡ณ

5

(4)

101 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Types in C
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Data Types in C: Understanding Variables and Operations and more Slides Computer Science in PDF only on Docsity!

Data Types in C

Data Transformation

  • Programs transform data from one form to another
    • Input data ๏ƒ  Output data
    • Stimulus ๏ƒ  Response
  • Programming languages store and process data in various ways depending on the type of the data; consequently, all data read, processed, or written by a program must have a type
  • Two distinguishing characteristics of a programming language are the data types it supports and the operations on those data types

A Data Type (continued)

  • When the compiler encounters a declaration for a

variable, it sets up a memory location for it

  • An operator used on a variable or variables is legal

only if

  • The operator is defined in that programming language for a variable of that type
  • The variable or variables involved with the operator are of the same or compatible types

Rules for Constructing Identifiers in C

  • Capital letters A-Z, lowercase letters a-z, digits 0- 9, and the underscore character
  • First character must be a letter or underscore
  • Usually only the first 32 characters are significant
  • There can be no embedded blanks
  • Keywords cannot be used as identifiers
  • Identifiers are case sensitive

Identifiers refer to the names of data types, constants, variables, and functions

Fundamental Data Types

  • void โ€“ used to denote the type with no values
  • int โ€“ used to denote an integer type
  • char โ€“ used to denote a character type
  • float, double โ€“ used to denote a floating

point type

  • int *, float *, char * โ€“ used to denote a

pointer type, which is a memory address type

Uses of Fundamental Data Types

int elevationIndicator; char inputSymbol; float totalCost;

int main (void) { double grossProduct; int *temperatureValuePtr;

grossProduct = 4567.89; inputSymbol = 'a';

return (0); } // End main

Uses of Derived Data Types

int elevationTable[20];

char inputSymbols[] = "Hello World";

struct operationsStruct { double heatReading; int temperatureValue; float speedMeter; char actionCode; }; // End struct

struct operationsStruct currentOperations;

Records (Structures)

  • A record permits a programmer to handle a group of variables as one variable
  • The fields (members) of a record can be any built- in or programmer-defined data type
  • A record can have values assigned to and read from it just like the built-in variable types
  • A record can also be passed as an argument to a function and serve as the return value for a function

Basic Operations on Records

currentOperations.speedMeter = 245.6; currentOperations.temperatureValue = 67; currentOperations.actionCode = 'z';

latestReading = currentOperations.heatReading;

statusFactor = currentOperations.speedMeter * currentOperations.temperatureValue;

futureOperations = currentOperations;

printf("Temp: %d Code: %c\n", futureOperations.temperatureValue, futureOperations.actionCode);

๏Š