C puzzles
Authentication
Login with:New JS-Kit account
Google Friend Connect
Twitter account
FriendFeed account
Yahoo account
Blogspot URL
JS-Kit account
Haloscan account
OpenID
Dear visitor,
Thanks for your interest in C programming.
In this page, you will find a
list of interesting C programming questions/puzzles,
These programs listed are the ones which I have received as
e-mail forwards from my friends, a few I read in some books, a few from the
internet, and a few from my coding experiences in C.
Most of the programs are meant to be compiled, run and
to be explained for their behaviour. The puzzles/questions can be broadly
put into the following categories:
General typo errors, which C programmers do often and are
very difficult to trace.
Small programs which are extremely hard to understand at the first
examination. These questions make a good excercise of reading and understanding
effecient code written by others.
I have used Gnu/Linux/gcc for all of them.
The order in which the programs appear doesn't have
any relation with the level of difficulty.
Please feel free to contact me if you need any help in solving the problems.
My contact info. is available here
And you might be interested in a few references for C programming
,
which I personally found very interesting.
If you are preparing for campus interviews, you might find the following
link interesting:
http://placementsindia.blogspot.com
Regards,
Gowri Kumar
C puzzles
The expected output of the following C program
is to print the elements in the array. But when
actually run, it doesn't do so.
#include
<stdio.h>
#define
TOTAL_ELEMENTS
(
sizeof
(
array
)
/
sizeof
(
array
[
0
]))
int
array
[] =
{23
,34
,12
,17
,204
,99
,16
};
int
main
()
{
int
d
;
for
(d
=-
1
;d
<=
(TOTAL_ELEMENTS
-
2
);d
++
)
printf
(&q
Ïà¹ØÎĵµ£º
ÓÐËÕæÕýµÄÀí½â¹ýÒ»¸ö±àÒëÆ÷ÄØ£¿Ðí¶àÈËÈÏΪTCºÜ¼òµ¥ºÜÂäºó£¬µ«ÊǼ´±ãÊÇÕâÑù¼òµ¥µÄ¹¤¾ß£¬µ½µ×Óм¸¸öÈËÕæÕýµÄÉîÈëÀí½âÁËÄØ£¿Ò»¸ö¼òµ¥µÄ±àÒëÆ÷¶¼²»ÄÜÀí½â£¬ÈçºÎÄܳÉΪ¸ßÊÖ£¬ÈçºÎÄÜÉîÈëµÄʹÓøü¼Ó¸ß¼¶µÄ¹¤¾ßÄØ£¿²»ÒªÒÔΪ×Ô¼ºÊ¹ÓõÄÊÇVC¾ÍºÜÁ˲»Æð£¬ÒòΪʹÓÃÕâÑùɵ¹Ï»¯µÄ¹¤¾ßÖ»ÄÜÈÃÄã¿´²»µ½ÊÂÎïµÄ±¾ÖÊ¡£½ÓÏÂÀ´ÎÒÃǾÍÀ´ÉîÈëµÄÈÏ ......
C/C++ÖÐStaticµÄ×÷ÓÃÏêÊö
Ò».ÔÚCÓïÑÔÖУ¬staticµÄ×ÖÃæÒâ˼ºÜÈÝÒ×°ÑÎÒÃǵ¼ÈëÆç;£¬ÆäʵËüµÄ×÷ÓÃÓÐÈýÌõ¡£
£¨1£©ÏÈÀ´½éÉÜËüµÄµÚÒ»ÌõÒ²ÊÇ×îÖØÒªµÄÒ»Ìõ£ºÒþ²Ø¡£
µ±ÎÒÃÇͬʱ±àÒë¶à¸öÎļþʱ£¬ËùÓÐδ¼Óstaticǰ׺µÄÈ«¾Ö±äÁ¿ºÍº¯Êý¶¼¾ßÓÐÈ«¾Ö¿É¼ûÐÔ¡£ÎªÀí½âÕâ¾ä»°£¬ÎÒ¾ÙÀýÀ´ËµÃ÷¡£ÎÒÃÇҪͬʱ±àÒëÁ½¸öÔ´Îļþ£¬Ò»¸öÊÇa.c£¬ÁíÒ»¸öÊÇm ......
ҪдºÃCÓïÑÔ³ÌÐò£¬×îÖØÒªµÄµ±È»ÊǰÑÒª½â¾öµÄÎÊÌâ·ÖÎöÇå³þ£¬Éè¼ÆºÃ½â¾öÎÊÌâµÄ·½°¸ºÍͨ¹ý¼ÆËãʵÏÖÇó½âµÄ¹ý³Ì£¬¶ÔÎÊÌâµÄÇó½â¹ý³Ì½øÐпÆÑ§µÄ½á¹¹»¯µÄ·Ö½â¡£ÔÚ´Ë»ù´¡ÉϽøÒ»²½¿¼ÂÇÈçºÎд³ÌÐòµÄʱºò£¬ÏÂÃæµÄ½¨Òé¿ÉÄÜÓÐËù°ïÖú¡£
ÕâЩ½¨ÒéÖÐÓÐЩÊÇÒ»°ãÐԵ쬲»½ö½ö¶ÔCÓïÑÔ³ÌÐòÉè¼ÆÓÐЧ£»Ò²ÓÐЩÊÇÌØ±ðÕë¶ÔCÓïÑÔ³ÌÐòÉè¼ÆµÄ¡£Õâ¸ö±í»¹ ......
±àÒë¹ý³Ì¸ÅÊö
Á˽âһЩ±àÒë֪ʶµÄ¶ÁÕß¶¼ÖªµÀ£¬Ëùν±àÒ룬¾ÍÊÇÔÚ±àÒë³ÌÐò¶ÁȡԴ³ÌÐò£¨×Ö·ûÁ÷£©£¬¶ÔÖ®½øÐдʷ¨ºÍÓï·¨µÄ·ÖÎö£¬½«¸ß¼¶ÓïÑÔÖ¸Áîת»»Îª¹¦ÄܵÈЧµÄ»ã±à´úÂ룬ÔÙÓÉ»ã±à³ÌÐòת»»Îª»úÆ÷ÓïÑÔ£¬²¢ÇÒ°´ÕÕ²Ù×÷ϵͳ¶Ô¿ÉÖ´ÐÐÎļþ¸Ðл¸ñʽµÄÒªÇóÁ´½ÓÉú³É¿ÉÖ´ÐгÌÐò¡£
UNIX»·¾³ÏµÄC±àÒëϵͳËù×ñѵÄÒ²ÊÇÕâôһ¸öÒ»° ......
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
C λ²Ù×÷
ʱ¼ä£º2009-10-9
×÷Õߣºsofa120
×¢£º ×ªÔØÇë˵Ã÷³ö´¦
/////////////////////////// ......