hi
if some one know the asnswer of this question then send me
thnaks
macros in which swap two number without using 3rd variable and then call
Macro in main function
14 1752
Hi HIRA HAMEED,
Welcome to thescripts. I'm sure you will find a wealth of information available here. At this stage, I am not sure how best to classify your question, so I will pass it to the "Miscellaneous Question" forum. The experts there may have a better idea of what direction to point you in.
In future, you can access a whole host of forums by selecting from theoptions on the blue bar near the top of the screen.
I hope the experts can help you out!
Are you looking for a C/C++ macro? Or is this a macro for an application such as MS Word?
-
a = a + b;
-
b = a - b;
-
a = a - b;
-
Check out the XOR Swap Trick.
You are right, the XOR is much better suited as it will never cause an overflow: -
a = a ^ b
-
b = a ^ b
-
a = a ^ b
-
You are right, the XOR is much better suited as it will never cause an overflow: -
a = a ^ b
-
b = a ^ b
-
a = a ^ b
-
This will also not cause a overflow.See this thread
Savage
This will also not cause a overflow.See this thread
Savage
Well, it does overflow, but in C and C++ that overflow does not matter. However, in other languages you may have an exception thrown causing your program to end prematurely. With an XOR this will not happen.
Well, it does overflow, but in C and C++ that overflow does not matter. However, in other languages you may have an exception thrown causing your program to end prematurely. With an XOR this will not happen.
Well,this is a C/C++ forum after all..
:P
Savage
Well,this is a C/C++ forum after all..
:P
Savage
Check again baby, we're in the Miscellaneous forum.
Check again baby, we're in the Miscellaneous forum.
Duh!
Why did I thought this is C/C++ forum?
LOL
Duh!
Why did I thought this is C/C++ forum?
LOL
Like I have previously stated: you're crazy!
Why did I thought this is C/C++ forum?
Because we still don't know what language the original poster is using (hint, hint, HIRA HAMEED...).
Because we still don't know what language the original poster is using (hint, hint, HIRA HAMEED...).
Aha,he posted this in C/C++ forum,now I remember.
Savage
Aha,he posted this in C/C++ forum,now I remember.
Savage
You sure do have all the answers, don't you Savage?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shi Jin |
last post by:
Hi there,
While I was trying to disassemble a simple C program for my OS course, I
found that the call to function longjmp is actually called to siglongjmp
under linux.
And similarly, under...
|
by: lasek |
last post by:
Hi...in some posts i've read...something about using macro rather then
function...but difference ??.
Best regards....
|
by: baumann |
last post by:
hi all,
i defined a macro like the below
#define initSock() \
do{\
WSADATA ws_data;\
WSAStartup(0x0202,&ws_data);\
}while(0)
|
by: Simon Morgan |
last post by:
Hi,
Can somebody please help me grok the offsetof() macro?
I've found an explanation on
http://www.embedded.com/shared/printableArticle.jhtml?articleID=18312031
but I'm afraid it still...
|
by: Mockey Chen |
last post by:
I using #define as following:
#include <stdio.h>
#define LOG_PREFIX "Current function: <" __FUNCTION__ ">: "
int main()
{
printf(LOG_PREFIX "some thing.\n");
return 0;
}
|
by: Umesh |
last post by:
how to convert a program to a function/macro and put it in a header
file? is there any shortcut method for this?
thanks.
|
by: jason |
last post by:
Hi,
I learned my lesson about passing pointers, but now I have a question
about macros.
Why does the function work and the MACRO which is doing the same thing
on the surface, does not work in...
|
by: Peng Yu |
last post by:
Hi,
It is benifitical to use macro in certain cases.
http://www.boost.org/doc/libs/1_35_0/libs/preprocessor/doc/index.html
However, I found that it is not easy to debug a macro. For example,...
|
by: mdh |
last post by:
I have asked a few questions about Macros...and think what I have been
missing ...and which all who have replied clearly understand...is that
this is a Pre-processor action.
Hopefully the above is...
|
by: sh.vipin |
last post by:
how to make large macro paste the code as it is
Problem Explanation '--
For example in the program below
/* a.c - starts here */
#define DECL_VARS() \
unsigned int a0;\
unsigned int a1;\...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |