Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

C programming #162

Open
leakna opened this issue Apr 22, 2021 · 9 comments
Open

C programming #162

leakna opened this issue Apr 22, 2021 · 9 comments

Comments

@leakna
Copy link

leakna commented Apr 22, 2021

int address=0124;
printf("%d",address);
Output=124
Why it ain't output 0 with all of those number?

@kostas741
Copy link

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.

@RahulYddv
Copy link

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.

@shreegilliorkar
Copy link

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

@MOHAMMAD3230
Copy link

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.

@Ritiksw
Copy link

Ritiksw commented Aug 14, 2021

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 .

@Shashank-Vyas
Copy link

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.

@ghost
Copy link

ghost commented Dec 23, 2022

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

@Samzchoy
Copy link

Samzchoy commented Feb 4, 2023

/*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

@yogirajbshinde21
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants