Free Essay

Arrays Versus Pointers

In:

Submitted By hmontes80
Words 288
Pages 2
Arrays versus Pointers
A pointer is a variable which keeps a memory address. This address is the position of another item in memory. A pointer has variable name exactly like any other variable and also has got type which designates what type of variable its elements refer to. For instance, in case one variable has the memory address of another variable, the 1st variable is said to point to the second variable.

Declaring a Pointer

Pointers may be announced as we do normal variables, except for the pointer name has an asterisk before it to show that it's variable which is a pointer. The normal syntax for announcing a pointer is

type* variable_name;

We can put the asterisk near to variable name, but it’s a good programming routine to put the asterisk close type because it shows that the pointer variable points to that kind of variable.

For instance, we wish to announce a pointer that keeps the memory address of an integer variable. The announcement would appear as follows

int* ptr;

There are 2 operators linked with pointers.

1. Address-of operator(&)

This operator is utilized to get the address of a variable. It's a unary operator. Let's see an illustration on the way to utilize this operator. int var = 9; //declare a variable of integer type int* ptr; //declare pointer ptr = &var; //assign the address of var to pointer variable

2. Indirection operator(*)

This operator is utilized to access the contents of the address included in the pointer variable. Next to view the way we utilize this operator, we carry on from above illustration. Assume we wish to print the value in var utilizing ptr we can do this as follows cout

Similar Documents

Free Essay

Linkedlist

...List 1 List vs Arrays Two built-in data structures that can be used to organize data, or to create other data structures: • Lists • Arrays Lists A list is an ordered set of data. It is often used to store objects that are to be processed sequentially. Arrays An array is an indexed set of variables, such as dancer[1], dancer[2], dancer[3],… It is like a set of boxes that hold things. A list is a set of items. An array is a set of variables that each store an item. Arrays and Lists You can see the difference between arrays and lists when you delete items. Arrays and Lists In a list, the missing spot is filled in when something is deleted. Arrays and Lists In an array, an empty variable is left behind when something is deleted. What’s wrong with Array and Why lists? • Disadvantages of arrays as storage data structures: – slow searching in unordered array – slow insertion in ordered array – Fixed size • Linked lists solve some of these problems • Linked lists are general purpose storage data structures and are versatile. Linked Lists A Head B C  • A linked list is a series of connected nodes • Each node contains at least – A piece of data (any type) – Pointer to the next node in the list • Head: pointer to the first node • The last node points to NULL node A data pointer The composition of a Linked List • A linked list is called "linked" because each node in the series has a pointer that points to the...

Words: 2375 - Pages: 10

Free Essay

C++ Objects Solutions

...an if/else Statement, p. 172 Using an if/else if Statement, p. 175 Solving the Time Calculator Problem, p. 236 The while Loop, p. 249 The for Loop, p. 263 Nested Loops, p. 277 Solving the Ocean Levels Problem, p. 299 Defining and Calling Functions, p. 306 Using Function Arguments, p. 316 Value-Returning Functions, p. 326 Solving the Markup Problem, p. 380 Creating a Class, p. 391 Creating and Using Class Objects, p. 393 Creating and Using Structures, p. 436 Solving the Car Class Problem, p. 480 Accessing Array Elements, p. 487 Passing an Array to a Function, p. 517 Two-Dimensional Arrays, p. 526 Solving the Chips and Salsa Problem, p. 567 Performing a Binary Search, p. 580 Sorting a Set of Data, p. 587 Solving the Lottery Winners Problem, p. 616 (continued on next page) Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 LOCATION OF VIDEONOTES IN THE TEXT Chapter 10 Pointer Variables, p. 621 Dynamically Allocating an Array, p. 645 Solving the Days in Current Month Problem, p. 676 (continued) Chapter 11 Operator Overloading, p. 704 Aggregation and Composition, p. 734 Overriding Base Class Functions, p. 755 Solving the Number of Days Worked Problem, p. 768 Converting Strings to Numbers, p. 788 Writing a C-String Handling Function, p. 800 Solving the Backward...

Words: 11246 - Pages: 45

Premium Essay

Adressing Modes

...= address field (A) • e.g. ADD A Add contents of cell A to accumulator Look in memory at address A for operand • Single memory reference to access data Direct Addressing Diagram Instruction Opcode Address A Memory • No additional calculations to work out effective address • Limited address space Operand Indirect Addressing (1) • Memory cell pointed to by address field contains the address of (pointer to) the operand • EA = (A) Look in A, find address (A) and look there for operand • e.g. ADD (A) Add contents of cell pointed to by contents of A to accumulator Indirect Addressing (2) • Large address space • 2n where n = word length • May be nested, multilevel, cascaded e.g. EA = (((A))) f Draw the diagram yourself • Multiple memory accesses to find operand • Hence slower Indirect Addressing Diagram Register Addressing (1) • • • • Operand is held in register named in address filed EA = R Limited number of registers Very small address field needed Shorter instructions Faster instruction fetch Instruction Opcode Address A Memory Pointer to operand Operand Register Addressing (2) • • • • No memory access Very fast execution...

Words: 592 - Pages: 3

Premium Essay

C++ Programming

...C++ PROGRAMMING: FROM PROBLEM ANALYSIS TO PROGRAM DESIGN FIFTH EDITION D.S. MALIK Australia  Brazil  Japan  Korea  Mexico  Singapore  Spain  United Kingdom  United States C++ Programming: From Problem Analysis to Program Design, Fifth Edition D.S. Malik Executive Editor: Marie Lee Acquisitions Editor: Amy Jollymore Senior Product Manager: Alyssa Pratt Editorial Assistant: Zina Kresin Content Project Manager: Matthew Hutchinson Art Director: Faith Brosnan Print Buyer: Julio Esperas Cover Designer: Roycroft Design/ www.roycroftdesign.com Cover Photo: ª Guntmar Fritz/Masterfile Proofreader: Green Pen QA Indexer: Elizabeth Cunningham Compositor: Integra ª 2011 Course Technology, Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at www.cengage.com/permissions Further permissions questions can be...

Words: 11776 - Pages: 48

Free Essay

Research Paper

.... . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 2 The Job Application Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Chapter 3 Approaches to Programming Problems. . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Chapter 4 Linked Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Chapter 5 Trees and Graphs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Chapter 6 Arrays and Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Chapter 7 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 . . Chapter 8 Sorting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

Words: 48008 - Pages: 193

Premium Essay

Learn C Programming Language in 24 Hours

...Sams Teach Yourself C in 24 Hours Previous | Table of Contents | Next Hour 1 - Getting Started A journey of a thousand miles is started by taking the first step. —Chinese proverb High thoughts must have high language. —Aristophanes Welcome to Teach Yourself C in 24 Hours. In this first lesson you'll learn the following:     What C is Why you need to learn C The ANSI standard Hardware and software required in order to run the C program What Is C? C is a programming language. The C language was first developed in 1972 by Dennis Ritchie at AT&T Bell Labs. Ritchie called his newly developed language C simply because there was a B programming language already. (As a matter of fact, the B language led to the development of C.) C is a high-level programming language. In fact, C is one of the most popular general-purpose programming languages. In the computer world, the further a programming language is from the computer architecture, the higher the language's level. You can imagine that the lowest-level languages are machine languages that computers understand directly. The high-level programming languages, on the other hand, are closer to our human languages. (See Figure 1.1.) Figure 1.1. The language spectrum. High-level programming languages, including C, have the following advantages:    Readability: Programs are easy to read. Maintainability: Programs are easy to maintain. Portability: Programs are easy to port across different computer platforms. The...

Words: 73255 - Pages: 294

Free Essay

Databases Review

...  9  secAon  9.8   –  Chapter  12  secAon  12.2.1   2   Midterm  exam   •  Day  and  Ame:     –  Thursday,  October  8,  2015   –  6  PM  to  8  PM   •  No  books,  homework  assignments,  lecture   slides  or  any  other  documents  are  allowed  for   this  exam.     –  has  to  complete  individually  by  each  student   3   Topics  covered  on  midterm:   •  •  •  •  •  Physical  disk  organizaAon   RAID  levels   Heap  files   Sorted  files   Indices   –  Integrated  versus  unintegrated   –  Clustered  versus  unclustered   –  Sparse  versus  dense   –  MulAple  a[ribute  search  keys     4   Topics  covered  on  midterm:     •  MulAlevel  indexing   –  ISAM   –  B+  Trees   •  Searching  B+  Trees   •  InserAng  into  B+  Trees   •  •  •  •  Hash  indices   Choosing  indices  for  queries   Designing  indices  (SecAon  12.2.1)   Index  covering   5   Physical  Disk  Structure   6   Disk  Latency   •  The  distance  between  disk  sectors  in   increasing  order:   1.  2.  3.  4.  Two  adjacent  sectors  on  the  same ...

Words: 1010 - Pages: 5

Premium Essay

Computers

...C Primer Plus Sixth Edition Developer’s Library ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS Developer’s Library books are designed to provide practicing programmers with unique, high-quality references and tutorials on the programming languages and technologies they use in their daily work. All books in the Developer’s Library are written by expert technology practitioners who are especially skilled at organizing and presenting information in a way that’s useful for other programmers. Key titles include some of the best, most widely acclaimed books within their topic areas: PHP & MySQL Web Development Luke Welling & Laura Thomson ISBN 978-0-672-32916-6 Python Essential Reference David Beazley ISBN-13: 978-0-672-32978-4 MySQL Paul DuBois ISBN-13: 978-0-321-83387-7 PostgreSQL Korry Douglas ISBN-13: 978-0-672-32756-8 Linux Kernel Development Robert Love ISBN-13: 978-0-672-32946-3 C++ Primer Plus Stephen Prata ISBN-13: 978-0-321-77640-2 Developer’s Library books are available in print and in electronic formats at most retail and online bookstores, as well as by subscription from Safari Books Online at safari. informit.com Developer’s Library informit.com/devlibrary C Primer Plus Sixth Edition Stephen Prata Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City C Primer Plus Sixth...

Words: 125302 - Pages: 502

Free Essay

Ali94

...35 New Ways to Improve Your Programs and Designs Scott Meyers More Effective C ADDISON-WESLEY PROFESSIONAL COMPUTING SERIES ++ Conforms to the new ISO/ANSI C++ standard! From the Library of Yuri Khan Praise for More Effective C++: 35 New Ways to Improve Your Programs and Designs “This is an enlightening book on many aspects of C++: both the regions of the language you seldom visit, and the familiar ones you THOUGHT you understood. Only by understanding deeply how the C++ compiler interprets your code can you hope to write robust software using this language. This book is an invaluable resource for gaining that level of understanding. After reading this book, I feel like I've been through a code review with a master C++ programmer, and picked up many of his most valuable insights.” — Fred Wild, Vice President of Technology, Advantage Software Technologies “This book includes a great collection of important techniques for writing programs that use C++ well. It explains how to design and implement the ideas, and what hidden pitfalls lurk in some obvious alternative designs. It also includes clear explanations of features recently added to C++. Anyone who wants to use these new features will want a copy of this book close at hand for ready reference.” — Christopher J. Van Wyk, Professor, Mathematics and Computer Science, Drew University “Industrial strength C++ at its best. The perfect companion to those who have read Effective C++.” — Eric Nagler, C++ Instructor...

Words: 43056 - Pages: 173

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

Analysis

...SEVENTH EDITION PROBLEM SOLVING AND PROGRAM DESIGN in C This page intentionally left blank SEVENTH EDITION PROBLEM SOLVING AND PROGRAM DESIGN in C Jeri R. Hanly, University of Wyoming Elliot B. Koffman, Temple University 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 Editorial Director, ECS: Marcia Horton Editor-in-Chief: Michael Hirsch Senior Project Manager: Carole Snyder Director of Marketing: Patrice Jones Marketing Manager: Yezan Alayan Senior Marketing Coordinator: Kathryn Ferranti Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Associate Managing Editor: Robert Engelhardt Production Manager: Pat Brown Creative Director: Jayne Conte Designer: Suzanne Behnke Media Editor: Daniel Sandin Media Project Manager: John Cassar Cover Image: (c) michael Holcomb/Shutterstock.com Full-Service Project Management: Mohinder Singh/ Aptara®, Inc. Composition: Aptara®, Inc. Printer/Binder: Edwards Brothers Cover Printer: Lehigh-Phoenix Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate page within text. Photo Credits: Page 4: Fig. 0.1: akg-images/Paul Almasy/Newscom. Page 11: Fig. 0.4: © 2008 IEEE/Journal of Microelectromechanical Systems (2006). Page 15:...

Words: 158087 - Pages: 633

Free Essay

Computer Vision

...Learning OpenCV Gary Bradski and Adrian Kaehler Beijing · Cambridge · Farnham · Köln · Sebastopol · Taipei · Tokyo Learning OpenCV by Gary Bradski and Adrian Kaehler Copyright © 2008 Gary Bradski and Adrian Kaehler. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Mike Loukides Production Editor: Rachel Monaghan Production Services: Newgen Publishing and Data Services Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: September 2008: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Learning OpenCV, the image of a giant peacock moth, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this...

Words: 150684 - Pages: 603

Free Essay

Discrete Event System

...PART ONE Introduction to Discrete-Event System Simulation 1 Introduction to Simulation A simulation is the imitation of the operation of a real-world process or system over time. Whether done by hand or on a computer, simulation involves the generation of an artificial history of a system, and the observation of that artificial history to draw inferences concerning the operating characteristics of the real system. The behavior of a system as it evolves over time is studied by developing a simulation model. This model usually takes the form of a set of assumptions concerning the operation of the system. These assumptions are expressed in mathematical, logical, and symbolic relationships between the entities, or objects of interest, of the system. Once developed and validated, a model can be used to investigate a wide variety of “what-if” questions about the realworld system. Potential changes to the system can first be simulated in order to predict their impact on system performance. Simulation can also be used to study systems in the design stage, before such systems are built. Thus, simulation modeling can be used both as an analysis tool for predicting the effect of changes to existing systems, and as a design tool to predict the performance of new systems under varying sets of circumstances. In some instances, a model can be developed which is simple enough to be “solved” by mathematical methods. Such solutions may be found by the use of differential calculus, probability...

Words: 33852 - Pages: 136

Free Essay

Vivek

...DETAILED SYLLABUS POST GRADUATE DIPLOMA IN COMPUTER APPLICATIONS (PGDCA) (EFFECTIVE FROM JULY 2011) Department of Computer Applications Makhanlal Chaturvedi Rashtriya Patrakarita Evam Sanchar Vishwavidyalaya B-38, Press Complex, M.P. Nagar, Zone-I, Bhopal Ph.: 4294448, 2768274 www.mcu.ac.in SCHEME FOR POST GRADUATE DIPLOMA IN COMPUTER APPLICATIONS (PGDCA) (Effective From July 2011 Session) SEMESTER -I Subject Code Subject Name Scheme L 1PGDCA1 1PGDCA2 1PGDCA3 1PGDCA4(A) 1PGDCA4(B) Fundamentals of Computers & Information Technology Introduction to Operating Systems (Dos, Windows, Linux) PC Packages Elective - 1 Foxpro MS-Access 4 4 1 3 T P Theory Paper 80 80 Internal Evaluation 20 20 Practical Exams Total Marks 100 100 4 4 1 3 3 80 80 20 20 25 25 125 125 Semester Total 450 (*L-Lecture, T-Tutorial, P-Practical) SEMESTER –II Subject Code Subject Name Scheme L 2PGDCA1 2PGDCA2 2PGDCA3 2PGDCA4(A) 2PGDCA4(B) 2PGDCA5 System Analysis and Design Programming with Visual Basic.NET Internet & E-Commerce Elective - 2 OOPs & Programming with C++ Financial Accounting with Tally Project Work 4 4 4 4 T 1 P 3 3 3 Theory Paper 80 80 80 80 Internal Evaluation 20 20 20 20 Practical Exams Total Marks 100 125 100 125 25 1 25 4 100 Semester Total 550 General Instructions: 1. For passing the subject examination minimum 40% marks must be separately scored in Theory Paper, Practical Exams and Internal Evaluation in the subject. 2. For...

Words: 4021 - Pages: 17