@mior.farhan.9 Thankyou for your answer but I had a doubt as to what is the mechanism or how does the compiler interprate that by adding one more % in the string it considers the next %d as part of string and not format specifier..for example by adding \" it interprates " as a string then why cannot we use \ in our case?
for example by adding \" it interprates " as a string then why cannot we use \ in our case?
Because escape characters are interpreted at the compiler level and format specifiers are interpreted at the library level. If \% gave you a literal '%' then it would still be treated as the opening character for a format specifier by the library code. Further, even though the library could be specified to use \%, it would have to actually look like this in user code:
printf("How are you \\%dad\\%");
And the reason is because the compiler will try to interpret any escape, so you need to escape the escape opening character to get a literal '\'. In other words, it's awkward either way, so printf()'s designer took the wiser route, in my opinion, and simply made a format specifier for a literal '%'.
It's probably a little advanced, but you can see a working implementation of printf() here:
I reccommend nullptr's suggestion. You're going to have to get used to the double percent sign anyway, because there are some situations where you need to have both a format specifier and a percent sign in the same call to printf().
printf("Jimmy got a %d%% on his quiz!", percentage);
Using the the "%%" in the format string is the only good solution as far as I'm concerned. The function itself states that this should be used to print a single '%' symbol; it makes no sense to create all sorts of more complex constructs to do something that can be done in a simple manner.
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...