Can anyone tell whats happening here | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone tell whats happening here

#include <stdio.h> int main() { static int x=25; int f1() {x=x+1; return x;} int f2() {x=x+2; return x;} x=(f1(),f2()); printf("%d",x); return 0; }

11th May 2020, 12:51 PM
Keerthana Nevuri
Keerthana Nevuri - avatar
1 Answer
+ 1
output - 28 The comma is a binary operator in c language and act as sequence point. Let me explain this in simpler terms the presence of comma operator guides the compiler to evaluate first operand and then discard the result got, after this it evaluates the second operand and returns the value as result. In this case first F1() is evaluated that changed static x to 26 and afterwards F2() is evaluated which converted x= 26+2=28 and that stores in x. Hope you understood.
11th May 2020, 5:14 PM
Rohit Jain
Rohit Jain - avatar