+ 20

Why does the following code give a compilation error on code playground? If I comment out any one of the lines, it works fine.

#include <stdio.h> int main() { printf("sizeof int: %d \n", sizeof(int)); printf("sizeof float: %d \n", sizeof(float)); printf("sizeof double: %d \n", sizeof(double)); printf("sizeof char: %d \n", sizeof(char)); printf("sizeof int*: %d \n", sizeof(int*)); printf("sizeof float*: %d \n", sizeof(float*)); printf("sizeof double*: %d \n", sizeof(double*)); printf("sizeof char*: %d \n", sizeof(char*)); return 0; }

25th Sep 2018, 1:58 AM
Sonic
Sonic - avatar
9 ответов
+ 21
Ketan Lalcheta don't worry I managed to fix it. The problem was that sizeof returns a long long instead of an int and I had to use %I64d instead of %d in the printf to print the result of sizeof.
25th Sep 2018, 5:07 AM
Sonic
Sonic - avatar
+ 16
Thanks again for the suggestion Ketan Lalcheta but removing almost all spaces didn't work for me. Are you able to check the latest C code in my profile and see if you get the same error for the same code?
25th Sep 2018, 4:46 AM
Sonic
Sonic - avatar
+ 16
Kirk Schafer thanks for that tip for finding the warnings. Also see my previous response on how the code was fixed (also available in the C code under my profile today). It's a bit sad that we have to use tricks like that to find the actual warnings.
25th Sep 2018, 5:10 AM
Sonic
Sonic - avatar
+ 14
Great, thanks Ketan Lalcheta !
25th Sep 2018, 3:18 AM
Sonic
Sonic - avatar
+ 5
You have to write all the code in straight line until you put semicolon. Because your IDE will be 16 bit
8th Oct 2018, 5:32 AM
AKS
AKS - avatar
+ 3
Sonic I just checked your code on playground and found that there are special characters got copied (might be when you copied code on playground)... rewrite all on playground or remove spaces (inturn it is special characters...you can remove it and provide new spaces if you wish) from your code manually and it works.. I just removed spaces and it worked
25th Sep 2018, 3:13 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 3
Actually...an anomaly is that commenting ANY line makes it work. If you add an invalid command, like this one, at the end of your program... bang; return 0; } The error will cause the compiler to dump all the previous warnings, and the list of warnings is very long. As seen is this Q&A: https://www.sololearn.com/discuss/1507972/?ref=app The LONG pause before SoloLearn returns Compiler Error seems to be related to exceeding about 2K in response, which means... Fix your warnings...and I either: A. Add to the "maybe a bug" report [edit: DONE] B. We use this as proof that long pauses probably tell us the output is too long (here, it hints at those warnings)
25th Sep 2018, 4:46 AM
Kirk Schafer
Kirk Schafer - avatar
+ 3
Well, it is kindof an obscure conclusion that I just made and...it does improve the beginner's experience if the code just runs without reporting non-fatal stuff. Still, I wonder if there'd be a way to get warnings as an optional output item so main output stays the same...
25th Sep 2018, 5:36 AM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Kirk Schafer i have a code that works on both the compiler on my phone and on my computer but it's giving compilation error on SL
26th Dec 2018, 8:53 PM
✳AsterisK✳
✳AsterisK✳ - avatar