Switch to full style
C++ code examples
Post a reply

Variable Size Arrays

Thu Nov 13, 2008 3:08 pm

define an array size but with a dynamic and variable way.
cpp code
#include <stdio.h>

// Read in the indicated number of numbers, then print them backwards.
void rne(int arr[], int size)
{
for(int i = 0; i < size; ++i)
scanf("%d", &arr[i]);

printf("----------------------------------------------------\n");
int i;
for(i = size-1; i >= 0; --i)
printf("%d ", arr[i]);
printf("\n----------------------------------------------------\n");
}

main()
{
// Allocate with new C99 variable-sized arrays.
int size;
scanf("%d", &size);
int arr[size];
rne(arr, size);
}




Post a reply
  Related Posts  to : Variable Size Arrays
 different between Local variable and Global variable     -  
 Set image size as a percentage of the page size     -  
 transient variable     -  
 Unset variable     -  
 PHP variable in javascript     -  
 Variable interpolation     -  
 Passing a Reference Variable     -  
 Testing the Type of a Variable     -  
 Delete session variable     -  
 how to call a global variable?     -  

Topic Tags

C++ Arrays