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.

Recommended Answers

All 3 Replies

Member Avatar for MonsieurPointer

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?

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.