Lecture 18 CIS 208 Wednesday, March 30, 2005. Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Files in C Rohit Khokher.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
1 Lecture 7  Fundamental data types in C  Data type conversion:  Automatic  Casting  Character processing  getchar()  putchar()  Macros on ctype.h.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Structure of a C program
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
Chapter 2 Data Types, Declarations, and Displays
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Windows Programming Lecture 05. Preprocessor Preprocessor Directives Preprocessor directives are instructions for compiler.
Macros. There are three basic phases for C programming. preprocessing, compiling, and linking. C input file is first passed to a preprocessing program.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
C Tutorial Session #2 Type conversions More on looping Common errors Control statements Pointers and Arrays C Pre-processor Makefile Debugging.
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
M.T.Stanhope Oct Title : C++ Basics Bolton Institute - Faculty of Technology (Engineering) 1 C++ Basics u Data types. u Variables and Constants.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Introduction to Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
Weekly C-minar Week 0. Today: Steps of the compile Basic inclusion/syntax rules Low-cost containment Debugging.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
UNIMAP Sem2-07/08EKT120: Computer Programming1 Week 2 – Introduction to Programming.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Secure Coding Rules for C++ Copyright © 2016 Curt Hill
The Machine Model Memory
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
ECE Application Programming
INC 161 , CPE 100 Computer Programming
Chapter 13 - The Preprocessor
Secure Coding Rules for C++ Copyright © Curt Hill
By: Syed Shahrukh Haider
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
C Preprocessor(CPP).
Chapter 2 Variables.
Govt. Polytechnic,Dhangar
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Lecture3.
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
C Programming Language
Primitive Types and Expressions
Unit 3: Variables in Java
EECE.2160 ECE Application Programming
Conditional Compilation
Variables and Constants
Presentation transcript:

Lecture 18 CIS 208 Wednesday, March 30, 2005

Test2 April 15 th : Happy Tax day. Review: Wednesday, the 13 th

bit fields structs that hold only bit indicators like an array of booleans

bit field struct tag { type name1: length; type name2: length;... type nameN: length; }variable_list;

bit field types must be either int, unsigned, or signed. length is the number of bits assigned to that label total size can’t be larger that 1 word

example struct status_type{ unsigned send : 2; //2 bits wide unsigned rec : 3;//3 bits wide unsigned p1 : 1; unsigned p2 : 1; } status ;

accessing once again,. or -> same rules, blah blah blah. status.rec = 4; status.p2 = 1; if (status.p1) {…}

run time errors attempting to give a value outside of range. status.send = 5; status.rec = -1;

can mix and match combine bit fields with other structs struct emp { struct adr address; float pay; unsigned lay_off : 1; unsigned hourly: 1; unsigned deductions: 3; };

restrictions single bits variables must be unsigned. Can’t find address of bit field variable bit field variables can’t be arrayed.

Uses: Limited storage (can store several Booleans in just one byte) some devices only transmit info encoded into bits.

int ungetC(char ch, FILE *stream) returns a character to an input stream. Can’t unget EOF Will be the next character read from stream. returns value equal to ch if successful, else EOF one character pushback is guaranteed. Some compilers will accept more.

example #include void read_word(FILE *fp, char *token) { while (isalpha(*token = getc(fp))) token++; ungetc(fp, *token); } read_word(in, “count/10”)?????

Conditional Compilation Directives Might not want some code compiled. These preprocessor commands tell compiler to skip over section of code. Allow for easy porting.

#if #else #elif #endif #if constant_expression statement sequence #endif if the expression, then the statement sequence is compiled. expression must be constant, no variables. use Macros. Can be nested

#if #else #elif #endif #include #define MAX 10; void main(void) { #if MAX >99 printf(“compiled for array greater than 99\n”); #else printf(“compiled for small array\n”); #endif }

#elif == else if #define US 0 #define ENGLAND 1 #define FRANCE 2 #define ACTIVE_COUNTRY US #if ACTIVE_COUNTRY == US char currency[] = “dollar”; #elif ACTIVE_COUNTRY == ENGLAND char currency[] = “pound”; #else char currency[] = “franc”; #endif

#ifdef #ifndef #ifdef macro_name statement sequence #endif True if macro_name is defined. #ifndef macro_name statement sequence #endif True if macro_name is undefined.

#ifdef may use #else can’t use #elif void main(void){ #ifdef FRED printf(“HI Fred”); #else printf(“hi anyone”); #endif #ifndef RALPH printf(“RALPH not defined”); #endif }

#undef undefined a macro. after command, macro name is useless. can be re-defined anytime afterwards.

#line sets the current line number #include #line 100//reset the line counter void main(void) {//line 100 printf(“%d”,__LINE__); //line 101 } prints out 101.

pre-defined macros __LINE__ :: current line number (int) __FILE__ :: current file name (string) __DATE__ :: date month/day/year (string) __TIME__ :: Time, hour:minute:second (string) __STDC__ :: constant decimal 1

comments /*This is C-Style */ //This is C++ style. //Might not work with all compilers.

C++ Starts on Friday Won’t be on test 2