Welcome Guest ( Log In | Register)



3 Pages V  < 1 2 3  
Reply to this topicStart new topic
> C Code, Can U Solve This?, Another interesting problem
Dark_Prisoner
post Feb 26 2008, 07:15 PM
Post #21


Newbie [Level 1]
*

Group: Members
Posts: 22
Joined: 20-February 08
Member No.: 58,158



QUOTE(nooc @ Nov 19 2004, 11:02 PM) *
CODE
#include <stdio.h>

void fun(void)
{
#define fun() i=10
}

int main()
{
int i = 20;
fun();
printf("i = %d\n", i);
return 0;
}


I think that this won't work :
(i guess) we can't put preprocessor directives on a function
If we can , it won't work also , because the compiler or the processor had completed the line :
CODE
fun();

so he won't replace it .

if the preprocessor works in functions i guess this will be the answer
CODE
void fun(void)
{
#define printf("i = %d\n", i) i=0
}

int main()
{
int i = 20;
fun();
printf("i = %d\n", i);
return 0;
}


What do you think ???

Go to the top of the page
 
+Quote Post
tricky77puzzle
post Feb 27 2008, 12:41 AM
Post #22


Super Member
*********

Group: [HOSTED]
Posts: 416
Joined: 26-January 08
Member No.: 56,881



printf is a standard function in C. You can't modify it.

Try doing the same thing in c++.
Go to the top of the page
 
+Quote Post
iGuest
post Apr 30 2008, 01:52 PM
Post #23


Hail Caesar!
*********************

Group: Members
Posts: 5,876
Joined: 21-September 07
Member No.: 50,369



code for this program
C Code, Can U Solve This?

Easy code in 'C' program to prove pallidrome rule

Thanking you,
Vikram









-question by vikram
Go to the top of the page
 
+Quote Post

3 Pages V  < 1 2 3
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Crazy Looking C Program(19)
  2. Code Documentation(1)
  3. Simple C File Handling In Action(4)
  4. Prob With My C Code(4)
  5. Source Code For Paint Like Program Under Dos In C(2)
  6. Wolfenstein Source Code Now In Public Domain(3)
  7. A Telephone Directory Source Code In C(2)
  8. C++ Roman Numeral Conversion Code Help(5)
  9. Most Efficient Code To Get Prime Numbers(7)


 



- Lo-Fi Version Time is now: 12th October 2008 - 03:53 PM