I declared a character array and at the time of taking input I used %d instead of %s in function scanf. Isnt my compiler suppose to flash an error for this? Or is it, due to some reason, not considered as compile time error ?
Anyone??
Or is it, due to some reason, not considered as compile time error
Correct. The compiler does NOT check for correspondence between a format string and arguments in a scanf statement. Even at run time, there is no type checking of arguments. Arguments are blindly interpreted per the format string.
#include <cstdio>
int main()
{
char str[80];
// warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘char*’
std::scanf("%d", str);
}