Best Answer

char c[3]; //array of 3 chars

char * p; //pointer of type char

p=c; //point the pointer to the base of char array

User Avatar

Wiki User

โˆ™ 2012-09-06 06:02:29
This answer is:
User Avatar
Study guides

Data Science

See all cards
7 Reviews

Add your answer:

Earn +20 pts
Q: How do you declare A pointer to array of three chars?
Write your answer...
Still have questions?
magnify glass
Related questions

How do you declare An array of three pointers to chars?

char* my_array[3]; /* an array of three pointers to char */

How do declare the following a An array of three pointers to chars b An array of three char pointers c A pointer to array of three chars d A pointer to function which receives an int point?

char* a[3]; char* b[3]; char[3] *c; void(*d)(int*); Note that these are definitions. To make these declarations only, use the keyword 'extern'.

How do you declare the following An array of three pointers to chars An array of three char pointers A pointer to array of three chars A pointer to function which receives an int pointer?

Please ask just one question at a time!Question 1:How do you declare an array of three pointers to chars?How do you declare an array of three char pointers?Note: both of these questions are merely alternative wordings for the same question.Answer 1:char * a[3];Question 2:How do you declare a pointer to an array of three chars?Answer 2:char a[3]; // an array of three charschar * p = a; // a pointer to an array of three charsQuestion 3:How do you declare a pointer to a function which receives an int pointer?Answer 3:#include // some functions we can point at:void func_1(int * p){}void func_2(int * p){}// note: all functions we wish to point at with the same// pointer must have the same main(){int* p = NULL; // instantiate an int pointervoid (*pFunc) (int*); // declare a function pointerpFunc = func_1; // point to func_1pFunc(p); // call func_1 via function pointerpFunc = func_2; // point to func_2pFunc(p); // call func_2 via function pointerreturn(0);}Note that the brackets in the function pointer declaration are required. If you omit them, you will end up with a standard function declaration that returns a pointer to void, resulting in a compiler error.

How do you create a pointer to an array of function pointers?

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.

How will you declare an array of three functions pointer where each function receives two ints and returns a float?

float (*fn[3])(int,int)

How do you declare an array of three char pointers?

int main() { char *array[3]; // This declares an array of type char*of size 3 // Declare two random chars char example0 = 'X'; char example1 = 'Y'; // You can use the char* array elements just like any regular char* array[0] = example0; array[1] = example1; printf("array[0] = %c, array[1] = %c\n", array[0], array[1]); // Prints X, Y array[0] = example1; array[1] = example0; printf("array[0] = %c, array[1] = %c\n", array[0], array[1]); // Prints Y, X return 0; }

How do you declare An array of three pointers to char?

char * p[3];

Can an array of pointers represent multidimensional array?

Yes. More specifically, they can be used to represent a dynamic multi-dimensional array. As most people know, for a one-dimensional dynamic array, you simply need a pointer to the first element in the array, where each element contains an object of the same type as the pointer. The pointer can be passed around functions just as if it were a static array, the only difference being the requirement to pass the upper bound of the array as well as the array itself. For a two-dimensional array, you need a pointer-to-pointer which points to the first element of a one-dimensional pointer array, where each pointer in that array points to a one-dimensional array of objects. The pointer-to-pointer must be the same type as the pointers and the objects. For a three-dimensional array you need a pointer-to-pointer-to-pointer. And so on. Each additional dimension simply adds a new level of indirection, and a new level of one-dimensional pointer arrays. Of course multi-dimensional arrays are only useful if every dimension is fully utilised and doesn't require too much in the way of resizing. If that is not the case, then you may get more efficient memory consumption from a vector of vectors (of vectors), which allows dynamic resizing at every level without having to copy existing elements. The downside is you lose the random access provided by the array.

How can single dimensional and two dimensional array concepts be explained?

If you imagine a standard chessboard, a one-dimensional array representing each of the squares on the board would need to contain 64 elements (numbered 0 to 63). However, because the board itself is two dimensional, it makes more sense to refer to individual squares by the intersection of the square's row and column. Thus a two dimensional array will contain 8 rows and 8 columns (each of which is numbered 0 to 7). Another way to look at a two-dimensional array is to imagine that first dimension represents a one-dimensional array of rows while each of these row elements is itself a one-dimensional array of squares, with one square per column. This may seem counter-intuitive at first, but when dealing with dynamic arrays, that may be exactly how the array is allocated. That is, while a static array always occupies contiguous memory locations (regardless of how many dimensions), a dynamic array is often allocated one dimension at a time. Each one-dimensional array will itself be contiguous, but the array as a whole may not be. However, regardless of how the memory is mapped, the dimensions make it easier to determine which individual element you are accessing. If our board were declared as a one-dimensional array, accessing element[24] doesn't immediately tell us which row or column that element resides in. Whereas element[4][0] tells us exactly which row and column the square is in. These are, in fact, the same square (and therefore the same element), but the second is more intuitive as there's a direct correlation between the array and the object it represents (an 8x8 chessboard). Arrays aren't restricted to just one or two dimensions. A three-dimensional array might be used to represent a cuboid. For instance, a standard 3x3x3 Rubik's cube might be represented by a three-dimensional array where each dimension has three elements (if we conveniently ignore the fact a Rubik's cube is not a real cube with 27 individual cubes). We can also go beyond 3-dimensions without the need for a Degree in Theoretical Physics. The trick is to remember that each dimension is itself a one-dimensional array. Therefore a four-dimensional array can be thought of as a one-dimensional array where each element is a three-dimensional array. A five-dimensional array is therefore a one-dimensional array where each element contains a four-dimensional array, and so on. Once you're familiar with this way of thinking, it no longer matters if the array is allocated contiguously or separately. Every element is addressable by its unique index, whether that index contains one or multiple dimensions. Dynamic arrays are a bit more difficult to work with, particularly when there are multiple dimensions to consider. However, the simplest way to manage them is by allocating a one-dimensional array for the entire array (multiplying all the dimensions together), and then use a separate array of pointers to divide the larger array into its individual dimensions, and finally maintain a pointer-to-pointer variable to refer to the array of pointers. So, going back to our chessboard example, if we suppose the chessboard is not restricted to 8x8 squares, a static array would be no use as it couldn't cater fora 9x9 board. Se we need a dynamic array. We begin by declaring a pointer-to-pointer and allocate a 9-element array of pointers to it. We then allocate an 81-element array to the first pointer. The other 8 pointers are then assigned an address within the 81-element array, such that each is offset by 9 elements from the previous element. Now we can access the array itself using the pointer-to-pointer, just as if it were a static array. If the pointer-to-pointer were named board, then board[1][2] would access the square in the second row, third column. This works because the [1] refers to the second pointer in the pointer array (which points to the second row in the array), while the [2] refers to the third element in that row. The language is such that we need not concern ourselves with the fact an array of pointers exists but, without it, we'd not be able to access the array multi-dimensionally. An alternative way to allocate the array would be to allocate individual one-dimensional arrays to each pointer in the pointer array (where each array represents a row on the board). However, because this would require 9 separate allocations, the creation of the array as a whole takes much longer than it would with the single allocation. In addition, releasing the array is much simplified as we only have to release the entire array (pointed to by the first element in the pointer array), and then release the pointer array itself. Using individual allocations would mean releasing each pointer in the pointer array before release the pointer array itself. Regardless of how the array is allocated, accessing the individual elements is achieved in the same way, via the pointer-to-pointer. It does not matter if the array resides in contiguous memory or not -- the pointer array takes care of all that for us automatically. Moving onto three dimensions and beyond is only complicated by the fact the pointer-to-pointer requires an extra level of indirection for each additional dimension. That is, a pointer-to-pointer-to-pointer is required for a three-dimensional array, which points to an array of pointer-to-pointer, each of which points to an array of pointer, each of which points to an appropriate offset within the actual array. Why bother with just two? Think about 27+(just to begin with) different dimensions & inter Universal expansionsional change regarding 'PURE ENERGY the form of Dark Matter & it's direct correlation with it's inter-actional Relationship to CREATION & ALL Eternity should be able to do that over lunch:)) 'Doc' is just fine:) Pick your Wavelength & the several Frequencies contained therein..........& GO FOR IT. You have talent.

When does an array behave like a pointer in C plus plus -- provide sample code to support each case?

An array never behaves like a pointer.Understand that a pointer is a variable -- no different to any other variable, other than its type. like any other variable, it is allocated its own memory (4 bytes in a 32-bit system). Those 4 bytes can store any 32-bit value, from 0x00000000 to 0xFFFFFFFF, but because it is declared to be a pointer, that value actually represents a memory location, somewhere within the 4GB address space. 0x00000000 is a reserved memory location -- what we refer to as NULL.An array is not the same as a pointer in any sense. The array name refers to the actual memory (the starting address) where the array resides. But the array name is not a variable -- unlike a pointer, it is not separate from the memory it refers to -- it is merely an alias that refers to the memory allocated to the array itself.That said, pointers and arrays can appear to be the same. For instance, the strlen() function expects you to pass a const char pointer, and yet you can pass an array name instead and it works just fine:char cArray[12];char * p = cArray;strlen( p ); // Pass a pointerstrlen( &cArray[0] ); // Pass pointer to array element via AddressOf operatorstrlen( cArray ); // Pass an array nameAll three of these functions work exactly the same so it would be easy to assume the array is a type of pointer. But it is not. To understand what's really going on here you have to understand how pointers and arrays are actually passed to function.When you pass a pointer to a function, you don't pass the pointer itself, you pass the memory address stored in the memory allocated to the pointer. In other words, pointers are passed by value, not by reference. Similarly, when you pass an array name, you pass the starting address of the array.That's all there is to it! The function's parameter, a pointer, is allocated its own memory. It is a temporary variable, local to the function. All it expects is a memory location so whether you pass a pointer or an array name, that's exactly what it receives.

What are array linear data structures?

All arrays are linear data structures, as are all lists. Arrays are linear because multiple elements are allocated in contiguous memory. If the array is a pointer array, only the pointer array need be contiguous; the data being pointed at can reside anywhere in memory, whether contiguous or not (you might use a separate pointer array to indirectly alter the order of elements in another array). Large and dynamic multi-dimensional arrays are typically allocated as a large array of pointers each of which points to a small array of data elements. For instance, a four-dimensional array might be allocated as a contiguous three-dimensional array of pointers, each of which points to a separately allocated one-dimensional array of data elements. Although this uses more memory overall to cater for all the pointer variables, allocating separate memory to each one-dimensional array is more likely to succeed than if all the elements were allocated as a contiguous multi-dimensional array, especially if the individual data elements are quite large.

How does two dimensional array differ from single dimensional array?

A one dimensional array is a scalar value repeated one or more times.A two dimensional array is an array of one dimensional arrays.A three dimensional array is an array of two dimensional arrays, and so forth.The one dimensional array is like a list of things, where the two dimensional array is like an array of things. (Think one row of a spreadsheet versus the whole spreadsheet.)[addendum]Every level of array depth is also a level of pointer depth. For example: A 3 dimensional int array is an int***. So a one dimensional int array is an int*, and a two dimensional int array is an int**. This is only important if you are doing pointer work, but it can become very important.

People also asked