background preloader

Pointer Basics

Pointer Basics
This document introduces the basics of pointers as they work in several computer languages -- C, C++, Java, and Pascal. This document is the companion document for the Pointer Fun with Binky digital video, or it may be used by itself. This is document 106 in the Stanford CS Education Library. This and other free materials are available at cslibrary.stanford.edu. Some documents that are related to this one include... Section 1 -- Pointer Rules One of the nice things about pointers is that the rules which govern how they work are pretty simple. 1) Pointers and Pointees A pointer stores a reference to something. The above drawing shows a pointer named x pointing to a pointee which is storing the value 42. Allocating a pointer and allocating a pointee for it to point to are two separate steps. 2) Dereferencing The dereference operation starts at the pointer and follows its arrow over to access its pointee. 3) Pointer Assignment Below are versions of this example in C, Java, C++, and Pascal.

http://cslibrary.stanford.edu/106/

Related:  general knowledge

Coding4Fun Articles We've all cringed as a hopelessly out of tune contestant appears on the latest episode of “American Idol.” Occasionally, there's a contestant who manages to be pitch perfect all the way through—right until they flub the final note. And in the cutthroat world of televised auditions, sing one slightly flat note and you're out. So what takes care of a bad-pitch day? Autotune—an effect that corrects the pitch of your voice so you'll never again sing out of tune. And now, with the power of modern microprocessors, autotune is possible in real-time, allowing singers to benefit from its almost magical powers during live concerts. Dennis Ritchie Home Page Location Dennis Ritchie Bell Labs, Rm 2C-517 600 Mountain Ave. Murray Hill, New Jersey 07974-0636, USA dmr@bell-labs.com +1 908-582-3770 (office), +1 908-582-5857 (fax) In Memoriam Dennis died in early October, 2011.

Low Level Bit Hacks You Absolutely Must Know I decided to write an article about a thing that is second nature to embedded systems programmers - low level bit hacks. Bit hacks are ingenious little programming tricks that manipulate integers in a smart and efficient manner. Instead of performing some operation (such as counting the 1 bits in an integer) by looping over individual bits, these programming nuggets do the same with one or two carefully chosen bitwise operations. To get things going I'll assume that you know what the two's complement binary representation of an integer is and also that you know all the the bitwise operations. I'll use the following notation for bitwise operations in the article:

C++ Programming/Exercises/Iterations - Wikibooks, open books for an open world - StumbleUpon Iterations[edit] Solutions requirements Solutions must: Hallmarks of a Great Developer - Test Guide If you ask me, I'll tell you a great developer Plans before coding A great developer takes the time to plan an approach before designing or coding. A great developer knows that the time required to do so will be more than paid back by the time saved by getting it more right the first time. A great developer plans all scales of work, from envisioning multiple versions of a product to writing or modifying a small method. E. W. Dijkstra Archive: A parable. (EWD 594) (Recently I found the following text in manuscript among old papers of mine. It must have been written in the middle of 1973, but I don't think that in the intervening three years it has lost anything of its significance. Hence I now incorporate it in the EWD-series.) A parable. Years ago a railway company was erected and one of its directors —probably the commercial bloke— discovered that the initial investments could be reduced significantly if only fifty percent of the cars would be equipped with a toilet, and, therefore, so was decided. Shortly after the company had started its operations, however, complaints about the toilets came pouring in.

Optimizing C and C++ Code Embedded software often runs on processors with limited computation power, thus optimizing the code becomes a necessity. In this article we will explore the following optimization techniques for C and C++ code developed for Real-time and Embedded Systems. Many techniques discussed here have roots in the material we covered in the articles dealing with C to Assembly translation. A good understanding of the following articles will help: Premature optimization is the root of all evil Donald Knuth wrote, "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered.

C++ QUICK REFERENCE Matt Mahoney, mmahoney@cs.fit.edu // Comment to end of line /* Multi-line comment */ #include <stdio.h> // Insert standard header file #include "myfile.h" // Insert file in current directory #define X some text // Replace X with some text #define F(a,b) a+b // Replace F(1,2) with 1+2 #define X \ some text // Line continuation #undef X // Remove definition #if defined(X) // Condional compilation (#ifdef X) #else // Optional (#ifndef X or #if !defined(X)) #endif // Required after #if, #ifdef

Scripting Languages: PHP, Perl, Python, Ruby - Hyperpolyglot a side-by-side reference sheet sheet one: version | grammar and execution | variables and expressions | arithmetic and logic | strings | regexes | dates and time | arrays | dictionaries | functions | execution control | exceptions | threads sheet two: streams | asynchronous events | files | file formats | directories | processes and environment | option parsing | libraries and namespaces | objects | inheritance and polymorphism | reflection | net and web | gui | databases | unit tests | logging | debugging sheet two: streams | asynchronous events | files | directories | processes and environment | option parsing | libraries and namespaces | objects | inheritance and polymorphism | reflection | net and web | gui | databases | unit tests | logging | debugging version used

An Interview by a Seventh Grader June 2010 (A seventh grader sent me these interview questions for a school project.) 1. What are some qualifications of a computer programmer? Free Books A lot of people keep asking about a good list of programming books. Hence, we are building this list to save your time and to spread the knowledge. Some of these books will definitely help us to evolve our coding skills and thought processes for developing better solutions. PHP Tutorial for Beginners PHP is a powerful scripting language that fits gracefully into HTML and puts the tools for creating dynamic websites in the hands of the people — even people like me who were too lazy to learn Perl scripting and other complicated backend hoodoo. This tutorial is for the person who understands HTML but doesn’t know much about PHP. One of PHP’s greatest attributes is that it’s a freely distributed open-source language, so there’s all kinds of excellent reference material about it out there, which means that once you understand the basics, it’s easy to find the materials that you need to push your skills.

Great Works in Programming Languages In September, 2004, I posted a query to the Types list asking people to name the five most important papers ever written in the area of programming languages. This page collects the responses I received. (A few are missing because I am still tracking down bibliographic information.) Many thanks to Frank Atanassow, David Benson, Nick Benton, Karl Crary, Olivier Danvy, Mariangiola Dezani, Dan Friedman, Alwyn Goodloe, Pieter Hartel, Michael Hicks, Robert Irwin, Luis Lamb, Rod Moten, Rishiyur Nikhil, Tobias Nipkow, Jens Palsberg, and John Reynolds for contributing.

The Brainfuck Programming Language Brainfuck is the ungodly creation of Urban Müller, whose goal was apparently to create a Turing-complete language for which he could write the smallest compiler ever, for the Amiga OS 2.0. His compiler was 240 bytes in size. (Though he improved upon this later -- he informed me at one point that he had managed to bring it under 200 bytes.) I originally started playing around with Brainfuck because of my own interest in writing very small programs for x86 Linux. I also used it as a vehicle for writing a program that created ELF files. Eventually, however, I too succumbed to the Imp of the Perverse and wrote some actual Brainfuck programs of my own.

Related: