Alex Rivera | Logout

What does the scanf function return?

Asked 2012-05-06T09:57:08.423
39

What is the value returned by scanf when:

int g;
int p = scanf("%d", &g);      // Originally: int p = scanf("%d", g);

I know that the signature of the scanf function is:

int scanf(const char *format, ...)

What is the int value returned from this function?

Edit
Report

1 Answer

0

Technically this is UB (Undefined behaviour).

int g;
int p=scanf("%d",g);
                 ^

You passing an unitialized integer to scanf to use it as an address to write to. From this point on, anything can happen. Most likely your app is going to crash.

answered 2012-05-06T10:10:25.310

Your Answer