The short answer is yes, in your case you can guarantee that int1 and int2 not changed .
However, I would advise you not to rely on this behavior, since it will probably generate code that is difficult to read, and because:
A long answer depends on your format string . Considering the C11 standard for fscanf (s7.21.6.2.16), we have:
The fscanf function returns the value of the EOF macro if the input fails before the completion of the first conversion (if any). Otherwise, the function returns the number of assigned input elements, which may be less than provided, or even zero, in an early match event.
It is critical to define input elements later in 7.21.6.2:
An input element is defined as the longest sequence of input characters that does not exceed any given field width and which is or is a prefix of the corresponding input sequence
So. The number returned by scanf is the number of elements read from the stream, not the number of pointers written in.
Additionally, relevant 7.21.6.2.2:
If the format is exhausted while the arguments remain, the excess arguments are evaluated (as always), but are ignored otherwise.
The behavior of ignoring arguments that are not written is also explicitly expressed in the example at the end of this section:
IN:
#include <stdio.h> /* ... */ int d1, d2, n1, n2, i; i = sscanf("123", "%d%n%n%d", &d1, &n1, &n2, &d2);
a value of 123 assigned to d1 and a value of 3 is assigned to n1 . Since %n never get an input failure, a value of 3 also assigned to n2 . The value of d2 not affected. The value 1 assigned to i .
If you are not familiar with %n , this is the "number of characters read from the stream so far."
This is a great example to illustrate your question: here we have three pointers, and one pointer is untouched. But fscanf returns only 1 here - because it only assigned one “input element” from the stream.
So in your example, yes, if you have %d %d and you pass it something that causes 0 views, then yes, the pointers will be untouched.
But if you have %n , then your function can still return 0 or EOF, while still consuming some input and writing pointers. For instance:
sscanf("aaa","aaa%n%d",&n1,&n2);
This writes 3 to n1 , leaves n2 untouched and returns EOF . A:
sscanf("aaa bbb","aaa%n%d",&n1,&n2);
This writes 3 to n1 , leaves n2 untouched and returns 0.