Giter Club home page Giter Club logo

Comments (9)

MOHAMMAD3230 avatar MOHAMMAD3230 commented on August 23, 2024 2

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,

#include <stdio.h>
int main()
{
char address[] = "0124";
printf("%s",address);
return 0;
}

0124
Process finished.

from c.

kostas741 avatar kostas741 commented on August 23, 2024 1

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.

from c.

shreegilliorkar avatar shreegilliorkar commented on August 23, 2024 1

@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 -

#include <stdio.h>
int main()
{
char address[] = "0123";
printf("%s",address);
return 0;
}

from c.

yogirajbshinde21 avatar yogirajbshinde21 commented on August 23, 2024 1

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 :
#include<stdio.h>
#include<conio.h>
int main() {
int num = 0123;
printf("%#o", num);
return 0;
}
// output: 0123

from c.

RahulYddv avatar RahulYddv commented on August 23, 2024

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.

from c.

Ritiksw avatar Ritiksw commented on August 23, 2024

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 .

from c.

Shashank-Vyas avatar Shashank-Vyas commented on August 23, 2024

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.

from c.

 avatar commented on August 23, 2024

How to enable or disable usb port using the c programming language

from c.

Samzchoy avatar Samzchoy commented on August 23, 2024

/*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: */
#include <stdio.h>
void main()
{
char a[ ] = "0020";
printf(" %s ",a);
}
// output --> 0020

from c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.