Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

You can also try this:
***select
t1.value, t2.value
from t1
left outer join t2
on t1.value = t2.value
union all
select
t1.value, t2.value
from t2
left outer join t1
on t1.value = t2.value
where
t1.value IS NULL ***
3 years ago
You can try this:
***select table_name from all_tables***
3 years ago
If you're only need keys, you can iterate through the **keySet()** of the map:

***Map map = ...;

for (String key : map.keySet()) {
// ...
}***

If you only need the values, use **values()**:

***for (Object value : map.values()) {
// ...
}***

Finally, if you want both the key and value, use **entrySet()**:

***for (Map.Entry entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
}***
3 years ago
Well, in ASCII code, the numbers (digits) start from 48. All you need to do is:

***int x = (int)character - 48;***

Or, since the character '0' has the ASCII code of 48, you can just write:

***int x = character - '0'; // The (int) cast is not necessary.***
3 years ago
You could use a small table to improve your speed. Similar techniques are useful in the embedded world, for example, to invert a byte:

***const char *bit_rep[16] = {
[ 0] = "0000", [ 1] = "0001", [ 2] = "0010", [ 3] = "0011",
[ 4] = "0100", [ 5] = "0101", [ 6] = "0110", [ 7] = "0111",
[ 8] = "1000", [ 9] = "1001", [10] = "1010", [11] = "1011",
[12] = "1100", [13] = "1101", [14] = "1110", [15] = "1111",
};

void print_byte(uint8_t byte)
{
printf("%s%s", bit_rep[byte >> 4], bit_rep[byte & 0x0F]);
}***
3 years ago
1. Typedef is used to ease the reading of the code - especially for pointers to functions, or structure names.

2. That syntax is not obvious to read, at least when beginning. Using a typedef declaration instead eases the reading

3. Yes, a function pointer stores the address of a function. This has nothing to do with the typedef construct which only ease the writing/reading of a program ; the compiler just expands the typedef definition before compiling the actual code.

Example:

***typedef int (*t_somefunc)(int,int);

int product(int u, int v) {
return u*v;
}

t_somefunc afunc = &product;
...
int x2 = (*afunc)(123, 456); // call product() to calculate 123*456 ***
3 years ago
In C++, there are three distinct character types:

char
signed char
unsigned char

If you are using character types for text, use the unqualified char:

it is the type of character literals like 'a' or '0'.
it is the type that makes up C strings like "abcde"

It also works out as a number value, but it is unspecified whether that value is treated as signed or unsigned. Beware character comparisons through inequalities - although if you limit yourself to ASCII (0-127) you're just about safe.

If you are using character types like numbers, use:

**signed char**, which gives you at least the -127 to 127 range. (-128 to 127 is common)
**unsigned char**, which gives you at least the 0 to 255 range.
The C++ standard only gives the minimum range of values that each numeric type is required to cover. sizeof (char) is required to be 1 (i.e. one byte), but a byte could in theory be for example 32 bits. sizeof would still be report its size as 1 - meaning that you could have sizeof (char) == sizeof (long) == 1.
3 years ago
You can do it with a compound literal. According to that page, it works in C99 (which also counts as ANSI C).

***MY_TYPE a;

a = (MY_TYPE) { .flag = true, .value = 123, .stuff = 0.456 };
...
a = (MY_TYPE) { .value = 234, .stuff = 1.234, .flag = false };***

The designations in the initializers are optional; you could also write:

***a = (MY_TYPE) { true, 123, 0.456 };
...
a = (MY_TYPE) { false, 234, 1.234 };***
3 years ago
I use this piece of code, it works OK with me so far.

***bool is_file_exist(const char *fileName)
{
std::ifstream infile(fileName);
return infile.good();
}***
3 years ago
Format %lf is a perfectly correct printf format for double, exactly as you used it. There's nothing wrong with your code.

Format %lf in printf was not supported in old (pre-C99) versions of C language, which created superficial "inconsistency" between format specifiers for double in printf and scanf. That superficial inconsistency has been fixed in C99.

You are not required to use %lf with double in printf. You can use %f as well, if you so prefer (%lf and %f are equivalent in printf). But in modern C it makes perfect sense to prefer to use %f with float, %lf with double and %Lf with long double, consistently in both printf and scanf.
3 years ago
It depends, if you are referring to unsigned long the formatting character is **"%lu"**. If you're referring to signed long the formatting character is **"%ld"**.
3 years ago
ANSI C99/C11 don't include an extra printf conversion specifier for bool. However, since any integral type shorter than int is promoted to int when passed down to printf(), you can use %d:

***bool x = true;
printf("%d\n", x); // prints 1***
3 years ago