Data Structures Unit 02

Similar documents
The Bucharest University of Economic Studies. Data Structures. Associate Professor Mihai DOINEA

The Bucharest University of Economic Studies. Data Structures. Heap Priority Queues Maps and Sets

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

A Fast Review of C Essentials Part I

COMP322 - Introduction to C++

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Low-Level Programming

Lecture 02 C FUNDAMENTALS

Review of the C Programming Language for Principles of Operating Systems

Tokens, Expressions and Control Structures

Fundamentals of Programming

CPSC 3740 Programming Languages University of Lethbridge. Data Types

High Performance Computing in C and C++

BLM2031 Structured Programming. Zeyneb KURT

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

A flow chart is a graphical or symbolic representation of a process.

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

EL6483: Brief Overview of C Programming Language

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Review of the C Programming Language

Introduction to C++ with content from

Ch. 3: The C in C++ - Continued -

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Fundamental of Programming (C)

The New C Standard (Excerpted material)

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

OBJECT ORIENTED PROGRAMMING USING C++

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

EMBEDDED SYSTEMS PROGRAMMING Language Basics

CSE 230 Intermediate Programming in C and C++

Variation of Pointers

.Net Technologies. Components of.net Framework

Chapter-8 DATA TYPES. Introduction. Variable:

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

IV Unit Second Part STRUCTURES

EECS 388 C Introduction. Gary J. Minden August 29, 2016

Computers Programming Course 5. Iulian Năstac

DEPARTMENT OF MATHS, MJ COLLEGE

QUIZ. What is wrong with this code that uses default arguments?

Basic Assembly SYSC-3006

Page 1. Agenda. Programming Languages. C Compilation Process

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

6.096 Introduction to C++ January (IAP) 2009

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Types, Variables, Literals, Constants

Variables. Data Types.

CS Programming In C

Lecture 3: C Programm

UNIT- 3 Introduction to C++

Presented By : Gaurav Juneja

Computer Systems Principles. C Pointers

Programming in C - Part 2

Short Notes of CS201

Code segment Stack segment

Fundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations

Special Topics for Embedded Programming

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Programming in C++ 4. The lexical basis of C++

CS201 - Introduction to Programming Glossary By

Procedures, Parameters, Values and Variables. Steven R. Bagley

C Language, Token, Keywords, Constant, variable

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

VARIABLES AND CONSTANTS

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

CS3157: Advanced Programming. Outline

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

Object-Oriented Programming

Data Types and Variables in C language

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

Module 7 More Data Types and Operators

Introduction to the C Programming Language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Syntax and Variables

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Computer System and programming in C

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

More about BOOLEAN issues

Introduction. Structures, Unions, Bit Manipulations, and Enumerations. Structure. Structure Definitions

Lectures 5-6: Introduction to C

OBJECTIVE QUESTIONS: Choose the correct alternative:

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

OpenCL C. Matt Sellitto Dana Schaa Northeastern University NUCAR

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

Programming. Elementary Concepts

Distributed Real-Time Control Systems. Lecture 17 C++ Programming Intro to C++ Objects and Classes

Transcription:

Data Structures Unit 02 Bucharest University of Economic Studies Memory classes, Bit structures and operators, User data types

Memory classes Define specific types of variables in order to differentiate between: allocation time; the type of memory that they used; the lifespan of a variable; the area of visibility, called the scope;

Declarations and Types Type specifiers: void, char, short, int, long, float, double, signed, unsigned, struct/union, enum Type qualifiers: const and volatile Storage-class specifier: auto, register, static, extern, typedef, declspec

Memory classes Automatic class variables are defined using the auto keyword or implicitly if nothing is specified: { } auto a = 2; int b = 20; //explicit //implicit

Memory classes Automatic class The variables are NOT initialized with implicit values They are automatically updated when entering the scope in which they are defined They keep residual values if they weren t previously initialized They are visible only in the scope where they are defined By exiting the visibility area, the memory assigned to them is freed They have local lifetime

Memory classes Static class variables are defined using the static keyword or implicitly for a certain category of variables like global because they are stored in the data segment: int b; static int a; // initialized implicitly with 0

Memory classes Static class Variables are initialized with 0 or an explicit value 2 types of such variables: internals, defined in the body of a function, externals, defined outside any function, in the global area They are stored in a permanent program area called data segment They keep their values at different calls of a function in which they were defined They have global lifetimes

Memory classes External class variables are used in a different area than the one in which they were defined. They are introduced, not defined, with the extern keyword: int a = 5; extern int b; { } int a = 10; int b = 20; // definition memory allocation // declaration compiler notification printf( Value for local b: %d, and for external b: %d, b,::b);

Memory classes Extern class They are global variables defined in separate compiled files This type of variables has two important moments: definition and declaration They are automatically initialized by compiler and have static meaning Definition is the stage in which the compiler allocates memory Declaration is the stage needed for using the variable after definition by preceding it with the extern keyword

Memory classes Register variables are defined using the register keyword and forces the allocation in one of the processor s registers: { } for(register int b = 0; b<100; b++);

Memory classes Register class They have similar behavior as automatic variables Are stored in one of the processor s registers in limited number The register specifier is only allowed for int, char and pointer data types They can not be dereferenced They have local lifetimes

User defined types Article Bit structure Union Enumeration Synonyms Groups different types of primitive variables Aggregated type which uses compact memory A particular type of article which allows users access at bit level Allows that the same memory region be defined as two or multiple different types of variables Is a list of constant integer variables with given names Are defined by using the typedef specifier

User defined types The article is a collection of heterogeneous data stored in a compact region of memory. It allows users to bring together multiple variables in a single defined type entity. struct name { type member_name; };

User defined types Bits structures allow bit access level; To access data at bit level programmers must: define a structure which maps perfectly on the data which must be accessed; load the pointer to the bit structure with the address of the respective data; processing the bits without altering the meaning and internal representation of data;

User defined types Bit fields: struct name { type field_name : width; int : width; int field_name : width; };

User defined types The declared bit field has the following properties: The type may be int, signed or unsigned; The number of bits that a member can refer is specified by width; If member name is missing, the number of bits specified in the width field can not be referred and accessed; The fields are accessed the same way as in any other structure; The address of fields can t be used;

Bitwise operators & ^ ~ >> << AND OR OR exclusive - XOR One complement (flips bit value) Right shifting Left shifting

Bitwise operators unsigned char x x=7 x=x<<1 x=x<<3 x=x<<2 x=x>>1 x=x>>2 x after operation 0000 0111 00000 1110 0000111 0000 011100 0000 1110 00000 1111 100000 value of x 7 14 112-64 -32-8

Bitwise operators & (AND) 0 1 (OR) 0 1 0 0 0 0 0 1 1 0 1 1 1 1 ^ (XOR) 0 1 0 0 1 1 1 0

Bitwise operators AND OR XOR NOT

Bitwise operators

Bitwise operators

User defined types Union defines an area of memory which at different time execution moments can refer to different objects of different types and lengths; Is a composed data type of different variables that are mutually exclusive / mutual exclusion (mutex)

User defined types All the fields share the same memory region of size equal to the size of the largest member in the structure. union nume_generic { }; tip tip tip nume_variabila_1; nume_variabila_2; nume_variabila_n;

User defined types union tip_uniune { int i; char ch; };

User defined types struct WORDREGS { }; unsigned ax, bx, cx, dx; unsigned si,di; unsigned cflag; unsigned flags; union REGS { struct BYTEREGS h; struct WORDREGS x; }; struct BYTEREGS { }; unsigned char al, ah; unsigned char bl, bh; unsigned char cl, ch; unsigned char dl, dh;

User defined types An enumeration is a set of integer type constants which specifies all the possible values of such a variable. enum name { enumerator [ = initializer]; } variable_list;

User defined types The use of typedef keyword defines a synonym for an existing data type; typedef tip new_name; whereas #define statement can be used to define aliases for values as well; #define TRUE 1 #define FALSE 0

Bitmap structure

Bitmap structure Structure Legend Bitmap Header 14 Bytes area 1 4B, file signature, 4D42h 2 4B, file size, 00000046h 3 4B, reserved area, 00000000h 4 4B, image data offset, 00000036h Bitmap InfoHeader Bitmap Data (pixels) 40 Bytes area Pixels stored in RGB format / 1B per color 5 3B pixel Red color, FF0000h 6 3B pixel Green color, 00FF00h 7 2B padding after full line 8 3B pixel Blue color, 0000FFh 9 3B pixel White color, FFFFFFh 10 2B padding after full line

MP3 structure

References Ion IVAN, Marius POPA, Paul POCATILU, coordonatori Structuri de date, Editura ASE, Bucuresti, 2008, ISBN 978-606-505-031-0 Ion SMEUREANU Programarea in limbajul C/C++, Editura CISON, 2001 Michael MAIN Data Structures & Other Objects Using Java, Editura Pearson, 2012, ISBN: 9780132911504 http://www.acs.ase.ro http://www.itcsolutions.eu