488 questions
4
votes
2
answers
209
views
Can I printf a half-precision floating-point value?
I have a _Float16 half-precision variable named x in my C program, and would like to printf() it. Now, I can write: printf("%f", (double) x);, and this will work; but - can I printf x ...
3
votes
3
answers
130
views
behaviour of fprintf when 'ls' format specifier is used with precision set for printing string of wide characters
In the C standard's C17 draft N2176 document, at 7.21.6.1.8, it says that
If no precision is specified, the array shall contain a null wide character. If a precision is specified, no more than that ...
-3
votes
2
answers
155
views
C++ format specifiers in custom functions
Is it possible in C++ to use format specifiers in a custom function?
Like as in the printf() statement, and how you can use e.g. '%d' to insert an int variable:
printf("The number is %d", ...
4
votes
1
answer
136
views
Given a double value x, why (signed long long)(x) != *(signed long long *)(&x)?
I wonder why the code below prints "wrong".
double x = 0x8000000000000000;
signed long long v1 = (signed long long)(x);
signed long long v2 = *(signed long long *)(&x);
printf( v1 == v2? ...
0
votes
2
answers
79
views
Declaration Statement Format Difference
I'm a beginner learning C programming and I'm wondering the difference between these two formats and why one works and the other does not:
// this one doesn't work
#include <stdio.h>
int main(...
-7
votes
1
answer
67
views
Printing using %s
enter image description here
I tried to print a list using format specifier %s in PYTHON. I thought %s will take only the string value from the list. Why did it take even int and float too. Can ...
0
votes
1
answer
74
views
Unexpected value when dereferencing pointer in C
The following code
#include <stdio.h>
int main()
{
long long data = 0xFFFEABCD11112345;
char *pData = (char *)&data;
printf("Value at address %p is %x\n", pData, *...
0
votes
1
answer
217
views
Pointers in C : Why printf %d for a pointer will show different values at each run, while %p work as expected and show the same address?
I'm trying to understand how C is handling the conversion between a pointer and its address. Some courses online (openclassrooms) suggests that displaying a pointer with %d will just convert the hex ...
0
votes
4
answers
204
views
Why does the printf("%c", 0.21) results in 'ß'?
So, here's my C code. While I was toying with my code in order to learn the format specifiers, especially %c:
#include <stdio.h>
void main()
{
double a = 0.21;
printf("%c", a);...
1
vote
2
answers
311
views
Where are the format specifiers implemented/defined in the C language?
I have been working in C for a couple months now and it has never come to my mind to check where actually the format specifiers implemented/defined in the C language format specifiers like:
%f
%d
%p
%...
1
vote
2
answers
3k
views
How to print hexadecimal values in "0x" format in C
I am trying to print hexadecimal values in C.
A simple known program to print hexadecimal value...( Using %x or %X format specifier)
#include<stdio.h>
int main()
{
unsigned int num = 10;
...
6
votes
2
answers
225
views
Interpreting the format specifier in printf("%# 01.1g",9.8)
Consider the following printf instruction:
printf("%# 01.1g", 9.8);
what should it print?
I'm reading the description of the g specifier on cppreference.com, which says (text for G removed):...
0
votes
2
answers
143
views
Comparing int64 and float value does not work inside loop
The following loop would run only when off which is uint64_t is less than the value returned by ceil which is double. However I don't see the loop being executed.
#include <bits/stdc++.h>
using ...
1
vote
3
answers
812
views
What is the point of format specifier in C?
What is the point of format specifier in C if we have allready set the type of variable before printf?
For example:
#include<stdio.h>
int main(void)
{
int a=7
printf("%d", a);
}...
0
votes
0
answers
43
views
I get some warnings when i use %llu as format specifier for unsigned long long with printf() function in C [duplicate]
I get some warnings from my IDE (Code:Blocks, Win64) when i use %llu as format specifier for unsigned long long in C with printf().
warning: unknown conversion type character 'l' in format
warning: ...
0
votes
2
answers
390
views
When using int and float datatype, why does the output of "%d" appear different?
#include <stdio.h>
#include <conio.h>
int main() {
int a = 2;
float b = 4;
clrscr();
printf("%d \n", a + b);
printf("%f \n", a + b);
printf(&...
2
votes
1
answer
4k
views
What is the meaning of this format `%02hhx`?
I saw in some functions that in order to convert number to hexadecimal format, using this format: printf("%02hhx", some_char); , but I don't understand why, and what is the meaning of this ...
-5
votes
2
answers
452
views
why it is giving output as 0.0000? [duplicate]
#include <stdio.h>
int main()
{
signed char ch;
ch = 128;
printf("%f", ch);
return 0;
}
Can anyone explain why it is printing 0.000 every time??
I tried %f as a format ...
-1
votes
1
answer
66
views
Malloc Array, trouble printing in new function in C [duplicate]
Hi I've created an array and used malloc to store it so it could use it in a different function but now I'm running into problems with printing the array as it says:
warning: format '%d' expects ...
1
vote
1
answer
177
views
%d vs %f format specifier (not sure of output): C
I get that %d is the format specifier for type decimal, and %f is for float, but I'm not sure why the output of the 2nd print statement is 3.
#include <stdio.h>
int main()
{
float arr[5] = {...
0
votes
1
answer
64
views
How a Gap in Between the Format Specifier, Making my Program Run Infinitely?
The problem is only in the last scanf of the program
The following program works perfectly the 1st time, but as soon as I use the again (from the restart/quit goto program in the last), the whole ...
-2
votes
1
answer
478
views
%X format specifier prints value only up to 4 bytes?
Hex value of 6378624653 is : 0x17C32168D
But this code prints : 0x7C32168D
#include<iostream>
int main()
{
int x = 6378624653;
printf("0x%x", x);
}
can anyone explain why ...
2
votes
1
answer
170
views
How to print character repeatedly using specifier instead of loop in java? [duplicate]
I want to print a char '=' repeatedly where I give the no. of times the asterisk should be repeated.
Example: count = 20 and I want to print ==================== using printf() and format specifiers.
0
votes
2
answers
153
views
Differing output with printf using %d and %i
I found questions about %i and %d on here, but all of them seemed to claim that they were the same in printf.
Compiler: Apple clang version 12.0.5 (clang-1205.0.22.9)
Note: 15 is 017 in octal and 0xf ...
1
vote
2
answers
831
views
Meanning of %! and %K with printf
I try to rewrite printf function and i found a strange result when use format specifier (%) with ! or K. I want to understand why i get this result.
printf("%!");
printf("%K&...