Group29.com - What did you expect?
  Create an account
:: Home  ::  Downloads  ::  Your Account  ::  Forums  ::
Google Adsense
Modules
  • Home
  • Downloads
  • ExpectationReviews
  • Forums
  • Group29 FAQ
  • MovieReviews
  • OtherReviews
  • Stories Archive
  • Submit News
  • Top 10
  • Topics
  • Web Links
  • New at Group29
    ·Expectation Review: Avengers: Infinity War [24]
    ·Movie Review: Star Wars: The Last Jedi [16]
    ·Movie Review: Star Wars: The Last Jedi [23]
    ·2017 USC vs UCLA preview
    ·Forum Topic: Update your Facebook property
    ·2016 UCLA vs USC preview
    ·Expectation Review: Star Wars: The Force Awakens [29]
    ·Web Link: WEP Key Converter
    ·Forum Topic: Why does my IPA file get saved as a zip file in IE?
    ·Web Link: BeyondCompare

    read more...
    TheForce.Net
    ·Rebelscum Breast Cancer Awareness Charity Patch
    ·BBC Interviews J.J. Abrams About Trek And Wars
    ·CEII: Jabba's Palace Reunion - Massive Guest Announcements
    ·Fathead's May the Fourth Be With You!
    ·Star Wars Night With The Tampa Bay Storm Reminder
    ·Stephen Hayford Star Wars Weekends Exclusive Art
    ·ForceCast #251: To Spoil or Not to Spoil
    ·New Timothy Zahn Audio Books Coming
    ·SDCC: Exclusive Black Series Boba Fett With Han In Carbonite Set
    ·Star Wars Art Exposition May 4th

    read more...
    Hot trends
    ·Group29.com

    read more...
    Group29 Discussion Board :: View topic - C and C++ Pointers and Addresses: Yes, you too can learn...
    Log in Register Forum FAQ Memberlist Search
    Ratings, Links, Free Speech and more

    Group29 Discussion Board Forum Index -> Group29 Tech Tips -> C and C++ Pointers and Addresses: Yes, you too can learn...
    Post new topic  Reply to topic View previous topic :: View next topic 
    C and C++ Pointers and Addresses: Yes, you too can learn...
    PostPosted: Tue Sep 13, 2005 8:22 am Reply with quote
    BB
    Regular
     
    Joined: Jun 23, 2004
    Posts: 340


      


    In C and C++, nothing screws me up more than pointers and values and their notations on variables * and &.

    Excerpt from
    The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie
    Chapter 5: Pointers and Arrays

    Quote:
    A pointer is a variable that contains the address of a variable. Pointers are much used in C, partly because they are sometimes the only way to express a computation, and partly because they usually lead to more compact and efficient code than can be obtained in other ways. Pointers and arrays are closely related; this chapter also explores this relationship and shows how to exploit it.

    Pointers have been lumped with the goto statement as a marvelous way to create impossible to understand programs. This is certainly true when they are used carelessly, and it is easy to create pointers that point somewhere unexpected.


    Pointers are like directions to somewhere...

    Think of the house of one of your friends. That house has an address. That house also has some content, meaning, people live there.

    So when you set a pointer, you set the directions for that house.

    What is inside the house? Use * (asterisk) on your variable name.
    What is the address of the house? Use & (ampersand) on your variable name.

    Pointers need to "point" to somewhere valid. To reserve space to build a house, You need to buy that space. That is what malloc does, it just buys you some space.

    If you give me an address for a house that is not there ... invalid

    Example:

    This is how you declare a pointer:

    Code:
    house* direction;


    Let us buy a house. We need to buy space for the house:

    Code:
    direction = (house*)malloc(sizeof(house))


    Wow... what was that?

    The malloc (memoray allocate) reserves space, remember? The big question is, how much space? That is what sizeof tells it, the size of a house. The (house*) part is one you do not need to bother. Just substitute house with whatever variable type you need.

    Now, Do you want to know what is inside of a house?

    Code:
    insideHouse = *house;


    Do you want to know what is the address of that new house?

    Code:
    addressHouse = &house;
    View user's profile Visit poster's website
    C and C++ Pointers and Addresses: Yes, you too can learn...
      Group29 Discussion Board Forum Index -> Group29 Tech Tips
    You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot vote in polls in this forum
    All times are GMT - 6 Hours  
    Page 1 of 1  

      
      
     Post new topic  Reply to topic  


    Powered by phpBB © 2001-2003 phpBB Group
    Theme created by Vjacheslav Trushkin
    Forums ©
    Group29 Productions

    All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest (c) 2006 by Group29 Productions.


    You can syndicate Group29 Productions news with an RSS Feeder using the file backend.php


    PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
    Page Generation: 0.22 Seconds

    :: HeliusGray phpbb2 style by CyberAlien :: PHP-Nuke theme by www.nukemods.com ::