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

  • Home
  • SEARCH
  • 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 3275686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:10:19+00:00 2026-05-17T19:10:19+00:00

Why does the following call: printf(%d %d, ‘a’, ‘b’); result in the correct 97

  • 0

Why does the following call:

printf("%d %d", 'a', 'b');

result in the “correct” 97 98 values?
%d indicates the function has to read 4 bytes of data, and printf shouldn’t be able to tell the type of the received arguments (besides the format string), so why isn’t the printed number |a||b||junk||junk|?

Thanks in advance.

  • 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-17T19:10:20+00:00Added an answer on May 17, 2026 at 7:10 pm

    In this case, the parameters received by printf will be of type int.

    First of all, anything you pass to printf (except the first parameter) undergoes “default promotions”, which means (among other things) that char and short are both promoted to int before being passed. So, even if what you were passing really did have type char, by the time it got to printf it would have type int. In your case, you’re using a character literal, which already has type int anyway.

    The same is true with scanf, and other functions that take variadic parameters.

    Second, even without default promotions, character literals in C already have type int anyway (§6.4.4.4/10):

    An integer character constant has type int.

    So, in this case the values start with type int, and aren’t promoted–but even if you started with chars, something like:

    char a = 'a';
    
    printf("%d", a);
    

    …what printf receives would be of type int, not type char anyway.

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

Sidebar

Related Questions

Why does the following code not work as I was expecting? <?php $data =
What does the following mean? Class.Function(variable := 1 + 1) What is this operator
Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time?
Why does the following code sometimes causes an Exception with the contents CLIPBRD_E_CANT_OPEN: Clipboard.SetText(str);
Why does the following method hang? public void pipe(Reader in, Writer out) { CharBuffer
What does the following code do in C/C++? if (blah(), 5) { //do something
What does the following code do? A link to something in the PHP manual
Why does the following behave unexpectedly in Python? >>> a = 256 >>> b
What does the following error mean? Geeneration of designer file failed: Exception from HRESULT:
What does the following expression return in Java? Math.max(Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); I saw this question

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.