Programmer's day special
Hi all,
Today being programmer's day (I dont know whether there is actually such a day :but what they tell is today is the 256th day of the year and 256 is the number of values representable by a byte of data ) let me post two good C -puzzles I have seen.
Q1) The first question is write code in the change function so that the printf in main prints 5.You should not modify the main function and u shud not use printf in the change function
#include
void change()
{
/*write code here*/
}
int main()
{
int i;
i=5;
change();
i=10;
printf("%d",i);/* this should print 5*/
}
the solution is
void change()
{
#define i i=5,j
}
so whenever u see "i" it will be replaced by thepreprocessor as
i=5,j that is
int i; becomes int i=5,j;
similarly
i=10 becomes i=5,j=10; //the comma operator
and printf('%d",i ) becomes printf("%d", i=5,j);and printf ignores the second argument.
Q2)WAP in C to print ur name 1000 times without using semi colon
solution
#include
void main (int argc, char **argv)
{
while (printf ("Babu Kalyanam\n") && ( argc++ <=1000)) { } } or you can use rather awkward solution #include
void main()
{
if ( printf("Babu Kalyanam\n"))
if ( printf("Babu Kalyanam\n"))
if ( printf("Babu Kalyanam\n"))
/*repeat this 1000 times */
if ( printf("Babu Kalyanam\n"))
{}
}
Labels: കണ്ടത്

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home