C±ê×¼¿âº¯ÊýabsµÄÒ»¸ö´íÎó
0x80000000£¬¼´–2147483648ʱ,¶ÔËüÈ¡¸º»á²úÉúÉÏÒç
VC.NET 7.1 ÌṩµÄÈ¡¾ø¶ÔÖµº¯Êý(abs.cÖÐ)ÈçÏ£º
¡¡¡¡ int __cdecl abs ( int number)
¡¡¡¡ {
¡¡¡¡ return( number>=0 ? number : -number );
¡¡¡¡ }
¡¡¡¡ ´Ëº¯ÊýʵÏֵ÷dz£¼òµ¥£¬Õ§¿´Ö®ÏÂÎÞÈκÎ벡£¬¿ÉÊÇ×Ðϸ×ÁÄ¥×ÁÄ¥£¬¾Í·¢ÏÖÁËÒ»¸ö´ó©¶´¡£¾Ù¸ö¼«¶ËµÄÀý×Ó£¬µ±º¯Êý²ÎÊýΪINT_MIN(32λµÄint´ËֵΪ0x80000000£¬¼´–2147483648)ʱ,¶ÔËüÈ¡¸º»á²úÉúÉÏÒ磬ÒòΪ32λµÄintÄܱíʾµÄ×î´óÕýÊýÊÇINT_MAX(0x7fffffff£¬¼´2147483647)¡£Êµ¼ÊÉÏ£¬¶ÔINT_MINÈ¡¸ºµÈÓÚʲôҲûÓиÉ(0x80000000°´ÕÕ²¹ÂëÈ¡¸º¹æÔò»¹ÊÇ0x80000000)¡£ÒòΪº¯ÊýÉùÃ÷µÄ·µ»ØÖµÒ²ÊÇint£¬ËùÒÔ´ó¶àÊýʱºò³ÌÐòÔ±»áÓÃij¸öint±äÁ¿À´½ÓÊÕÕâ¸ö·µ»ØÖµ£¬µ«ÊÇÈçÉÏËùÊöµÄ¼«¶ËÇé¿öÔò¼¸ºõ°Ù·Ö°ÙµØµ¼Ö³ÌÐò»ìÂÒ¡£
¡¡¡¡ ¼òµ¥µÄ½â¾ö°ì·¨¾ÍÊÇ×ÜÊÇÓÃunsigned intÀàÐ͵ıäÁ¿À´½ÓÊÕ·µ»ØÖµ¡£ÒòΪ32λµÄunsigned intµÄÖµÓò·¶Î§ÊÇ0µ½4294967295(0xffffffff),2147483648ÂäÔÚÕâ¸ö·¶Î§ÄÚ£¬ËùÒÔÓÃunsigned int±äÁ¿¿ÉÒÔÕýÈ·µØ±í´ïINT_MINµÄ¾ø¶ÔÖµ¡£Èç¹û¾õµÃÕâÖÖ×ö·¨ÈÝÒ×Íü¼Ç£¬»¹¿ÉÒÔ×Ô¼ºÐ´Ò»¸öabs£¬Ö»ÐèÔÚÉÏÊöº¯ÊýÌåµÄÇ°Ãæ¼ÓÒ»¾äassert(number > INT_MIN)¾ÍÐÐÁË£¬»òÕß½«·µ»ØÖµ¸Ä³Éunsigned intÀàÐÍ¡£
¡¡¡¡ ΪʲôÔÚ±ê×¼¿âÖлá³öÏÖÕâôÒþ±ÎµÄ©¶´ÄØ£¿ÒòΪ¼ÆËã»úµÄ´æ´¢¿Õ¼äÓÐÏÞ£¬ËùÒÔCÖеÄÿÖÖÀàÐÍËùÕ¼×Ö½ÚÊýÒ²ÐëÊÇÓÐÏÞ´óС£¬ÕâÑù³ÌÐòÓïÑÔÖеÄÀàÐÍÕæÕýÄܱíʾµÄÖµÓò¾ÍÊǶÔÓ¦ÊýѧÀàÐÍÖµÓòµÄÓÐÏÞ×Ó¼¯ÁË¡£Õâ¾ÍÊÇÏÖʵÓëÀíÏëµÄ²î¾à¡£²»½öÈç´Ë£¬ÒòΪÓзûºÅÀàÐͱÈÎÞ·ûºÅÀàÐͶದ³öÒ»¸ö¶þ½øÖÆλÀ´±íʾ·ûºÅÐÅÏ¢£¬ÔòËüÃÇÄܱíʾµÄÖµÓòÓÖÓÐËù²îÒì¡£µ«ÊdzÌÐòԱд³ÌÐòÈ´ÍùÍùÓÐÒâ»òÎÞÒâµØºöÂÔÕâÖÖ²î±ð£¬²»Ô¸Ãæ¶ÔÏÖʵ(ÕýÈçÓеijÌÐòÔ±µ÷Óú¯Êý´Ó²»¼ì²é·µ»ØÖµ)¡£ËûÃÇʹÓóÌÐòÖеÄÀàÐ;ÍÏóÔÚʹÓÃÀíÏëµÄÊýѧÉϵÄÀàÐÍÒ»Ñù¡£Å·ÖÞ°¢ÀïÑÇÄÉ»ð¼ý±¬Õ¨¾ÍÊÇ´ËÖÖ´íÎó¸øÎÒÃǵÄ×î²ÒÍ´½Ìѵ¡£
¡¡¡¡ ¼ÈÈ»Èç´Ë£¬Ã¿Ò»¸öC³ÌÐòÔ±¶¼ÓÐÔðÈÎÀμÇÕâôһÌõ¹æÔò:“¾³£·´ÎÊ£ºÕâ¸ö±äÁ¿»ò±í´ïʽ»áÉÏÒç»òÏÂÒçÂ𣿔(¡¶±à³Ì¾«´â£Microsoft±àдÓÅÖÊÎÞ´íC³ÌÐòÃؾ÷¡·P80,Steve Maguire Öø)¡£
Àý×Ó:
#include <stdio.h>
int MyAbs(int number)
{
return(number>=0 ? number :(-number));
}
void main()
{
int number = 0x80000000;
int absnumber = MyAbs(number);
if(absnumber<0)
pri
Ïà¹ØÎĵµ£º
http://www.cppreference.com/wiki/cn/stl/algorithm/remove
Óï·¨:
#include <algorithm>
forward_iterator remove( forward_iterator start, forward_iterator end, const TYPE& val );
remove Ëã·¨ÒƳý [start,end) ·¶Î§Ö®ÄÚµÄËùÓÐÓë val ÏàµÈµÄÔªËØ¡£
´Ëº¯ÊýµÄ·µ»ØÖµÊÇÒ»¸öµ ......
¶¨ÒåÒ»¸ö×Ö·ûÖ¸Õ룬Æä±¾ÖʵĴ¦Àí·½Ê½ÊÇ°´×Ö·ûÊý×é´¦ÀíµÄ£¬ÔÚÄڴ濪±ÙÒ»¸ö×Ö·ûÊý×éÓÃÀ´´æ·Å×Ö·û´®³£Á¿£¬ÕâÑù±Ø¶¨»áÖÕÖ¹·û¡£¶øÕâÑùµÄÌØÐÔÒ²½ö¶ÔÓÚ×Ö·ûÖ¸Õë±äÁ¿¡£
ÔÚCÓïÑÔÖУ¬Í¨¹ýÊý×éÃû»òÕßÖ¸Õë±äÁ¿Êä³öÒ»¸ö×Ö·û´®£¬ÎÒÀí½âΪÁ½¸ö£º×Ö·û´®ÖÕÖ¹·ûµÄ´æÔÚ£»ÒÔ%s¸ñʽµÄÊä³ö·½Ê½¡£
char *p="I love china!";
& ......
ÓдÎÒ»¸öͬÊÂÎÊÎÒ
swc ^= swc;
ÊÇʲôÒâ˼,ÎÒÒ²²»ÖªµÀ,²éÁËÏÂ,Òâ˼Ӧ¸ÃÊǽ«swc±äÁ¿Çå0£¬ÒÉ»óµÄÊÇΪʲô¾Í²»ÄÜд³É swc = 0; ÄØ?²»Ã÷°×
˳±ã¼Ç¼ÏÂÆäËûµÄ²Ù×÷,Åöµ½ÐµÄÔÙ×·¼Ó:
swc = ~swc; //±äÁ¿È¡·´ ......
c/c++ÃæÊÔÌâ
¡¡¡¡±¾ÎĵÄд×÷Ä¿µÄ²¢²»ÔÚÓÚÌṩC/C++³ÌÐòÔ±ÇóÖ°ÃæÊÔÖ¸µ¼£¬¶øÖ¼ÔÚ´Ó¼¼ÊõÉÏ·ÖÎöÃæÊÔÌâµÄÄÚº¡£ÎÄÖеĴó¶àÊýÃæÊÔÌâÀ´×Ô¸÷´óÂÛ̳£¬²¿·ÖÊÔÌâ½â´ðÒ²²Î¿¼ÁËÍøÓѵÄÒâ¼û¡£
¡¡¡¡Ðí¶àÃæÊÔÌâ¿´ËƼòµ¥£¬È´ÐèÒªÉîºñµÄ»ù±¾¹¦²ÅÄܸø³öÍêÃÀµÄ½â´ð¡£ÆóÒµÒªÇóÃæÊÔÕßдһ¸ö×î¼òµ¥µÄstrcpyº¯Êý¶¼¿É¿´³öÃæÊÔÕßÔÚ¼¼ÊõÉϾ¿¾¹´ïµ½ÁËÔ ......