What is the difference between conversion specifiers %i and %d in formatted IO functions (*printf / *scanf)
What is the difference between %d and %i when used as format specifiers in printf and scanf? 4 Answers 4
What is the difference between %d and %i when used as format specifiers in printf and scanf? 4 Answers 4
I can never understand how to print unsigned long datatype in C. Suppose unsigned_foo is an unsigned long, then I try: printf(“%lu\n”, unsigned_foo) printf(“%du\n”, unsigned_foo) printf(“%ud\n”, unsigned_foo) printf(“%ll\n”, unsigned_foo) printf(“%ld\n”, unsigned_foo) printf(“%dl\n”, unsigned_foo) And all of them print some kind of -123123123 number instead of unsigned long that I have. 7 Answers 7
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits in 29 bits int normalInt = 5; printf(“My number is %d bytes wide and its value is %ul. A normal number is %d.\n”, sizeof(num), num, normalInt); return 0; } Output: My number is 8 bytes wide and its value is 285212672l. … Read more
What is the correct format specifier for double in printf? Is it %f or is it %lf? I believe it’s %f, but I am not sure. Code sample #include <stdio.h> int main() { double d = 1.4; printf(“%lf”, d); // Is this wrong? } 5 s 5 “%f” is the (or at least one) correct … Read more