4. Arrays as function parameters #

Created Wednesday 13 November 2019

Declaring and defining the variables in the same statement:

  1. data_type arr_name[] = { val1, val 2,…}; // creates an array of size = number of values n braces
  2. data_type arr_name[arr_size] = { val1, val 2,…val n}; // creates an array of size arr_size(assuming no. of values <= arr_size). Also the first n elements of the arrays are initialized to val1 val2 … val n. An the remaining are initialized to 0. Remember this.

Q) Reversing an array. Swap n/2(floored) times. On Both sides A) for(int i=0, j=n-1, a = 1; a<=n/2; a++, i++, j–) { int temp = arr[i]; ar[i] = arr[j]; arr[j] = arr[i]; }