0

Hi folks,

int a=10,b=5,tmp;
tmp=a;
a=b;
b=tmp;

This is ordinary swap. I want to do this swap to the structure variables. And how to free the memory of tmp structure variable after swapping.

4
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by WaltP
0

Hi folks,
This is ordinary swap. I want to do this swap to the structure variables. And how to free the memory of tmp structure variable after swapping.

I neither see a structure nor a pointer of any type. Care to elaborate?

0

It will depend on the contents of the structure and how it was allocated. Post the structure and appropriate code to get better comments.

Edited by Ancient Dragon: n/a

0

Hi folks,

int a=10,b=5,tmp;
tmp=a;
a=b;
b=tmp;

This is ordinary swap. I want to do this swap to the structure variables.

Make tmp an instance of the structure. Move each element as you swap.

And how to free the memory of tmp structure variable after swapping.

Why? It's not necessary.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.