answersLogoWhite

0

How is a10-element char array declared?

Updated: 8/19/2019
User Avatar

Wiki User

13y ago

Best Answer

char myCharArray[10];

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How is a10-element char array declared?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you convert char array into unsigned char array in c?

You can't convert the data type of any variable.


What type of data is held in a string?

String in C is basically a Character 1-D array, whose last character is a NULL ['\0']. It is declared as follows: char array_name[size]; Ex. char wiki[10];


How do you declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

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 signature.int 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.


What is return type of string in c?

In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').


What are the parts of an array?

Its type, name and number of elements. char example[12]; // a char array, named 'example' with 12 elements. The name is also a reference to the array itself, referring to the first element in the array (e.g., example == &example[0]).


What is an array pointers?

I guess it is an 'array of pointers'. Example:int main (int argc, char *argv[])


Give an example of a multi dimensional array in Cpp?

// 2 dimensional array (a sudoku puzzle): char sudoku[9][9]; // 3 dimensional array (100 sudoku puzzles): char sudokus[100][9][9]


How is an array specified?

int a[100]; char b[50];


What will be the signature of the function that returns three-dimensional array char arr234?

You cannot return an array by value as all arrays (including multi-dimensional arrays) will implicitly degrade to pointers, so they must be returned by reference instead. However, you cannot return the address of a local variable as that variable will fall from scope when the function returns, so the memory is no longer valid. Therefore the array must be allocated dynamically, on the heap. You cannot create multi-dimensional arrays on the heap as easily as you can on the stack or in static memory. Essentially you need three separate arrays. The first holds all the actual elements and is allocated by multiplying all the dimensions together with the size of each element. Thus to dynamically allocate the equivalent of a char[2][3][4] array, you would actually allocate a char[24] array (2*3*4=24). char* array1 = malloc (2*3*4*sizeof(char)); The second array holds pointers into the first array. This array is the equivalent of a char*[2][3] array, but is actually allocated as a char*[6] array (2*3=6): char** array2 = malloc (6*sizeof(char*)); Once you have this array you need to initialise the pointers so they each point into the first array, where each pointer refers to the start address of a group of 4 elements: for (int i=0; i<6; ++i) { array2[i]=&array1[i*4]; } Finally, you can allocate the third array which holds pointers into the second array and is equivalent to a char**[2] array: char*** array3 = malloc (2*sizeof(char**)); Again, the pointers must be initialised to point into the second array, where each pointer points to the start address of a group of 3 pointers: for (int i=0; i<2; ++i) { array3[i]=&array2[i*3]; } Putting this all together, we can create a function that dynamically allocates a three-dimensional char array of any size: char*** create_array3d (unsigned d1, unsigned d2, unsigned d3) { int i; char* a1 = malloc (d1*d2*d3*sizeof(char)); char** a2 = malloc (d1*d2*sizeof(char*)); char*** a3 = malloc (d1*sizeof(char**)); for (i=0; i<(d1*d2); ++i) { a2[i]=&a1[i*d3]; } for (i=0; i<d1; ++i) { a3[i]=&a3[i*d2]; } return a3; } Thus the signature for this function will be: char*** create_array3d (unsigned, unsigned, unsigned); The problem with this function is how we go about releasing the memory given we only have one pointer. The easiest way is to create another function: void release_array3d (char*** ptr) { free (ptr[0][0];) free (ptr[0]; free (ptr); } To demonstrate how we might use these functions, consider the following: int main (void) { const int d1=2; const int d2=3; const int d3=4; int x, y, z; /* instantiate array */ char*** array = create_array3d (d1, d2, d3); /* initialise it with some values */ for (x=0; x<d1; ++x) for (y=0; y<d2; ++y) for (z=0; z<d3; ++z) array[x][y][z] = (x+1)*(y+1)*(z+1); /* perform other operations on array */ /* ... */ /* release array */ release_array3d (array); array = 0; return 0; } Note how we can access the array elements just as if the array were allocated on the stack or in static memory and that the functions hide all the (low-level) implementation details from the user.


How string constants are declared in c?

Some strings are constants, others aren't; some constants are strings, other aren't. So these are unrelated things. Examples: "text" -- constant string 123 -- constant number char s[40] -- variable string


How do you declare an array of five pointers to chars?

char *p="ragav"


How many constructors are there for the string class?

The String class has multiple Constructors. Some of them are: 1. String - new String(String val) 2. Character Array - new String(char[] array) 3. Character Array with index positions - new String(char[] array. int start, int end)