Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22461

Format specifer in C++

$
0
0

I'am trying to understand a C++ compiler behaviour. Here is a code, where I made two mistakes intentionally:

  1. forgot %ld format specifier in scanf and just wrote %.
  2. added unknown format specifer for printf - wrote %l instead of %ld for long datatype.
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    // Complete the code.
    int a; long b; char c; float d; double e;
    scanf("%d % %c %f %lf", &a, &b, &c, &d, &e);
    printf("%d \n%l \n%c \n%f \n%lf", a, b, c, d, e);
    return 0;
}

There is a snippet above, that successfully compiles and shows warnings. Why it didn't produce an error for unknown/missing C++ format specifier? How it was compiled?

Output: Input data and strange output after mistakes


Viewing all articles
Browse latest Browse all 22461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>