Thread: Confusion with pointers!

  1. #1
    Registered User
    Join Date
    Nov 2017

    Smile Confusion with pointers!

    for example
    int *p' //means an integer pointer
    int p = 4*8;//means a integer number
    Can you note that I am using the same operator in two completely different scenarios and the operator knows how to perform the job depending upon its position. So how does it do that?

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    The compiler keeps track of the order or elements in each expression and interprets the * (Asterisk) accordingly. There are fixed rules that ensure there's no ambiguity, even if things can get hard to parse for humans working with the code.

    There is also the dereference operator:
    int i = 5 * 7;
    int* p = &i;
    int j = *p; // dereference p to get i
    Maybe if the language was designed nowadays, different characters would be used:
    int i = 5 * 7;
    int^ p = @i; // int pointer p = address of i

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confusion with pointers
    By Stormboy in forum C Programming
    Replies: 8
    Last Post: 08-31-2013, 08:49 AM
  2. confusion with pointers
    By baxy in forum C Programming
    Replies: 2
    Last Post: 12-01-2011, 06:25 AM
  3. Confusion With Pointers
    By ObjectWithBrain in forum C Programming
    Replies: 28
    Last Post: 07-14-2011, 11:44 AM
  4. Confusion using pointers
    By kluxy in forum C Programming
    Replies: 10
    Last Post: 03-27-2010, 12:07 AM
  5. Confusion about pointers
    By rishiputra in forum C Programming
    Replies: 1
    Last Post: 05-01-2003, 04:39 PM

Tags for this Thread