ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm not sure what you're asking. arr[] is obviously an array of some type, and i is presumed to be a variable of some type too, but you don't indicate what type of array arr is or why type of variable i is. If I had an array of integers, and a variable i that was an integer. I would do the following to put i at the first index of arr[]:
Code:
int main(){
int i = 5; /* an arbitrary value */
int arr[10]; /* an array of 10 integers */
arr[0] = i; /* assign value i (which = 5) to the first index in arr[] */
return 0;
}
If arr[] = i has a meaning, I don't know what it is. If you have an array arr[] then arr points to the beginning of the array, not arr[]. Similarly, if you are assigning values then you can say arr[n] = i, and also in the declaration you can say int arr[] = {i}, but not arr[] = i.
arr[] = i is not valid c++ as far as i can work out, ive tried to do it by overloading the [] operator but it doesnt work because [] has to have one argument and it cant be a default argument
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.