answersLogoWhite

0

It is possible, if it is a dynamically allocated array:

int n= 0; Elem *p= NULL;

...

AddElem (Elem newval)

{

n += 1; p = (Elem *)realloc (p, n*sizeof (Elem));

p[n-1] = newval;

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Appending array elements using function in c plus plus programming?

#include<iostream> void append(std::vector<int>& v, int i){ v.push_back(i); } int main() { std::vector<int> v; append( v, 100 ); // same as calling v.push_back(100); return(0); }


What is the syntax for determining the size of an array in C using the keyword sizeof?

To determine the size of an array in C using the keyword sizeof, you would use the syntax: sizeof(array) / sizeof(array0).


Find largest value algorithm in c?

** pseudo code ** if array length == 1, return first element else if array length > 1 max = first element for second item to last item if item > max max = item return max else // array length is 0 error


How do you find matrix in c?

using multidimensional array


Can you give an example of array using character variable in c program?

the example of array over charcter variables is char ["string"]


How do you make a C plus plus program that arrange the the numbers in ascending order?

Heres something i whipped up in a hurry... This uses the Bubble Sort method found (related links) #include <iostream> using namespace std; int main(int argc, const char* argv) { int arraysize = 5; //Unsorted array size int array [] = { 5, 3, 4, 2, 1 }; //The array of numbers itself //Display the unsorted array cout << "Before: {"; for (int c=0; c <= arraysize; c++) { cout << array[c]; if (c != arraysize) { cout << ","; } } cout << "}" << endl; //Acctually sort the array int tmp=0; //Used for swaping values for (int loop=0; loop <= (arraysize - 1); loop++) { for (int c=0; c <= (arraysize - 1); c++) //The sort loop { if (array[c] > array[c + 1]) { //Swaps the two values in the array tmp = array[c]; array[c] = array[c + 1]; array[c + 1] = tmp; //Cleanup tmp = 0; } } } //Display the sorted array cout << "After: {"; for (int c=0; c <= arraysize; c++) { cout << array[c]; if (c != arraysize) { cout << ","; } } cout << "}" << endl; return 0; }


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i < array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }


What is the array of string in c?

A string in C is stored in a 1 dimension array so an array of strings is simply a two dimension array.


Sorting an array in PHP without using sort function?

plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++


Is it possibly to return an array of strings in a function without using pointers in C plus plus?

No.


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....