This question already has answers here:
How does a leading zero change a numeric literal in Java?
(3 answers)
Closed 7 years ago.
I'm trying to initialize an int array, but when I go back to reference it, my values change as you can see here. For example my values {010, 011} are changing to {8,9}. Can anyone tell me why this is happening? Thank you in advance!
Numbers starting with a zero are treated as octal by the compiler.
010 in octal is 8.
Maybe just use 10 to initialise the values.
By prefixing the 10 with 0, you are telling the compiler that it is an octal number(base-8 number). To solve this, simply initialize your values as {10,11}
Related
This question already has answers here:
Strange numbers when array is not initialized in C++ [duplicate]
(3 answers)
What happens to a declared, uninitialized variable in C? Does it have a value?
(9 answers)
Closed 1 year ago.
I have tried a simple code and found a strange error(wrt me)
it is something like s[10]
now i have put some number of values into this array.t
like s[0]=0;s[1]=1.s[2]=2 and all others are empty.
now i put a for loop to see how it goes and to my surprise after index 2, some random numbers popping up in output and idk why. It should be null and the loop should have exited but here, it gives me some output like 01248766575...
why is it happening? pls do help me if u know
This question already has answers here:
What does printf return?
(4 answers)
Closed 8 years ago.
A question regarding C Programming
As we all know that printf() is a function to show the out on screen.
And we also know that every function has a return type.
So my question is that:
What the default return type of printf() function ?
printf() returns number of characters successfully printed out.
The return type is int
printf returns int. See this for details.
This is what it has to say
On success, the total number of characters written is returned.
If a writing error occurs, the error indicator (ferror) is set and a negative number is returned.
If a multibyte character encoding error occurs while writing wide characters, errno is set to EILSEQ and a negative number is returned
int, it returns the number of characters that it has printed.
This question already has answers here:
Handling large numbers in C++?
(10 answers)
Closed 8 years ago.
Is it possible to take an input of range greater than what C/C++ provides? Is it possible to accept an input range greater than that of unsigned long long and even larger up to the range of 10^1000?
If it is possible in C/C++, please answer how it can be done, thanks.
There's no bigint in C or C++, however library like this one can provide it: https://code.google.com/p/infint/
Input into a string. Then convert the string into the desired type.
If you use a library that provides types for large integers, such a library might also offer input functions.
This question already has answers here:
What does \x mean in C/C++?
(7 answers)
strlen - the length of the string is sometimes increased by 1
(1 answer)
Closed 8 years ago.
I know that hex-decimal number is usually prefixed with 0x in C/C++ language.
For example, 0x5A means 90 in decimal.
But I saw an example code using single-quoted character with '\x'.
BYTE outputBuffer[index++] = '\x5A'; // instead of 0x5A
Is the meaning of '\x5A' exactly the same as 0x5A?
If so, why is there alternative way of hex-decimal notation?
For a character, both are quite equal.
But only one can be mixed into a string with other normal characters. "ABC\x5A"
And only one can be used to initialize a large integral type: long long x = 0x1234567812345678LL;
This question already has an answer here:
what does DATA TKX/2HKX/ mean in fortran?
(1 answer)
Closed 1 year ago.
Does anyone know the meaning of 4HEND in the following line which comes from an old Fortran code?
DATA XHEND / 4HEND /
4HEND is a Hollerith code to represent the character string "END ". In very old FORTRAN, the variable XHEND might even be a 4-byte integer or real used to hold character data. If implicit typing was in effect in this program, XHEND would have been a real. Another recent question with Hollerith codes: Writing both characters and digits in an array
It replaces assignment
XHEND='END '