![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| The Following User Says Thank You to MrPickle For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| |
| ||||
| What about Code: Function(int[] myArray); |
| The Following User Says Thank You to HelloWorld For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| ||||
| I know how to parse arrays, I wanted to know whether you could pass individual variables straight into an array. |
| The Following User Says Thank You to MrPickle For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| ||||
| Quote:
calling Function(1, 3, 2, 1, 0); then they would be put straight into an array in Function's arguments. |
| The Following User Says Thank You to MrPickle For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| ||||
| something like.. Code: Function (int a, int b, int c, int d, int e)
x[0] = a;
x[1] = b;
x[2] = c; // ... and so on Last edited by HelloWorld : 05-21-2008 at 02:36 PM. |
| The Following User Says Thank You to HelloWorld For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| |||
| Its still not entirely clear to me what exactly you want to do - Are you trying for array initialisation? Code: int my_arr[] = { 1, 2, 3, 4, 5, 6, 7 }; |
| The Following User Says Thank You to Bench For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| ||||
| It's hard to explain. I want to know if it's possible to put pass variables, straight into an array that is the argument of a function. Argh, that doesn't explain it. If I declared a function like: Code: void MyFunction(int MyArray[]){} Maybe this explains things: Code: #include <iostream>
using namespace std;
void MyFunction(int MyArray[]){
cout << MyArray[0] << endl;
cout << MyArray[1] << endl;
cout << MyArray[2] << endl;
}
int Main(){
MyFunction({1, 4, 6}); //Something or another
return 0;
} Quote:
|
| The Following User Says Thank You to MrPickle For This Useful Post: | ||
vikramsony (05-24-2008) | ||
| |||
| No, that's not possible, since a function will only accept an array parameter by way of a pointer-to its first element. a pointer is an address in memory, which implies that an array must already exist in memory before you may pass it to a function. Perhaps you could give a broader view of the problem you're trying to solve, and someone might be able to suggest how to deal with it. |
| The Following 2 Users Say Thank You to Bench For This Useful Post: | ||
MrPickle (05-22-2008), vikramsony (05-24-2008) | ||
| ||||
| It wasn't a problem, I was just curious to as how you could do it if it's possible. My assumption was that you'd already have to have an array defined. Thanks. |
| The Following User Says Thank You to MrPickle For This Useful Post: | ||
vikramsony (05-24-2008) | ||
![]() |
| Thread Tools | |
| Display Modes | |
| |