C/C++ hackerrank question

Hello, I am using hackerrank to get better at solving problems, but for some reason it is teaching C stuff in among the c++ stuff. I know C works with C++ and that C++ came from C, but I dont know a lot about it, and because of that I am stuck with a problem.

The error I am getting is with the &l in the scanf and it says "Invalid operands to binary expression ('int *' and 'long')" and i have no idea why. From what I can tell % is still the modulus operator in C, so I am not sure if that is what it is referring to with the binary expression, and that is what is causing the problem. But according to the site, i am using the % correctly.


1
2
3
4
5
6
7
8
9
10
11
 int main() {
    int i;
    long l;
    char c;
    float f;
    double d;
    scanf("%d %ld %c %f %lf" , &i &l &c &f &d );
    printf("%d %ld %c %f %lf" , i, l, c, f, d );
    
    return 0;
}
You need commas between each argument, just like printf.
% here is not an operator; it's part of the string, and is used for formatting by printf/scanf.
%d means it expects an integer, %ld long integer, %c char, etc.
"stringly typed", as the pun goes.
Last edited on
Thank you, that solved the issue. And thanks for the explanations on what stuff is, really not enjoying this c stuff, its very confusing, so that helped out.
Topic archived. No new replies allowed.