i was trying to declare an array first then push value like these #include<iostream> using namespace std; int main() { unsigned var[]; var[0] = 56; var[1] = 569; var[2] = 2; } Code (markup): why its not working??
tnx but Array length is unknown i mean in this example i used only 3 but in real script it cud be more or less.. allocate memory for it runtime whts tht? how can u do tht? any example? sorry im novice at c++
Ok int main() { int *var; //pointer to int int array_length = 3; //array length. this variable can be calculated var = new int(array_length); //allocate memory to array according array_length var[0] = 56; var[1] = 569; var[2] = 2; } Code (markup):
tnx again mate but still error wht im trying to do here is my code #include <iostream> using namespace std ; int main() { int first; int second; int n=1; //maybe i hav to declare array variable here int allFirst; int allSeconds; do { cout << "enter first number: "; cin >> first; allFirst[n] = first; cout << "enter second number: "; cin >> second; allSecond[n] = second; n++; }while(first > second); } Code (markup): so, its unknown how many loops...so whts arrays lengths. its varies i hav to store all the inputs using Array. cant use another method & although in example i used only int, i might have to add char, unsigned etc also plz help (
Ushould use dynamic memory allocation. small example in c int *ptr,len; printf("Enter the size of array u want\n"); scanf("%d",&len); ptr = malloc(len*sizeof(int)); then u can access ptr i starting from 0 to len .... This is simple c program buddy