+ 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; }
9 Antworten
+ 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.
+ 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?
+ 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.
+ 14
Great, thanks Ketan Lalcheta !
+ 5
You have to write all the code in straight line until you put semicolon. Because your IDE will be 16 bit
+ 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
+ 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)
+ 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...
+ 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