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 8140445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:10:21+00:00 2026-06-06T12:10:21+00:00

I have found two different things in two well known books in c, first

  • 0

I have found two different things in two well known books in c,
first one is
“Formal parameters are not replaced in quoted string in macro expansion” – by K&R c language page 76

second one is a code,

#define PRINT(var,format) printf("variable is %format\n",var)
PRINT(x_var,f);

later macro invocation would be expanded as

printf("x_var is %f\n",x_var);
  • this is by programming in ansi c – E. balagurusamy at page 448.

Surely two citations are contradictory one with another. as far I know first one is true and my compiler giving me result so. But second book is also well known and popular. I want to know if there was such things in previous versions of c or the second citation is a false one.

  • 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-06-06T12:10:22+00:00Added an answer on June 6, 2026 at 12:10 pm

    The second book is wrong: it is easy to check that the macro will not be expanded like that. However, you can get the effect that they describe by stringizing tokens using the # preprocessor operator:

    #define PRINT(var,format) printf(#var" is %"#format"\n",var)
    

    Now you can print your variable as follows:

    int xyz = 123;
    PRINT(xyz, d);
    

    Here is a link to a working sample on ideone.

    Note the addition of the double quotes before and after the ‘#format’, and the ‘#’ before ‘var’ and ‘format’. The ‘#’ operator causes the value of the variable to be made into a quoted string — with double quotes of its own. This makes the replaced strings be four quoted strings in a row, that the C compiler recognizes as a request to concatenate into one string. Thus the strings: “xyz”, ” is %”, “d” and “\n” are concatenated into: “xyz is %d\n”

    (Note this example is different from the example in the original question in that the orignal example had “variable is…” where the answer replaced ‘variable’ with an instance of the ‘var’ macro argument)

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

Sidebar

Related Questions

I'm structuring a database, and found that I have two different objects I'm trying
I have found two ways to extract matches in Python: 1. def extract_matches(regexp, text):
I have found only two methods (SaveFile, LoadFile) which save in a file. How
I have found possible slowdown in my app so I would have two questions:
I have found many people with simliar issues but no soultions...basically I have two
I have two branches: trunk, production. I have found a problem in trunk, made
I have seen programs exporting to Excel in two different ways. Opening Excel and
I've found a pretty nasty bug in EF 4.1 Code First. Assume we have
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have found Okapi Similarity measure can be used to calculated document similarity from

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.