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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:42:11+00:00 2026-05-24T19:42:11+00:00

#include stdafx.h #include<stdio.h> #define PR(x) printf(%d\t,(int)(x)); #define PRINT(a,b,c) PR(a) PR(b) PR(c) #define MAX(a,b) (a<b?b:a)

  • 0
#include "stdafx.h"
#include<stdio.h>

#define PR(x) printf("%d\t",(int)(x));
#define PRINT(a,b,c) PR(a) PR(b) PR(c)
#define MAX(a,b) (a<b?b:a)

int main()
{
    int x=1,y=2;
    //PR(MAX(x++,y));
    PRINT(MAX(x++,y),x,y);  //2,2,2
    PRINT(MAX(x++,y),x,y);  //2,3,2
    return 0;
}

x is 1 so the 3 values to be passed as arguments in PRINT is 2 2 2.

Then in the second PRINT the values that will be passed is 2 3 2. So the output should be 2 2 2 2 3 2. But this program outputs as 2 2 2 3 4 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-24T19:42:12+00:00Added an answer on May 24, 2026 at 7:42 pm

    Your MAX macro is bad. It evaluates one of its arguments twice.

     MAX(x++,y)
    

    expands to:

     (x++ < y ? y : x++)
                    ^^^
    

    So x is incremented twice if it started out smaller than y.

    There is no undefined behavior in that code because there is a sequence point between the evaluation of the first part of the ternary operator and the part that is selected. The whole PRINT expression expands to:

     printf("%d\t", (x++ < y ? y : x++));
     printf("%d\t", (x));
     printf("%d\t", (y));
    

    Which is all fine. This does not mean you should be using such macros. Use simple functions, and let the compiler do its job of type-checking and inlining what it thinks is best.

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

Sidebar

Related Questions

#include stdafx.h #include<stdio.h> int aarray[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(aarray)/sizeof(int)) int main() { printf(%d\n,SIZE); if(-1<=SIZE)printf(1\n); else
#include <stdafx.h> #include <stdio.h> #include <conio.h> #include<stdlib.h> #define My_Sizeof(type) ((char*)((type*)0 +1) - (char*)(type*)0) void
//#include StdAfx.h #include <stdio.h> #include <windows.h> #include <winbase.h> #include <iostream> #include <tchar.h> using namespace
#include stdafx.h #include <stdio.h> struct s { char *st; struct s *sp; }; struct
I am getting errors for the below program. #include stdafx.h #include<stdio.h> struct s {
// diskbin.cpp : main project file. #include stdafx.h #include <windows.h> #include <iostream> #include <fstream>
I have the main .cpp file with this: #include stdafx.h #include Form1.h #include <iostream>
// Huffman Tree.cpp #include stdafx.h #include <iostream> #include <string>//Necessary to do any string comparisons
//file list.h #include stdafx.h namespace st { struct My_List; typedef My_List list; list* create(const
I omitted #include stdafx.h in each file. stdafx.h (precompiled headers) #include a.h #include b.h

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.