C Ö®±
1.ÓÐn¸öÕûÊý£¬Ê¹Ç°Ãæ¸÷Êý˳ÐòÏòºóÒÆm¸öλÖã¬×îºóm¸öÊý±ä³É×îÇ°Ãæm¸öÊý¡£
#include<stdio.h>
int f(int *);
int main()
{
int *p,a[10];
for(p=a;p<a+10;p++)
scanf("%d",p);
f(a);
for(p=a;p<a+10;p++)
printf("%d ",*p);
return 0;
}
int f(int *a)
{
int i,*p,b[10];
for(p=a;p<a+10;p++)
{
if(p-a<10-3)
b[p-a+3]=*p;
else
b[p-a-10+3]=*p;
}
for(i=0,p=b;p<b+10;i++,p++)
a[i]=*p;
return 0;
}
2.ÓÐn¸öÈËΧ³ÉһȦ£¬Ë³ÐòÅźš£´ÓµÚ1¸öÈË¿ªÊ¼±¨Êý£¨´Ó1µ½3±¨Êý£©£¬·²±¨µ½3µÄÈËÍ˳öȦ×Ó£¬ÎÊ×îºóÁôϵÄÊÇÔÀ´µÚ¼¸ºÅµÄÄÇλ¡£
#include<stdio.h>
int main()
{
int *p,*q,r=1,i,t=0,n,a[100];
for(i=0;i<100;i++)
a[i]=i+1;
p=a;
printf("input the number of people:");
scanf("%d",&n);
while(t!=n-1)
{
if(p-a==n) p=q;
if(r==3&&*p!=0)
{
*p=0;
r=1;
t++;
}
if(*p!=0) r++;
for(i=0;i<n;i++)
{
if(a[i]!=0)
{
q=&a[i];
break;
}
}
p++;
}
printf("the final one is No.%d\n",*q);
return 0;
}
Ïà¹ØÎĵµ£º
ÓÐ¹Ø extern "C"
¸ã¹ýCºÍC++»ì±àµÄͬ־ÃǶ¼ÖªµÀÕâ¸öɶÒâ˼¡£
Õâ¶ùÓн²£ºhttp://www.cppblog.com/Macaulish/archive/2008/06/17/53689.html
µ«¿´Ò»ÏÂÏÂÃæµÄÕâ¸ö´úÂ룺
#include <iostream>
using namespace
std;
extern "C" { int g_inta; }
int main (void)
{
g_ ......
1.·Ö²ãÉè¼Æ£¬¸ôÀëƽ̨Ïà¹ØµÄ´úÂë¡£¾ÍÏñ¿É²âÊÔÐÔÒ»Ñù£¬¿ÉÒÆÖ²ÐÔÒ²Òª´ÓÉè¼Æ×¥Æð¡£Ò»°ãÀ´Ëµ£¬×îÉϲãºÍ×îϲ㶼²»¾ßÓÐÁ¼ºÃµÄ¿ÉÒÆÖ²ÐÔ¡£×îÉϲãÊÇGUI£¬´ó¶àÊýGUI¶¼²»ÊÇ¿çƽ̨µÄ£¬ÈçWin32 SDKºÍMFC¡£×îϲãÊDzÙ×÷ϵͳAPI£¬´ó¶à²¿·Ö²Ù×÷ϵͳAPI¶¼ÊÇרÓõġ£
¡¡¡¡Èç¹ûÕâÁ½²ãµÄ´úÂëÉ¢²¼ÔÚÕû¸öÈí¼þÖУ¬ÄÇôÕâ¸öÈí¼þµÄ¿ÉÖ²ÐÔ½«·Ç³£µÄ² ......
´æ´¢Àà¾ÍÊÇÓÃÓÚ´æ´¢³ÌÐòÊý¾ÝµÄÄÚ´æµÄÀàÐÍ£¬ÓÉÈý¸öÊôÐÔÀ´±íʾ£º´æ´¢Ê±¼ä¡¢×÷ÓÃÓòºÍÁ´½Ó¡£
´æ´¢Ê±ÆÚÃèÊöµÄÊDZäÁ¿Õ¼ÓÃÄÚ´æµÄʱ¼ä£¬Óо²Ì¬µÄ¡¢×Ô¶¯µÄºÍ·ÖÅäµÄÈýÖÖ
×÷ÓÃÓòÊDZäÁ¿Æðµ½×÷Óõķ¶Î§£¬ÓдúÂë¿é×÷ÓÃÓòºÍÎļþ×÷ÓÃÓòÁ½ÖÖ
Á´½Ó˵Ã÷¸Ã±äÁ¿¿ÉÒÔ±»ÄÄЩµØ·½ÒýÓã¬ÓпÕÁ´½Ó¡¢ÄÚ²¿Á´½ÓºÍÍⲿÁ´½ÓÈýÖÖ
ÏÂÃæÊÇÎåÖÖ´æ´¢ÀàµÄÊôÐÔ ......
1.ÇóÏÂÃ溯ÊýµÄ·µ»ØÖµ£¨Î¢Èí£©
int func(x)
{
int countx = 0;
while(x)
{
countx
++;
x = x&(x-1);
}
return countx;
}
¼Ù¶¨x = 9999¡£ ´ð°¸£º8
˼·£º½«xת»¯Îª2½øÖÆ£¬¿´º¬ÓеÄ1µÄ¸öÊý¡£
2. ʲôÊÇ“ÒýÓÔ£¿ÉêÃ÷ºÍʹÓÓÒýÓÔҪעÒâÄÄЩÎÊÌ⣿
´ð£ºÒýÓþÍÊÇij¸öÄ¿±ê±äÁ¿µÄ&l ......
//cExample.h
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
int add(int x, int y);
#ifdef __cplusplus
}
#endif
#endif
---------------------------------
//cExample.c
#include"cExample.h"
int add(int x, int y)
{
return x + y;
}
----------------- ......