Setting array to null




















Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. You can store multiple variables of the same type in an array data structure. You declare an array by specifying the type of its elements.

If you want the array to store elements of any type, you can specify object as its type. In the unified type system of C , all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object.

Array is the abstract base type of all array types. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 9 years, 2 months ago. Active 3 years, 3 months ago. Viewed 56k times. Improve this question. Hovercraft Full Of Eels k 25 25 gold badges silver badges bronze badges. Chin Chin You're fooling yourself. Variables in Java are not objects, though but rather references to objects. In Java, objects can never be variables. Add a comment. Active Oldest Votes. Improve this answer.

Newbyte 1, 4 4 gold badges 17 17 silver badges 35 35 bronze badges. I see no dynamic allocation here, though it makes sense that you assume there will be. However, this is wrong; delete array[0]. Sure, that cleans up after the first element, but what about the others? I think it's best to be very clear when dealing with a beginner.

The OP may take that to mean that delete array[0] is all you need, which is wrong. I think it doesn't make sense, right? I think there is probably a better way to solve your problem here, but you'd need to expand on the question a bit. Chin: No, arrays are fixed in size at compile time. Originally Posted by kotoko. Originally Posted by itCbitC. Look at the memset call to initialize the array of task structs or a particular element thereof to NULL.

Thanks for the heads up with the pointer problem, I'm adapting from a threads program so I didn't notice that yet. I guess I'll just substitute that with the index of the array, that might be simpler. Originally Posted by matsp. Well, you can set all elements to zero - if some implementation of compiler decides that NULL is actually internally represented by something other than zero, you may be in trouble.

So whilst that may well cause the memory to be filled with the zero value, it is not guaranteed that Code:. Admittedly, I'm picking holes by pedantery, but if I'm sure someone else would shove the same argument down my throat if I made such a suggestion. Last edited by itCbitC; at AM.

Originally Posted by Bjarne Stroustrup I get maybe two dozen requests for help with some sort of programming or design problem every day.

Most have more sense than to send me hundreds of lines of code.



0コメント

  • 1000 / 1000