Where is `%p` useful with printf?

They do not do the same thing. The latter printf statement interprets b as an unsigned int, which is wrong, as b is a pointer. Pointers and unsigned ints are not always the same size, so these are not interchangeable. When they aren’t the same size (an increasingly common case, as 64-bit CPUs and operating … Read more

Strings and character with printf

If you try this: #include<stdio.h> void main() { char name[]=”siva”; printf(“name = %p\n”, name); printf(“&name[0] = %p\n”, &name[0]); printf(“name printed as %%s is %s\n”,name); printf(“*name = %c\n”,*name); printf(“name[0] = %c\n”, name[0]); } Output is: name = 0xbff5391b &name[0] = 0xbff5391b name printed as %s is siva *name = s name[0] = s So ‘name’ is … Read more

How do I print a non-null-terminated string using printf?

printf(“%.*s”, length, string); Use together with other args: printf(“integer=%d, string=%.*s, number=%f”, integer, length, string, number); // ^^^^ ^^^^^^^^^^^^^^ In C you could specify the maximum length to output with the %.123s format. This means the output length is at most 123 chars. The 123 could be replaced by *, so that the length will be … Read more

What is PRIu64 in C?

PRIu64 is a format specifier, introduced in C99, for printing uint64_t, where uint64_t is (from linked reference page): unsigned integer type with width of … 64 bits respectively (provided only if the implementation directly supports the type) PRIu64 is a string (literal), for example the following: printf(“%s\n”, PRIu64); prints llu on my machine. Adjacent string … Read more

why does %d stand for Integer?

It stands for “decimal” (base 10), not “integer.” You can use %x to print in hexadecimal (base 16), and %o to print in octal (base 8). An integer could be in any of these bases. In printf(), you can use %i as a synonym for %d, if you prefer to indicate “integer” instead of “decimal,” … Read more

Is it possible to print out only a certain section of a C-string, without making a separate substring?

Is it possible to print out only the last 5 bytes of this string? Yes, just pass a pointer to the fifth-to-the-last character. You can determine this by string + strlen(string) – 5. What about the first 5 bytes only? Use a precision specifier: %.5s #include <stdio.h> #include <string.h> char* string = “Hello, how are … Read more

Why does printf(“%f”,0); give undefined behavior?

The “%f” format requires an argument of type double. You’re giving it an argument of type int. That’s why the behavior is undefined. The standard does not guarantee that all-bits-zero is a valid representation of 0.0 (though it often is), or of any double value, or that int and double are the same size (remember … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)