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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:44:43+00:00 2026-05-17T06:44:43+00:00

#include<stdio.h> int main(void) { int a=5; printf(%d+1,a); } Output: d. I didn’t get how

  • 0
#include<stdio.h>
int main(void)
{
 int a=5;
 printf("%d"+1,a);
}

Output: d.
I didn’t get how the output is coming: d ?

  • 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-17T06:44:43+00:00Added an answer on May 17, 2026 at 6:44 am

    You passed as first argument of printf "%d"+1; "%d" is actually seen as a const char * that points to a memory location where %d is stored. As with any pointer, if you increment it by one, the result will point to the following element, which, in this case, will be d.

    a is not used, but this should not be a problem since in general (I don’t know if it’s standard-mandated Edit: yes it is, see bottom) the stack cleanup responsibility for variadic functions is up to the caller (at least, cdecl does it that way, this however may or may not be UB, I don’t know*).

    You can see it easier this way:

    #include<stdio.h>
    int main(void)
    {
        int a=5;
        const char * str="%d";
        printf(str + 1, a);
    }
    

     

    str ---------+
                 |
                 V
              +----+----+----+
              |  % |  d | \0 |
              +----+----+----+
    
    str + 1 ----------+
                      |
                      V
              +----+----+----+
              |  % |  d | \0 |
              +----+----+----+
    

    Thus, ("%d"+1) (which is "d") is interpreted as the format string, and printf, not finding any %, will simply print it as it is. If you wanted instead to print the value of a plus 1, you should have done

    printf("%d", a+1);
    

    Edit:
    * ok, it’s not UB, at least for the C99 standard (§7.19.6.1.2) it’s ok to have unused parameters in fprintf:

    If the format is exhausted while arguments remain, the excess arguments are
    evaluated (as always) but are otherwise ignored.

    and printf is defined to have the same behavior at §7.19.6.3.2

    The printf function is equivalent to fprintf with the argument stdout interposed
    before the arguments to printf.

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

Sidebar

Related Questions

#include<stdio.h> int main(void) { int a=-3,b=5,c; c=a|b; printf(%d ,c); c=a&b; printf(%d ,c); } The
#include <stdio.h> #include <stdlib.h> int main( void ) { char *ptr1 = Hello World\n;
I have a question regarding the execution of the following program. #include<stdio.h> int main(void)
Source: #include <stdio.h> void main() { int i, j, tree_Size, spaces, total_Spaces, x; char
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const
I wrote a program in C having dangling pointer. #include<stdio.h> int *func(void) { int
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
Consider the following code: #include <stdio.h> namespace Foo { template <typename T> void foo(T
So I have this code: #include <stdio.h> int arraySum (int *a, int n); int

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.