1,776 views
1 votes
1 votes
What is the output of following program?
#include <stdio.h>
void main(){
int p = -8;
int i = (p++, ++p);
printf("%d\n", i);
}

Can anyone explain?

1 Answer

1 votes
1 votes
Here Output will be -6

as p = -8

and i = (p++,++p)    //comma is used as separator

let k = p++ => k = p and p= p+1

that means k = -8 and  p = -7

and lel l = ++p => p = p+1 and l = p

that means l = -6 and p = -6

as comma operator evaluates left to right that why first p++ then ++p will be resolved

so i = -6

Related questions

2 votes
2 votes
1 answer
1
rupamsardar asked Aug 30, 2023
484 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...
0 votes
0 votes
1 answer
2
SHWETAV SUMAN asked Oct 6, 2022
328 views
i have typed the following code but when i executed it the solution was not according to my expectation.unsigned short int y= -9; int iy=y; printf(“%d”,iy); solutio...
0 votes
0 votes
3 answers
3
ykrishnay asked May 30, 2022
1,061 views
int main(){extern int a = 20;printf("%d",a); }//why this gives error but followig code is not extern int a =20;int main(){printf("%d",a); } //why this happens that first ...
0 votes
0 votes
0 answers
4
ykrishnay asked May 20, 2022
384 views
What is stream in c programming ? as i read file io in c programming so thats where i read “stream” word so what stream means ? thank you