Geeks Talk

Prepare for your Next Interview




C Program Logic Question

This is a discussion on C Program Logic Question within the C and C++ forums, part of the Software Development category; #define f(g1,g2) g1##g2 main() { int var12=100; printf("%d",f(var,12)); } this prints the output 100. and if i change the value in f(...


Go Back   Geeks Talk > Software Development > C and C++

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-29-2007
Junior Member
 
Join Date: Feb 2007
Location: india
Posts: 10
Thanks: 2
Thanked 3 Times in 2 Posts
sundarkms is on a distinguished road
C Program Logic Question

#define f(g1,g2) g1##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}

this prints the output 100. and if i change the value in f(var,12) as f(var,13) a error is coming and if i delete # then also error is coming i cant understand give a brief explanation

#define f(g1,g2) g1##g2

main()
{
int var12=100;
printf("%d",f(var,12));
}

this prints the output 100. and if i change the value in f(var,12) as f(var,13) a error is coming and if i delete # then also error is coming I cant understand give a brief explanation
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-31-2007
Junior Member
 
Join Date: Aug 2007
Location: Bangalore
Posts: 5
Thanks: 0
Thanked 3 Times in 3 Posts
chpushpakumar is on a distinguished road
Re: C Program Logic Question

## is String concatenation operator. This will concatenates two values in that Macro.
Here Var12=100.

In Macro f(g1,g2) is g1##g2.

So If f(var,12) then it is var12 so Answer is 100.
If we put f(var,13) then it is var13, which is not declared.
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Knowledge about Program ID in Cobol program RyanJames MainFrame 2 02-14-2008 09:32 AM
Can anyone write this Matching Logic? zyxwv MainFrame 0 05-16-2007 07:06 PM
what is the logic behind this ? psuresh1982 Brainteasers 7 02-05-2007 03:38 AM
Where lies the flaw in the logic? psuresh1982 Brainteasers 1 11-17-2006 02:00 AM
Apply Logic to get the number Bessie Brainteasers 2 08-25-2006 04:24 PM


All times are GMT -4. The time now is 09:11 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved