Like Tree1Likes
  • 1 Post By c99tutorial

Basic Pointer Problem

This is a discussion on Basic Pointer Problem within the C Programming forums, part of the General Programming Boards category; How can we assign a pointer to a function? const char* function_name(), here what exactly does the pointer point to? ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Location
    Kolkata
    Posts
    20

    Basic Pointer Problem

    How can we assign a pointer to a function? const char* function_name(), here what exactly does the pointer point to?

    Thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    In this example, const char * is the type of the return result.

    size_t strlen( const char *);
    size_t is the return type
    const char * is the parameter type.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Location
    Kolkata
    Posts
    20
    size_t here is an user-defined return type I believe. How do we implement it? Can you help me with an example? Thanks.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,053
    size_t is a type defined by the standard. I think the idea is to solve problems similar to this:

    char x[y];

    You might think y is an integer. But is it really? What if y is -1? What if y is a number outside the range of valid addressable areas on your computer?

    Defining the type as size_t solves these problems because it is guaranteed to work in these situations. But really the bottom line is that if a function returns size_t, then you must either:
    a. assign it to a size_t type variable
    b. guarantee for yourself that the value returned actually does fit into the variable type you are assigning to

    More info:
    int - What is size_t in C? - Stack Overflow

  5. #5
    Registered User
    Join Date
    Jan 2013
    Location
    Kolkata
    Posts
    20
    Thank YOU.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Pointer Problem
    By Prateek Sarkar in forum C Programming
    Replies: 8
    Last Post: 01-21-2013, 10:02 AM
  2. Very basic pointer problem
    By DeliriumCordia in forum C Programming
    Replies: 6
    Last Post: 09-10-2012, 11:00 AM
  3. Basic Pointer Help
    By Neti in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2012, 02:02 PM
  4. Basic pointer syntax
    By Mnemonist in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2010, 09:37 PM
  5. Basic pointer q
    By Jasper in forum C Programming
    Replies: 1
    Last Post: 11-28-2009, 01:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21