Thread: Homework typo

  1. #1
    Registered User
    Join Date
    Dec 2016
    Posts
    4

    Homework typo

    Hello everyone, I was wondering if there is a typo in the solutions for the code below:

    int x = 0;
    int *p_int = &x;
    int **p_p_int = & p_int;
    *p_int = 12;
    **p_p_int = 25;
    p_int = 12;
    *p_p_int = 3;
    p_p_int = 27;

    Then it asks for x , p_int and p_p_int values.

    why does x = 25 in the solution? doesn't *p_int only reference it, so one can only change this x-value by reference or manually change by assigning x a value directly? also what does *p_p_int point to ?

  2. #2
    Registered User
    Join Date
    Dec 2016
    Posts
    4
    Okay I see that the *p_p_int points to the p_int address, and this **p_p_int points to x, never mind figured it out.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,165
    p_int = 12;
    *p_p_int = 3;
    p_p_int = 27;
    These three are nonsense, since integers are not pointers.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Typo on C Tutorial
    By FloridaJo in forum C Programming
    Replies: 1
    Last Post: 05-30-2013, 10:48 AM
  2. Typo on C-FAQ
    By ssharish2005 in forum General Discussions
    Replies: 3
    Last Post: 06-06-2011, 05:24 PM
  3. typo in mass calculation
    By florian100 in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2009, 12:31 AM
  4. typo on faq
    By chrismiceli in forum Linux Programming
    Replies: 2
    Last Post: 10-06-2003, 03:23 PM
  5. typo
    By ygfperson in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2002, 01:25 AM

Tags for this Thread