in Programming in C
546 views
2 votes
2 votes
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int p=9;
    printf("%d %d",p++,++p);
}



 

how it executed and also how printf function executed left to right or right to left?

in Programming in C
546 views

1 Answer

4 votes
4 votes
Best answer

How this is executed?

Only the person who wrote the particular version of the compiler can even predic this. Because in the following statement two modifications to the same variable happens without a sequence point in between (usage of ',' in argument list is not a sequence point though comma operator is), and hence the behavious is not defined by C standard and falls under Undefined Behaviour category.

printf("%d %d",p++,++p);

Now printf function is executed left-right or right-left?

I suppose you meant the order in which arguments to printf are processed. This is also not defined by C standards and compiler is free to choose as it like or the programmer is not supposed to make any assumption about this.

Why these questions are never asked in exams like GATE/TIFR?

Because they have better things to do.

Why there are less innovations from Indian Engineers?

Who told, only we can innovate these questions. While people abroad innovate things like Facebook and all we spend our time innovating and solving these kind of questions. Just google or search in Facebook C groups- at least half of the posts will be such questions being asked by Indian students.

Read More: https://gateoverflow.in/62411/what-is-the-output

selected by
by

Related questions

1 vote
1 vote
2 answers
3
Sanjay Sharma asked in Programming in C Nov 17, 2016
876 views
Sanjay Sharma asked in Programming in C Nov 17, 2016
876 views