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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:35:32+00:00 2026-05-22T18:35:32+00:00

Possible Duplicates: C programming: is this undefined behavior? Is this program having any sequence

  • 0

Possible Duplicates:
C programming: is this undefined behavior?
Is this program having any sequence point issues ?

Hi,

I am running the following program

void print(int *a, int *b, int *c, int *d, int *e)
{

    printf("\n %d %d %d %d %d",*a,*b,*c,*d,*e);
}

int _tmain(int argc, _TCHAR* argv[])
{

    static int arr[] = {97,98,99,100,101,102,103,104};
    int *ptr=arr+1;
    print(++ptr,ptr--,ptr,ptr++,++ptr);
    getchar();
    return 0;
}

I thought I would be getting 99 99 98 98 100 as output but I am getting 100 100 100 99 100 as output. I cant understand why. Do pointers behave differently then normal variable when used with ++ or –(pre or postfix) operators. Can u please help me understand how the program is working

  • 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-22T18:35:33+00:00Added an answer on May 22, 2026 at 6:35 pm

    You’re reading and modifying ptr multiple times without a sequence point. This is undefined behavior. The compiler can emit any code it feels like. Don’t do it.

    Please note also that the order of evaluation of function arguments is not defined, so your print statement, even if it was well-defined, would not necessarily output what you think it would.

    See this question Is this undefined behavior for a similar issue.

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

Sidebar

Related Questions

Possible Duplicate: C programming, why does this large array declaration produce a segmentation fault?
Possible Duplicates: Overriding vs Virtual How am i overriding this C++ inherited member function
Possible Duplicates: how to start a for loop in R programming Creating a for
Possible Duplicates: Is the following JavaScript construct called a Closure? What do parentheses surrounding
Possible Duplicate: How costly is .NET reflection? I am currently in a programming mentality
Possible Duplicates: C++0X when? When will C++0x be finished? When will C++0x be released?
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicates: is “else if” faster than “switch() case” ? What is the relative
Possible Duplicate: C Programming: Forward variable argument list. What I'd like to do is
Possible Duplicate: C programming : How does free know how much to free? When

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.