Wiki User
∙ 2009-10-30 19:50:43typedef void (*myfunptr)(void);
extern void fun1 (void), fun2 (void), fun3 (void);
myfunptr ptrs[] = {fun1, fun3, fun3};
ptrs[0]();
ptrs[1]();
...
Wiki User
∙ 2009-10-30 19:50:43You point at the array the same way you would with an array of any pointer type, by using an additional level of indirection than is employed by the pointers in the array itself. In this case, the array contains pointer-to-function data types (with one level of indirection), thus you must use a pointer-to-pointer-to-function data type (with two levels of indirection) in order to point at the array itself. Had the array contained pointer-to-pointer-to-function data types (where each pointer points to a separate array of pointer-to-function data types), then you'd use three levels of indirection, and so on. You increase the level of indirection by placing an additional asterisk before the pointer's name when you declare the pointer. That is, one asterisk per level.
If the array is static you can simply point at the first element. For dynamic arrays you can allocate a contiguous block to a single pointer which can then be subdivided using a one-dimensional array of pointer to pointers, each of which points to a one-dimensional array of pointers, each of which points to a separate object within the array. For extremely large arrays, however, it is better to split the elements into separate one-dimensional arrays, by creating a one-dimensional array of pointer to pointers first, then allocating each of those pointers to a separate one-dimensional array of pointers, each of which points to a separate one-dimensional array of objects. Either way, you must destroy all the individual arrays in the reverse order of creation.
Function Pointers are basically used when we want to select a function which is to be used dynamically at run time.AnswerFunction pointers are the only way for "Interept programming". In UNIX all the Interepts are called using function pointers. This is mainly used in system programming. Answerits nothing but a pointer to function. which is similar to ptr to a variable, if we are saying ptr to a variable then it will hold address of the variable like that fn. ptr will have the address of the function.. one of the major application of the function pointer is call back function.. i.e callback.AnswerPointers to functions/methods/subroutines aka 'Delegates' are frequently used in .NET programming especially in EventHandling, MemberInvoking A function pointer is used to pass a function as an argument to another function, or to store a function as a data item, for example a list of functions can be implemented as an array of pointers to functions. Function pointers are used to store interrupt handlers in tables.
A pointer is normally considered an atomic data type. Therefore, a pointer cannot "be indexed like an array" in that it is not possible to access portions of a pointer through an index. However, a pointer can point to data which can be accessed through pointer operations as well as through index operations. Further, multiple pointers can be arranged in an array of pointers, and each individual pointer within that array of pointers can be reached through its array index. Example 1: an array of pointers const char* const array_of_pointers[] = { "Hello, World", "Hello, Venus", "Hello, Mars" }; In this example, each of array_of_pointers[0], array_of_pointers[1] or array_of_pointers[2] evaluates to one pointer, selected with the array index 0..2. Example 2: access to data through pointer using an array-style index void example(char* const text) { *text = 'a'; // set first character pointed to to 'a' *(text+1) = 'b'; // second char becomes 'b' // the following are equivalent to the above, but use index notation: text[0] = 'a'; text[1] = 'b'; } Key to example 2 is the declaration of the pointer as a constant pointer.
In C, arrays are always passed by reference. This is, if you have an array value, and you pass it as the argument to a function, you are actually passing a pointer to the first element in the array, and modifications to the array from inside the function will be seen by the caller.
You point at the array the same way you would with an array of any pointer type, by using an additional level of indirection than is employed by the pointers in the array itself. In this case, the array contains pointer-to-function data types (with one level of indirection), thus you must use a pointer-to-pointer-to-function data type (with two levels of indirection) in order to point at the array itself. Had the array contained pointer-to-pointer-to-function data types (where each pointer points to a separate array of pointer-to-function data types), then you'd use three levels of indirection, and so on. You increase the level of indirection by placing an additional asterisk before the pointer's name when you declare the pointer. That is, one asterisk per level.
If the array is static you can simply point at the first element. For dynamic arrays you can allocate a contiguous block to a single pointer which can then be subdivided using a one-dimensional array of pointer to pointers, each of which points to a one-dimensional array of pointers, each of which points to a separate object within the array. For extremely large arrays, however, it is better to split the elements into separate one-dimensional arrays, by creating a one-dimensional array of pointer to pointers first, then allocating each of those pointers to a separate one-dimensional array of pointers, each of which points to a separate one-dimensional array of objects. Either way, you must destroy all the individual arrays in the reverse order of creation.
No.
Function Pointers are basically used when we want to select a function which is to be used dynamically at run time.AnswerFunction pointers are the only way for "Interept programming". In UNIX all the Interepts are called using function pointers. This is mainly used in system programming. Answerits nothing but a pointer to function. which is similar to ptr to a variable, if we are saying ptr to a variable then it will hold address of the variable like that fn. ptr will have the address of the function.. one of the major application of the function pointer is call back function.. i.e callback.AnswerPointers to functions/methods/subroutines aka 'Delegates' are frequently used in .NET programming especially in EventHandling, MemberInvoking A function pointer is used to pass a function as an argument to another function, or to store a function as a data item, for example a list of functions can be implemented as an array of pointers to functions. Function pointers are used to store interrupt handlers in tables.
A pointer is normally considered an atomic data type. Therefore, a pointer cannot "be indexed like an array" in that it is not possible to access portions of a pointer through an index. However, a pointer can point to data which can be accessed through pointer operations as well as through index operations. Further, multiple pointers can be arranged in an array of pointers, and each individual pointer within that array of pointers can be reached through its array index. Example 1: an array of pointers const char* const array_of_pointers[] = { "Hello, World", "Hello, Venus", "Hello, Mars" }; In this example, each of array_of_pointers[0], array_of_pointers[1] or array_of_pointers[2] evaluates to one pointer, selected with the array index 0..2. Example 2: access to data through pointer using an array-style index void example(char* const text) { *text = 'a'; // set first character pointed to to 'a' *(text+1) = 'b'; // second char becomes 'b' // the following are equivalent to the above, but use index notation: text[0] = 'a'; text[1] = 'b'; } Key to example 2 is the declaration of the pointer as a constant pointer.
In C, arrays are always passed by reference. This is, if you have an array value, and you pass it as the argument to a function, you are actually passing a pointer to the first element in the array, and modifications to the array from inside the function will be seen by the caller.
AnswerI take it you are using some version of c,c++,visualC etc etc. One thing that is standard is pointers. A pointer is the address of a memory space that holds information in that specific space. By referencing the pointer in your code, you can print out that specific bit of information that the poiner is actually pointing to. Hope this helps
Pointer is a variable which points to the address of another variable. Pointers come handy when we are left with no choices such as calling a function using "pass by reference" method, using memory allocated dynamically etc...
It is not possible to declare a two-dimensional array using an array of pointers in any programming language, but many programming languages support declarations of N-dimensional arrays of pointers.The exact syntax varies with the programming language, and requires support for N-dimensional arrays and pointers. In C, the following declares an array of pointer variables, each implemented as pointer to the generic type "void":void* array_1D[10];The type of the expression array_1D is "void * const."The following example expands on the previous one by declaring a two-dimensional array of "void" pointers:void* array_2D[10][20];The type of the expression array_2D is "void ** const."The last example declares a 3-dimensional array of "void" pointers, which can be seen as a 2-dimensional array of arrays of pointers:void* array_3D[10][20][30];
I guess you wanted to ask, why is it scanf ("%s", array)and not scanf ("%s", &array).Well, array is by definition a pointer to the first element: array = &array[0]
If you have shaky hands, a laser pointer can be very distracting.
Yes, a linked list can be implemented in an array. Instead of pointers (or references in JAVA) you can use element indexes in the "next" and "last" items.This does not stop you from using pointers or references. They still work. You can take the address of an element of an array, such as &a[217], and place that in the .next or .last pointers, and manage the relationships in the normal way. Using an array is simply one way to manage memory.