Free Essay

Enum, Struct Et Type

In:

Submitted By malikyman
Words 823
Pages 4
Institut de Technologie du Cambodge

Génie Informatique et Communication

Type énuméré, structure et renommage des types

1. Type énuméré
Un type énuméré est un type dont on énumère, c’est‐à‐dire dont on donne la liste effective, les éléments de ce type. Bien entendu cela ne peut concerner que des types correspondants à un ensemble fini d’éléments. La définition d’un type énuméré est très simple : on énumère les éléments de ce type, qui sont des identificateurs, séparés par des virgules et encadrés par des accolades ouvrante et fermante. Par exemple : {lundi, mardi, mercredi, jeudi, vendredi, samedi, dimanche}

Pour définir un tel type, on commence par le mot clé enum, suivi d’un identificateur qui sera le nom du type, suivi de la définition, suivie d’un point‐virgule. Par exemple : enum jour {lundi, mardi, mercredi, jeudi, vendredi, samedi, dimanche};

Pour déclarer d’une variable d’un type énuméré, on commence également par le mot clé enum, suivi du nom du type, suivi du nom de la variable (ou des variables), suivi d’un point‐ virgule. Par exemple : enum jour j;

On ne peut qu’affecter une constante (du type donné) à une variable d’un type énuméré ou comparer une variable du type à une des valeurs du type. Par exemple : j = dimanche ; if (j == lundi) printf("Monday");

Le langage C considère les valeurs des types énumérés comme des constantes entières de type int, les convertissant dans l’ordre dans lequel elles ont été énumérées lors de la déclaration à partir de 0. Ceci permet alors de travailler comme avec des types ordinaux.

2. Structure
Les structures permettent de regrouper des objets (des variables) au sein d'une entité repérée par un seul nom de variable. Les objets contenus dans la structure sont appelés champs de la structure (ou attributs).

2.1 Déclaration d’une structure
Lors de la déclaration de la structure, on indique les champs de la structure, c'est‐à‐dire le type et le nom des variables qui la composent: Préparé par M. VALY Dona

1

Institut de Technologie du Cambodge

Génie Informatique et Communication

struct nom_structure { type_champ1 nom_champ1; type_champ2 nom_champ2; type_champ3 nom_champ3;

type_champN nom_champN;
};






la dernière accolade doit être suivie d'un point‐virgule! le nom des champs répond aux critères des noms de variable deux champs ne peuvent avoir le même nom les données peuvent être de n'importe quel type

Ainsi, la structure suivante est correcte: struct ma_structure { int age; char sexe; char nom[12]; float moyenne; struct autre_structure struct_b;
/* en considerant que la structure autre_structure est definie */
};

2.2 Définition d'une variable structurée
La définition d'une variable structurée est une opération qui consiste à créer une variable ayant comme type celui d'une structure que l'on a précédemment déclaré, c'est‐à‐dire la nommer et lui réserver un emplacement en mémoire. La définition d'une variable structurée se fait comme suit: struct nom_structure nom_variable_structuree;

nom_structure représente le nom d'une structure que l'on aura préalablement déclarée. nom_variable_structuree est le nom que l'on donne à la variable structurée. Soit la structure Personne: struct personne{ int age; char sexe;
};

On peut définir plusieurs variables structurées: struct personne p1, p2, p3;

2.3 Accès aux champs d'une variable structurée
Chaque variable de type structure possède des champs repérés avec des noms uniques.
Toutefois le nom des champs ne suffit pas pour y accéder étant donné qu'ils n'ont de contexte qu'au sein de la variable structurée. Pour accéder aux champs d'une structure on
Préparé par M. VALY Dona

2

Institut de Technologie du Cambodge

Génie Informatique et Communication

utilise l'opérateur de champ (un simple point) placé entre le nom de la variable structurée que l'on a définit et le nom du champ: nom_variable.nom_champ;

Ainsi, pour affecter des valeurs à la variable p1 (variable de type struct Personne définie précédemment), on pourra écrire: p1.age = 18; p1.sexe = 'M';

3. Renommage des types
Jusqu’à il n’y a pas longtemps on n’a qu’un nombre limité de types avec des identifications très simples (tels que int, float et char). Avec les constructeurs de types qu’on a vus
(tableau, type énuméré, structure), cela risque d’être pénible de déclarer une variable.
Heureusement on peut donner un nom à un type donné, aussi compliqué soit‐il, et utiliser ce nom au lieu de la description complète du type à chaque fois que l’on voudrait déclarer une variable. Ceci se fait en langage C grâce au mot clé typedef. typedef type nom_type;

Où type est la description d’un type et nom_type l’identificateur, comme d’habitude non utilisé pour autre chose. Cette ligne se place au niveau des déclarations de constantes et des variables. On renomme ainsi le type type en lui donnant un nouveau nom de substitution nom_type. On pourra déclarer plutôt une variable de type type de la façon suivante : nom_type var1, var2, var3;

Par exemple : typedef int entier; typedef enum jour Jour; typedef struct personne Personne;

entier i = 1;
Jour j = lundi;
Personne p;
p.age = 18;

Réf : Pillou, J. (2003). Introduction langage C. Commentçamarche.
Préparé par M. VALY Dona

3

Similar Documents

Free Essay

Kkhksanfklhaklfh

...translation . . . . 2.2 Phases of translation . . . . 2.3 Character sets . . . . . . . . 2.4 Trigraph sequences . . . . . 2.5 Preprocessing tokens . . . . 2.6 Alternative tokens . . . . . 2.7 Tokens . . . . . . . . . . . . 2.8 Comments . . . . . . . . . . 2.9 Header names . . . . . . . . 2.10 Preprocessing numbers . . . 2.11 Identifiers . . . . . . . . . . 2.12 Keywords . . . . . . . . . . 2.13 Operators and punctuators 2.14 Literals . . . . . . . . . . . 3 Basic 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 Contents concepts Declarations and definitions One definition rule . . . . . Scope . . . . . . . . . . . . Name lookup . . . . . . . . Program and linkage . . . . Start and termination . . . Storage duration . . . . . . Object lifetime . . . . . . . Types . . . . . . . . . . . . Lvalues and rvalues . . . . . ii x xiv 1 1 1 2 5 5 6 6 7 8 11 14 16 16 16 17 18 19 20 20 20 20 21 21 22 22 23 32 32 34 36 42 55 58 62 65 69 74 ii . . . . . . . . . . ....

Words: 144120 - Pages: 577

Premium Essay

Gsl Scientific Library

...GNU Scientific Library Reference Manual Edition 1.14, for GSL Version 1.14 4 March 2010 Mark Galassi Los Alamos National Laboratory Jim Davies Department of Computer Science, Georgia Institute of Technology James Theiler Astrophysics and Radiation Measurements Group, Los Alamos National Laboratory Brian Gough Network Theory Limited Gerard Jungman Theoretical Astrophysics Group, Los Alamos National Laboratory Patrick Alken Department of Physics, University of Colorado at Boulder Michael Booth Department of Physics and Astronomy, The Johns Hopkins University Fabrice Rossi University of Paris-Dauphine Copyright c 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The GSL Team. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being “GNU General Public License” and “Free Software Needs Free Documentation”, the Front-Cover text being “A GNU Manual”, and with the Back-Cover Text being (a) (see below). A copy of the license is included in the section entitled “GNU Free Documentation License”. (a) The Back-Cover Text is: “You have the freedom to copy and modify this GNU Manual.” Printed copies of this manual can be purchased from Network Theory Ltd at http://www.network-theory.co.uk/gsl/manual/. The money raised from sales of the manual...

Words: 148402 - Pages: 594

Free Essay

Hacking the Art of Exploitation

...2nd Edition Hacking the art of exploitation jon erickson PRAISE FOR THE FIRST EDITION OF HACKING: THE ART OF EXPLOITATION “Most complete tutorial on hacking techniques. Finally a book that does not just show how to use the exploits but how to develop them.” —PHRACK “From all the books I’ve read so far, I would consider this the seminal hackers handbook.” —SECURITY FORUMS “I recommend this book for the programming section alone.” —UNIX REVIEW “I highly recommend this book. It is written by someone who knows of what he speaks, with usable code, tools and examples.” —IEEE CIPHER “Erickson’s book, a compact and no-nonsense guide for novice hackers, is filled with real code and hacking techniques and explanations of how they work.” —COMPUTER POWER USER (CPU) MAGAZINE “This is an excellent book. Those who are ready to move on to [the next level] should pick this book up and read it thoroughly.” —ABOUT.COM INTERNET/NETWORK SECURITY ® San Francisco HACKING: THE ART OF EXPLOITATION, 2ND EDITION. Copyright © 2008 by Jon Erickson. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. Printed on recycled paper in the United States of America 11 10 09 08 07 123456789 ISBN-10: 1-59327-144-1 ISBN-13: 978-1-59327-144-2 Publisher:...

Words: 139438 - Pages: 558

Free Essay

Student

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R OB E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured...

Words: 142312 - Pages: 570

Free Essay

Concepts of Programming Languages

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R O B E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured in the United States...

Words: 142253 - Pages: 570

Premium Essay

Let Us C - Yashwant Kanetkar.Pdf

...Let Us C Fifth Edition Yashavant P. Kanetkar Dedicated to baba Who couldn’t be here to see this day... About the Author Destiny drew Yashavant Kanetkar towards computers when the IT industry was just making a beginning in India. Having completed his education from VJTI Mumbai and IIT Kanpur in Mechanical Engineering he started his training company in Nagpur. Yashavant has a passion for writing and is an author of several books in C, C++, VC++, C#, .NET, DirectX and COM programming. He is a much sought after speaker on various technology subjects and is a regular columnist for Express Computers and Developer 2.0. His current affiliations include being a Director of KICIT, a training company and DCube Software Technologies, a software development company. In recognition to his contribution Microsoft awarded him the prestigious “Best .NET Technical Contributor” award recently. He can be reached at kanetkar@kicit.com. Preface to the Fifth Edition It is mid 2004. World has left behind the DOTCOM bust, 9/11 tragedy, the economic downturn, etc. and moved on. Countless Indians have relentlessly worked for close to two decades to successfully establish “India” as a software brand. At times I take secret pleasure in seeing that a book that I have been part of, has contributed in its own little way in shaping so many budding careers that have made the “India” brand acceptable. Computing and the way people use C for doing it keeps changing as years go by. So overwhelming...

Words: 46379 - Pages: 186

Premium Essay

Let Us C

...Let Us C Fifth Edition Yashavant P. Kanetkar Dedicated to baba Who couldn’t be here to see this day... About the Author Destiny drew Yashavant Kanetkar towards computers when the IT industry was just making a beginning in India. Having completed his education from VJTI Mumbai and IIT Kanpur in Mechanical Engineering he started his training company in Nagpur. Yashavant has a passion for writing and is an author of several books in C, C++, VC++, C#, .NET, DirectX and COM programming. He is a much sought after speaker on various technology subjects and is a regular columnist for Express Computers and Developer 2.0. His current affiliations include being a Director of KICIT, a training company and DCube Software Technologies, a software development company. In recognition to his contribution Microsoft awarded him the prestigious “Best .NET Technical Contributor” award recently. He can be reached at kanetkar@kicit.com. Acknowledgments It has been a journey of almost a decade from the stage the book idea of “Let Us C” was conceived up to the release of this Fifth Edition. During this journey I have met so many students, developers, professors, publishers and authors who expressed their opinions about Let Us C. They have been the main motivators in my effort to continuously improve this book. In particular I am indebted to Manish Jain who had a faith in this book idea, believed in my writing ability, whispered the words of encouragement and made helpful suggestions...

Words: 46651 - Pages: 187

Free Essay

C Book

...Let Us C Fifth Edition Yashavant P. Kanetkar Dedicated to baba Who couldn’t be here to see this day... About the Author Destiny drew Yashavant Kanetkar towards computers when the IT industry was just making a beginning in India. Having completed his education from VJTI Mumbai and IIT Kanpur in Mechanical Engineering he started his training company in Nagpur. Yashavant has a passion for writing and is an author of several books in C, C++, VC++, C#, .NET, DirectX and COM programming. He is a much sought after speaker on various technology subjects and is a regular columnist for Express Computers and Developer 2.0. His current affiliations include being a Director of KICIT, a training company and DCube Software Technologies, a software development company. In recognition to his contribution Microsoft awarded him the prestigious “Best .NET Technical Contributor” award recently. He can be reached at kanetkar@kicit.com. Acknowledgments It has been a journey of almost a decade from the stage the book idea of “Let Us C” was conceived up to the release of this Fifth Edition. During this journey I have met so many students, developers, professors, publishers and authors who expressed their opinions about Let Us C. They have been the main motivators in my effort to continuously improve this book. In particular I am indebted to Manish Jain who had a faith in this book idea, believed in my writing ability, whispered the words of encouragement and made helpful suggestions...

Words: 46741 - Pages: 187

Free Essay

Distributed Systems

...Distributed Systems: Concepts and Design Edition 3 By George Coulouris, Jean Dollimore and Tim Kindberg Addison-Wesley, ©Pearson Education 2001 Chapter 1 1.1 Exercise Solutions Give five types of hardware resource and five types of data or software resource that can usefully be shared. Give examples of their sharing as it occurs in distributed systems. 1.1 Ans. Hardware: CPU: compute server (executes processor-intensive applications for clients), remote object server (executes methods on behalf of clients), worm program (shares cpu capacity of desktop machine with the local user). Most other servers, such as file servers, do some computation for their clients, hence their cpu is a shared resource. memory: cache server (holds recently-accessed web pages in its RAM, for faster access by other local computers) disk: file server, virtual disk server (see Chapter 8), video on demand server (see Chapter 15). screen: Network window systems, such as X-11, allow processes in remote computers to update the content of windows. printer: networked printers accept print jobs from many computers. managing them with a queuing system. network capacity: packet transmission enables many simultaneous communication channels (streams of data) to be transmitted on the same circuits. Data/software: web page: web servers enable multiple clients to share read-only page content (usually stored in a file, but sometimes generated on-the-fly). file: file servers enable multiple clients to share...

Words: 38975 - Pages: 156

Premium Essay

Kkswmddkmdkemwekdemkedmkdemkmdkmdkew

...MODERN DATABASE MANAGEMENT / JfFFREY A. HOFFER . Warehousing Success 426 Data Warehouse Architectures 428 Generic Two-Level Architecture 428 Independent Data Mart Data Warehousing Environment 426 429 C O NTENTS Dependent Data Mart and Operational Data Store Architecture: A Three-Level Approach Logical Data Mart and Real-Time Data Warehouse Architecture 432 Three-Layer Data Architecture 435 Role of the Enterprise Data Model 435 Role of Metadata 436 Some Characteristics of Data Warehouse Data Status Versus Event Data 437 Transient Versus Periodic Data 438 An Example of Transient and Periodic Data 438 Transient Data 438 Periodic Data 439 Other Data VVarehouse Changes 440 The Reconciled Data Layer 441 Characteristics of Data after ETL 441 The ETL Process 442 Extract 442 Cleanse 444 Load and Index 446 Data Transformation 447 Data Transformation Functions 448 Record-Level Functions 448 Field-Level Functions 449 More Complex Transformations 451 Tools to Support Data Reconciliation 451 Data Quality Tools 451 Data Conversion Tools 452 Data Cleansing Tools 452 Selecting Tools 452 The Derived Data Layer 452 Characteristics of Derived Data 452 The Star Schema 453 Fact Tables and Dimension Tables 453 Example Star Schema 454 Surrogate Key 455 Grain of Fact Table 456 Duration of the Database 456 Size of the Fact Table 457 Modeling Date and Time 458 Variations of the Star Schema 458 Multiple Fact Tables 458 Factless Fact Tables...

Words: 80097 - Pages: 321