Open leakna opened 3 years ago
That will help you https://www.google.com/url?sa=t&source=web&rct=j&url=https://stackoverflow.com/q/153890&ved=2ahUKEwiVtrTLn6DwAhVDO-wKHaLUAzUQFjAAegQIBRAC&usg=AOvVaw3ohj-uhfwA-Fkgw49Vo0Sx
In c the leading 0 isn't recognized by the compiler. If you want to show it i would suggest you printing it as a text and not as a number.
You cannot print 0 in C language as a integer with output you want. If you want to print it you can do using an array or string.
@leakna, In the case of Integer or float data type, if you add 0 at the front of the number it will not print in the output and print the rest of the number without zero on the output screen. If you want to print zero on the output screen with your number as it is, you have to use string (i.e. array of char) Instead of using Integer. Hope this will help you. Here is the code for it in C -
int main() { char address[] = "0123"; printf("%s",address); return 0; }
int address=0124; printf("%d",address); Output=124 Why it ain't output 0 with all of those number?
I had worked in decoder android APK,
int main() { char address[] = "0124"; printf("%s",address); return 0; }
0124 Process finished.
You cannot print 0 in C language as a integer with output you want. If you want to print it you can do using an array or string.
Yeah... It leads to octal to decimal conversion... When we add 0 before any intiger .
0124=124. Since your input and output are integers and not strings, it is as expected. If you consider your input as a string then the output will be as per your requirement otherwise 0 will not be considered an integer by the compiler.
How to enable or disable usb port using the c programming language
/if 0 is in first place of numbers i.e 012 or 01 etc in a integer variable then the compiler doesnot reconige it so to print that kind of output use string for example: /
void main() { char a[ ] = "0020"; printf(" %s ",a); } // output --> 0020
int address=0124; printf("%d",address); Output=124 Why it ain't output 0 with all of those number?
In C programming, numbers are operated and set to in Decimal value but 0 is considered as a octal value. so we should include "%#o" in printf statement.
why '#' ? because it will include prefix of the number = 0123 which is 0 else it will only print 123.
so your final code would be :
int main() { int num = 0123; printf("%#o", num); return 0; } // output: 0123
int address=0124; printf("%d",address); Output=124 Why it ain't output 0 with all of those number?