Thread: A few questions on pointers

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    15

    A few questions on pointers

    Hi guys,

    I need some help.

    1) What exactly does this mean and how do I use this definition:
    Code:
    typedef int (*Tf2)(int [], int);
    2) How can I get the value of one element from this 2D array, inside the function?
    For example, if it was declared as int v[][], I would do v[5][6]. Can I do the same with pointers?
    Code:
    int function(int **v)
    Thank you.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    1. It's a typedef for a function pointer.

    Eg.
    Code:
    int foo ( int array[], int size ) {
    }
    
    Tf2 myfunc = foo;
    
    result = myfunc( array, len );  // calls foo
    > For example, if it was declared as int v[][], I would do v[5][6]. Can I do the same with pointers?
    No, you cannot pass an array declared [][] to a pointer expecting **
    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. malloc problem
    By Tool in forum C Programming
    Replies: 23
    Last Post: 03-12-2010, 10:54 AM
  2. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. moving pointers to pointers
    By Benzakhar in forum C++ Programming
    Replies: 9
    Last Post: 12-27-2003, 08:30 AM

Tags for this Thread