Thread: Typo on C-FAQ

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732

    Typo on C-FAQ

    From the chapter "A tutorial on Pointer" i see the following snippet of code

    Code:
    const int cintA = 10;                     // A constant int
    int       intB = 20;                      // A nonconstant int
    const int *pointer_to_const_int = &cintA; // A pointer to a const int. The POINTER ITSELF IS NOT CONST.
    *pointer_to_const_int = 20;               // Compiler error *pointer_to_const_int is a constant 
                                              // and cannot be changed.
    pointer_to_const_int++;                   // This is fine, it's simple pointer arithmetic 
                                              // moving the pointer to the next memory location.  
                                              // The pointer itself is not const so it may be repointed.
    const int *const  const_pointer_to_const_int = &cintA;  // Here we have a constant pointer to a 
                                              // constant int. Notice as pointer is const we must 
                                              // initialise it here.
    const_pointer_to_const_int++;             // This is now illegal. The pointer itself is const 
                                              // and may not be repointed.
    *const_pointer_to_const_int = 40;         // Again compiler error. Pointer points to constant data. 
                                              // You cannot write through this pointer.
    int *pointer_to_int = *intB;
    *pointer_to_int = 40;                     // This is fine. Data pointed to is not constant.
    pointer_to_int++;                         // Again fine, pointer is not constant, you may repoint it.
    int *const  const_pointer_to_int = &intB; // Constant pointer to non-constant int. 
                                              // Pointer is const so must be initialised here.
    const_pointer_to_int++;                   // Compiler error. The pointer itself is constant and 
                                              // may not be repointed.
    *const_pointer_to_int = 80;               // This is fine. Although the pointer is constant the object
                                              // pointed to is not constant and so may be written to.
    Highlighted statment - Shouldn't that be?

    Code:
    int *pointer_to_int = &intB;
    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Yes, I think you're correct. Trying to compile the relevant lines results in "error: invalid type argument of ‘unary *’ (have ‘int’)" on my system.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Yes this needs to be changed. Calling administrators *shout loud*

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #4
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012
    Thank you for the report; I have corrected this typo.

    By the way, the fastest way to report errors is to email me directly at [email protected].

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird typo leads to interesting result... what does it mean?
    By pollypocket4eva in forum C++ Programming
    Replies: 4
    Last Post: 06-17-2010, 03:30 AM
  2. typo in mass calculation
    By florian100 in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2009, 12:31 AM
  3. basic recursion function question. typo in book?
    By navyzack in forum C Programming
    Replies: 6
    Last Post: 04-18-2005, 11:07 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