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
Ïà¹ØÎĵµ£º
(ת)C/C++ ºêÏê½â ÊÕ²Ø
ÖÚ¶àC++Êé¼®¶¼ÖÒ¸æÎÒÃÇCÓïÑÔºêÊÇÍò¶ñÖ®Ê×£¬µ«ÊÂÇé×ܲ»ÈçÎÒÃÇÏëÏóµÄÄÇô»µ£¬¾ÍÈçͬgotoÒ»Ñù¡£ºêÓÐ
Ò»¸öºÜ´óµÄ×÷Ó㬾ÍÊÇ×Ô¶¯ÎªÎÒÃDzúÉú´úÂë¡£Èç¹û˵ģ°å¿ÉÒÔΪÎÒÃDzúÉú¸÷ÖÖÐͱðµÄ´úÂë(ÐͱðÌæ»»)£¬
ÄÇôºêÆäʵ¿ÉÒÔΪÎÒÃÇÔÚ·ûºÅÉϲúÉúеĴúÂë(¼´·ûºÅÌæ»»¡¢Ôö¼Ó)¡£
¹ØÓÚºêµÄһЩÓï·¨ÎÊÌ⣬¿É ......
ѧϰCÓïÑÔʱ£¬ÓÃ×Ö·û´®µÄº¯ÊýÀýÈçstpcpy()¡¢strcat()¡¢strcmp()µÈ£¬Òª°üº¬Í·Îļþstring.h
ѧϰC++ºó£¬C++ÓÐ×Ö·û´®µÄ±ê×¼Ààstring£¬stringÀàÒ²Óкܶ෽·¨£¬ÓÃstringÀàʱҪÓõ½string.hÍ·Îļþ¡£
ÎÒÏÖÔÚ¿´vcµÄÊéÉÏÒ²ÓÐCStringÀ࣬Õâ¸öÒª°üº¬Ê²Ã´£¬ÔõôÓÃ?
ÎÒÏÖÔÚºÜÃÔ»ó£¬ÕâÁ½¸ö string.hÓÐÊ²Ã´Çø±ð¡£ÊÇÔõô»ØÊÂ
ÇÒ¿´ ......
½ñÌì½â´ðһЩͬѧÔÚѧ¿ª·¢¹ý³ÌÖÐµÄÆÕ±éÎÊÌâ,¾ÍÊÇÈçºÎѧºÃÒ»ÃÅÓïÑÔ?
ÎÒÊÇÕâÑùÀ´Àí½âµÄ,Òª×öÈκÎÊÂÎï,Ê×ÏÈÒª·ÖÎöΪʲôҪ×ö,Ö»ÓаѺËÐĵÄ,ÄÚÐĵÄÔÒòÕÒµ½²ÅÄܰÑÒ»¼þÊÂÇé×öºÃ,·ñÔò,Ä㻨ÔÙ¶àµÄѧ·ÑѧijÖÖ¼¼ÊõÈÔÈ»»áÒ»ÎÞËù»ò,´ÓÎÒ¸öÈ˵ijɳ¤¹ý³ÌÀ´½«ÎÒÊÇ´Ó97Äê½Ó´¥¼ÆËã»ú,¿ªÊ¼Ñ§µÄһ̤ºýÍ¿,²»ÖªµÀÀÏʦÔÚ½²Ê²Ã´,²»ÖªµÀѧÁË»áÓÐʲ ......
ÒýÑÔ
¡¡¡¡Ö¸ÕëÊÇC/C++ÓïÑÔµÄÌØÉ«£¬¶øÊý×éÃûÓëÖ¸ÕëÓÐÌ«¶àµÄÏàËÆ£¬ÉõÖÁºÜ¶àʱºò£¬Êý×éÃû¿ÉÒÔ×÷ΪָÕëʹÓá£ÓÚÊǺõ£¬ºÜ¶à³ÌÐòÉè¼ÆÕ߾ͱ»¸ãºýÍ¿ÁË¡£¶øÐí¶àµÄ´óѧÀÏʦ£¬ËûÃÇÔÚCÓïÑԵĽÌѧ¹ý³ÌÖÐÒ²´íÎóµÃ¸øÑ§Éú½²½â£º"Êý×éÃû¾ÍÊÇÖ¸Õë"¡£ºÜÐÒÔË£¬ÎҵĴóѧÀÏʦ¾ÍÊÇÆäÖÐÖ®Ò»¡£Ê±ÖÁ½ñÈÕ£¬ÎÒÈÕ¸´Ò»ÈյؽøÐÐ×ÅC/C++Ï ......
C±ê×¼¿âÍ·Îļþ assert.h
@º¯ÊýÃû³Æ: assert
º¯ÊýÔÐÍ: void assert(int exp)
º¯Êý¹¦ÄÜ: Õï¶ÏÀࣺ±í´ïʽ½á¹ûÕýÈ·ÐÔ²âÊÔ²¢¿Éʹ³ÌÐòÖÐÖ¹
º¯Êý·µ»Ø:
²ÎÊý˵Ã÷: ½«´íÎóÐÅÏ¢Êä³öµ½Á÷stderrÖУ¬Èç¹ûexpΪ0£¬ÔòÖÐÖ¹³ÌÐòÖ´ÐÐ.exp-±í´ïʽ
ËùÊôÎļþ: & ......