#includestdio.h
#define power(a) #a
int main()
{
printf(%d,*power(432));
return 0;
}
ans is 52 on gcc. Explain plss
--
best wishes!!
Vaibhav Shukla
DU-MCA
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
#includestdio.h
#define power(a) #a
int main()
{
printf(%d,*power(432));
return 0;
}
the printf statement, after preprocessing, will look like
printf(%d,*432);
so, when u print the value at the first position of the string, 52, which is
the ascii value of 4, will be printed.
On Thu, Jun 23,
printf(%d,*power(432)) will expand as
*printf(%d, *432)*
432 represents here a string and *432 is pointing to the first string
literal i.e 4 whose ascii value is 52..hence the output is 52
On Thu, Jun 23, 2011 at 4:02 PM, Shachindra A C sachindr...@gmail.comwrote:
#includestdio.h
#define
hmm i got it.thnx
On Thu, Jun 23, 2011 at 4:05 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote:
printf(%d,*power(432)) will expand as
*printf(%d, *432)*
432 represents here a string and *432 is pointing to the first string
literal i.e 4 whose ascii value is 52..hence the output is 52
#a is the replacement sequence which is substituted in the printf statement
The statements
#define power(a) #a
printf(%d,power(a));
is substituted as
printf(%d,a);
it is replaced with the string literal a . then *power(a) is converted as
value at that string literal address.
Hope this solves
COOL BRO THIS IS A GOOD SOLN
On Tue, Apr 5, 2011 at 4:10 PM, Azhar Hussain azhar...@gmail.com wrote:
Few Important things about macros, before I explain the output
1. Macros are replaced in passes.
2. Macros are not recursive.
regarding the output remember the rule for expansion
A
nice explanation
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit
u can see the pre-processed file using gcc -E prog_name.cand @
bottom u can see what actually the code is doing.
On Tue, Apr 5, 2011 at 12:45 PM, Arvind akk5...@gmail.com wrote:
#includestdio.h
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
thx pratik
On Sat, Apr 9, 2011 at 8:13 PM, Pratik Kathalkar
dancewithpra...@gmail.comwrote:
u can see the pre-processed file using gcc -E prog_name.cand @
bottom u can see what actually the code is doing.
On Tue, Apr 5, 2011 at 12:45 PM, Arvind akk5...@gmail.com wrote:
#includestdio.h
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
printf(%s,g(f(1,2)));
printf(\t%s,h(f(1,2)));
return 0;
}
i have run this program in gcc compiler and getting : f(1,2) 12 as
output.
can anyone explain the reason for getting this output?
--
You received this
Hi Arvind,
These are preprocessor specific operators. Check out
http://msdn.microsoft.com/en-us/library/wy090hkc(v=vs.80).aspx
-Vandana
On Tue, Apr 5, 2011 at 12:45 PM, Arvind akk5...@gmail.com wrote:
#includestdio.h
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
Few Important things about macros, before I explain the output
1. Macros are replaced in passes.
2. Macros are not recursive.
regarding the output remember the rule for expansion
A parameter in the replacement list, *UNLESS* preceded by a # or ##
preprocessing token or followed by a ##
#includestdio.h
int main()
{
printf(anuj,kumar);
return 0;
}
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
*The prototype of printf is*
*int printf(const char ***format**, ...);*
*
*
*Thus it takes a string and then variable number of arguments.*
*
*
*Every argument passed after (char *format)string is to resolve the%
inside the string (which is passed as the first argument)*
*
*
*Thus anuj will be
14 matches
Mail list logo