Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:29:32+00:00 2026-05-27T22:29:32+00:00

Possible Duplicate: # and ## in macros why the output of second printf is

  • 0

Possible Duplicate:
# and ## in macros

why the output of second printf is f(1,2) what is the order in which macro is evaluated?

#include <stdio.h>
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)

int main()
{
  printf("%s\n",h(f(1,2)));
  printf("%s\n",g(f(1,2)));
  return 0;
}

output 12 
       f(1,2)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:29:32+00:00Added an answer on May 27, 2026 at 10:29 pm

    From http://gcc.gnu.org/onlinedocs/cpp/Argument-Prescan.html#Argument-Prescan

    Macro arguments are completely macro-expanded before they are substituted into a macro body, unless they are stringified or pasted with other tokens. After substitution, the entire macro body, including the substituted arguments, is scanned again for macros to be expanded. The result is that the arguments are scanned twice to expand macro calls in them.

    Meaning:

    • f concatenates its argument and so its argument is not expanded
    • h does not stringify or concatenate its argument and so its argument is expanded.
    • g stringifies its argument, and so its argument is not expanded

    h(f(1,2)) -> g(12) -> "12"

    g(f(1,2)) -> "f(1,2)"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Problem with Macros Hi all I have defined this macro: #define SQ(a)
Possible Duplicate: C Preprocessor, Stringify the result of a macro Shortly: #include <iostream> float
Possible Duplicate: "static const" vs "#define" in c A macro is a fragment of
Possible Duplicate: What are C macros useful for? Every few months I get an
Possible Duplicates: What’s the use of do while(0) when we define a macro? Why
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: Check if access table exists I'm new to vba macros. Any idea
Possible Duplicate: static const vs #define in C I started to learn C and
Possible Duplicate: C, Macro defining Macro Does anyone know how to pull off something
Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.