questions about pointers

This is a discussion on questions about pointers within the C Programming forums, part of the General Programming Boards category; hey guys, im kind of new in c and i have two questions, first what is the void * v[] ...

  1. #1
    Registered User
    Join Date
    Apr 2009

    questions about pointers

    hey guys, im kind of new in c and i have two questions, first what is the void * v[] for? second what is the "comp" in this line? "int (*comp)(void *,void *);" its part of an example program for it casting of some kind?
    appreciate any help.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    1) It is an array of pointers that point to a void (can point to anything). So v[1] is a pointer, v[3] is also a pointer (a *void)
    2) It is a function pointer that points to a function that is like int fun(void *, void* )
    int fun(void* a, void* b)
       return 0;
    int (*comp)(void*, void*);
    comp = &fun; //comp will point to fun
    comp(a, b); //like fun(a,b)

  3. #3
    Join Date
    Oct 2008
    comp is a pointer to a function returning int
    v is an array of void pointers

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    "int (*comp)(void *,void *);" is a function pointer. One use for that is so you can include a function as a parameter to another function:
    #include <stdio.h>
    void one() {
    	printf("Function one\n");
    void two() {
    	printf("Function two\n");
    void dowhat (void (somefunction)()) {
    int main() {
    	return 0;
    I've never used C's qsort but apparently you can pass it your own comparison function, which accepts two pointers (to the things to compare) and returns an int.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 06:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 11:56 AM
  3. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  4. pointers, functions, parameters
    By sballew in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 10:33 PM
  5. Pointers pointers pointers...
    By SMurf in forum C Programming
    Replies: 8
    Last Post: 10-23-2001, 05:55 PM

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