Printing integer returns *0x0 [closed] - c

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm learning C and trying to understand the printf function better.
When I print:
printf("%d", 6 << 1);
it returns 120x0 instead of the expected 12. Why is that? I'm using gcc compiler.

Change this
printf("%d", 6 << 1);
to
printf("%d\n", 6 << 1);
and try to always add a newline character to distinguish the printed text from other output, unless you need to print things next to each other.
You should now see
12
0x00

most likely you're code is working properly printing 12 and later you print 0x0 somewhere.

Related

Why C gave a weird output when adding floats and integers? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
I am learning C right now and I understand that I can't add an integer with a decimal like so:
#include <stdio.h>
int main() {
printf("%d",15+9.0);
return 0;
However when running this I expected some sort of an error. Instead, I got a weird output:
-1866308488
Can someone help me understand why it gave me this output?
As #PaulMcKenzie said, C expected an int based on the %d format specifier. You gave it a double instead. C often gives unexpected behavior instead of throwing an error like Java or C#. What happens to a double variable when %d is used in a printf? says that the resulting behavior is undefined and OS-specific.

Why the output of printf("%d","") is 173 in c language? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
#include<stdio.h>
#include<conio.h>
void main()
{
printf("%d","");//printing output
getch();
}
The output is 173 .I am not getting why the output is 173.
First, you're trying to print a string as decimal integer, which means the decimal you try to print is going to be the pointer to the string (actually a pointer to the array of characters) and not the string itself. To use an individual character use single-quotes, not double-quotes.
To accomplish what you're actually trying to do, do this:
printf("%d", ' ');
Note there is an actual space between the two single-quotes.
The result will be 32, which is the decimal value for the ASCII Space character.

1 not equal to 0 but the code says equal in c [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
This code prints both "equal" and "1 0".
Why is this happening even though 1 != 0 ?
if(2/2 == 2/2.0)
printf("equal \n");
printf("%d %d", 2/2, 2/2.0);
The result of 2/2.0 is of type double. But you are using %d to print it, which is undefined behaviour. Use %lf instead to print a double. That's why you get 0 which is a possible result of invoking undefined behaviour.

Lua Error 'for' limit must be a number [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm working on a scanner plugin that loops through a range of various channels in increments of up to 32.
I'm new to Lua.
Tables, tables everywhere.
I did not know Lua did not do +=, ++.
i = i + 1 -- flashbacks.
I'm running into this variable type error,
plugins/scanner/main.lua:136: 'for' limit must be a number
and i've checked my variable types. both say they're numbers.
right now i'm working on getting the incremental loops running smoothly.
here's the link to the code :
http://codepad.org/Dc3jBBrx
thanks again, stack.
I think it's probably just a typo on line 136
Scanner.innerRrangeMax should be Scanner.innerRangeMax
e.g line 136 is
for i = Scanner.innerRangeMin, Scanner.innerRrangeMax do
try
for i = Scanner.innerRangeMin, Scanner.innerRangeMax do

how to print out the following value using printf in C? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a variable:
int a = 0x0304;
I print it out like this:
printf("the value is 0x4x\n", a);
but it shows the value is 0x304, I want the result should be the value is 0x0304, how to print it out like this?
Try adding a leading 0 to your format specifier - %04x
printf("the value is 0x%04x\n", a);
Just in case its omission from your question wasn't a typo, note that I've also added a % to make this a format specifier. As it stands, the code in your question would have just echoed the value is 0x4x

Resources