Structure deleting

Hi!

Can anyone tell me how to delete a structure?


struct student{
int id,age; 
};
int main(){

struct student abc[50]; //input data of three students
int a,b,flag=0,z,x;
for(a=1;a<=3;a++){
                  printf("\nID no.:\t");
                  scanf("%d", &abc[a].id);
                  printf("\nAge:\t");
                  scanf("%d", &abc[a].age);
}
 
printf("\n[1]Print");
printf("\n[2]Delete");
printf("\nEnter choice: ");
scanf("%d",&x);


There are 2 choices for me to do one is print and the other is delete.
Can you tell me how can I do the delete function? I already know how to print.
Last edited on
When you create a variable on the stack (which you do when you make it without using new or static) it is tidied away at the end of scope. You cannot remove it otherwise.

What do you want to happen? What do you mean by "delete"? Do you mean you want that memory back to use for something else? Do you mean you want to reset the value to some zero value?

While I'm here, main() is just plain wrong. Use int main()
Last edited on
Yes I want the memory back to be used for something else, is that possible?
Let it die at the end of scope. If you must reuse the memory within scope, you can do so only if you create the object with new. You can then mark the memory as available for reuse with delete.

However, unless you're working on some kind of embedded hardware with really, really restricted memory, it's pointless. You've got so much memory that worrying about a handful of ints is just silly. Really, really silly.
Last edited on
Topic archived. No new replies allowed.