c - Is it legal to use non-whitespace characters betwen field specification? If it's okay, then what is the output we can expect? -


#include<stdio.h>  main(){  int a,b,c; scanf("%d-%d",&a,&b); c=a+b; printf("%d",c);   } 

what output can expect code?

yes, using not whitespace characters in scanf format string legal. characters expected read , skipped over. if characters not given in input, scanf stops reading @ point.

for example, if input 3-4, 3 stored in a, - match pattern, , 4 stored in b output 7.

if on other hand inputted 4x5, 4 stored in a x halt reading of further input because not match -. b have undefined value , result of adding value undefined.


Comments