Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (lgbasallote):

can someone teach me how to do arrays in C?

OpenStudy (lgbasallote):

i just need the basic idea of the syntax for arrays

OpenStudy (anonymous):

it depends on what type of arrays you are looking for: int array you can have something along the lines : int a[size]; or int a[] ={1,2,3,4,5,6,7...} or you could have a dynamical array ( use of pointers) int*a=new int[size]

OpenStudy (lgbasallote):

is it possible to have an array with no limits?

OpenStudy (anonymous):

it depends. for an array of which you don't know the size at compilation, you should use the dynamical array(created with pointers). in c++ you must have a fixed sized array. for "infinite" size you could opt to use python and do something like: a=list() and a.append(item) and then you could just use this syntax to do your bidding. but for c/++ you must declare either a static size int a[10] for instance, or int *a=new int[size_you_want]

OpenStudy (lgbasallote):

well then nevermind that. suppose i have a definite size. how should i introduce the array?

OpenStudy (anonymous):

what array do you need? int float double char?

OpenStudy (lgbasallote):

it might be interesting to know a summary what those are

OpenStudy (anonymous):

what do you want to do with the array? store numbers? letters?

OpenStudy (lgbasallote):

well i'm still just practicing so my idea is that the program asks the user how many numbers he wants to input and then the program asks the user for those n numbers

OpenStudy (lgbasallote):

i tried this main() { int a[100]; int b, c, d; printf("How many numbers do you want? "); scanf("%d", &c); for (b=1; b<=c; b++) { printf("\nEnter number %d: ", b); scanf("%d", d); }

OpenStudy (anonymous):

#include <iostream> using namespace std; void askNumbers(){ int a; cout<<"How many numbers do you want to enter?"<<endl; cin>>a; float *b=new float[a]; for(int i(0);i<a;++i){ cout<<"Enter "<<i<<" number"<<endl; cin>>b[i]; } for(int l(0);l<a;++l) cout<<b[l]<<" "; delete []b; } int main() { askNumbers(); return 0; }

OpenStudy (anonymous):

just an exemple

OpenStudy (lgbasallote):

that looks like c++ codes?

OpenStudy (lgbasallote):

are they?

OpenStudy (anonymous):

well yes, but you can replace cout by stdout or printf it's the same thing

OpenStudy (lgbasallote):

im not really used to those codes...

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!