+ 2

Please explain me this c language code.

Void f(int* x){ Printf("%d",(*x)++); *x=2; } Int main(){ Int a = 3; Int* b = &a; f(&a); Printf("%d",*b); Return 0; }

29th Jun 2019, 6:05 PM
Gaurav Rawat
Gaurav Rawat - avatar
3 Respuestas
+ 5
Hi. C is entering the code to execute at the main-function. First thing it does is to reserve memory for an integer value called a and assign the value 3 to it. Next, a pointer to an integer memory is reserved called b and it points to the memory of integer a. Then function f is called which takes an integer pointer as input value called x. In function f the value of contained at the memory of x (asterisk * is the notation to receive the value of the memory it points to) is incremented (with no effect) and printed to command line. After that it is set to 2 and returning to the execution in main. Here the value contained at memory position is printed, which should be 2 due to the same memory as x pointed to before. Return 0 to show that all went fine with your execution. Hope that helps. Cheers. C. Post scriptum: Be aware of case sensitivities. All Int should be int and so on. There will be no new line or whitespace between the two printf
29th Jun 2019, 6:19 PM
ChrA
ChrA - avatar
+ 2
Thanks for your explaination But tell me what is the output
30th Jun 2019, 5:32 AM
Gaurav Rawat
Gaurav Rawat - avatar
+ 2
See here https://code.sololearn.com/cdoPN4MAr5kc/?ref=app I only change the cases of some keywords
30th Jun 2019, 5:55 AM
ChrA
ChrA - avatar