Yahoo India Web Search

Search results

  1. Jul 4, 2011 · Passing a multidimensional array as argument to a function. Passing an one dim array as argument is more or less trivial. Let's take a look on more interesting case of passing a 2 dim array. In C you can't use a pointer to pointer construct (int **) instead of 2 dim array. Let's make an example:

  2. Easiest Way in Passing A Variable-Length 2D Array. Most clean technique for both C & C++ is: pass 2D array like a 1D array, then use as 2D inside the function.

  3. Dec 14, 2014 · In func(B), you are just passing address of the pointer which is pointing to array B. You can do change in func() as B[i] or *(B + i). Where i is the index of the array. In the first code the declaration says, int *B[10] says that B is an array of 10 elements, each element of which is a pointer to a int.

  4. Nov 21, 2011 · When passing an array to a function in C, you should also pass in the length of the array, since there's no way of the function knowing how many elements are in that array (unless it's guaranteed to be a fixed value). As Salvatore mentioned, you also have to declare (not necessarily define) any structs, functions, etc. before you can use them.

  5. Sep 3, 2015 · It's pointer to an array, so in fact pointer to pointer, not a pointer to a value. first and second - there is no difference between them. I would use first one to indicate, that I am passing pointer to a char and second to indicate, that I am passing array of chars (pointer to a first char in table.).

  6. I'm new to C and I have a doubt. Since C functions create local copies of it's arguments, I'm wondering why the following code works as expected: void function(int array[]){ array[0] = 4;

  7. Some explanation: You probably know that when you pass an array to a function, you actually pass a pointer to the first member. In C language, 2D array is just an array of arrays. Because of that, you should pass the function a pointer to the first sub-array in the 2D array.

  8. May 23, 2013 · I am learning C and am having trouble passing the pointer of a 2D array to another function that then prints the 2D array. Any help would be appreciated. int main( void ){ char array[50][50]; int SIZE; ...call function to fill array... this part works.

  9. Oct 16, 2013 · When we pass an element of an array to a function, it is treated as an normal variable and the called function creates a copy of the actual argument and operates on it. Any changes made in the formal arguments doesn't affect the actual arguments.

  10. Aug 8, 2016 · When you are doing string_copy(my_array), you are passing a char (*)[100], i.e. pointer to char[100] array to your function. But your function is expecting a char *[], i.e. array of char pointers, because you have defined your function that way.

  1. People also search for