Two questions about basic C programs
Here’s how you would use a for loop;
Here’s how you would use a for loop;
It’s better to use unicode than extended ASCII, which is non-standard. A thread about printing unicode characters in C : printing-utf-8-strings-with-printf-wide-vs-multibyte-string-literals But indeed you need to copy paste unicode characters.. A better way to start:
It documents your intent – you will be storing small numbers, rather than a character. Also it looks nicer if you’re using other typedefs such as uint16_t or int32_t.
Two things I see. First, you’re mixing chars with ints in the matrix array. Second, you’re printing the elements of matrix out to a file using the “%s” format. “%s” expects a null-terminated string where as you are passing chars and ints. This will cause the printf to try and access memory that is out-of-bounds, … Read more
“Segmentation fault” means that you tried to access memory that you do not have access to. The first problem is with your arguments of main. The main function should be int main(int argc, char *argv[]), and you should check that argc is at least 2 before accessing argv[1]. Also, since you’re passing in a float … Read more
Huge difference. As the name implies, a double has 2x the precision of float[1]. In general a double has 15 decimal digits of precision, while float has 7. Here’s how the number of digits are calculated: double has 52 mantissa bits + 1 hidden bit: log(253)÷log(10) = 15.95 digits float has 23 mantissa bits + … Read more
According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bit (see sections 7.17 and 7.18.3). size_tis an unsigned data type defined by several C/C++ standards, e.g. the C99 ISO/IEC 9899 standard, that is defined in stddef.h.1 It can be further imported by inclusion of stdlib.h as … Read more
In pthread_exit, ret is an input parameter. You are simply passing the address of a variable to the function. In pthread_join, ret is an output parameter. You get back a value from the function. Such value can, for example, be set to NULL. Long explanation: In pthread_join, you get back the address passed to pthread_exit by the finished thread. If you pass just a plain … Read more
0L is a long integer value with all the bits set to zero – that’s generally the definition of 0. The ~ means to invert all the bits, which leaves you with a long integer with all the bits set to one. In two’s complement arithmetic (which is almost universal) a signed value with all bits set to one is -1. The reason for … Read more
uint32_t is a numeric type that guarantees 32 bits. The value is unsigned, meaning that the range of values goes from 0 to 232 – 1. This declares a pointer of type uint32_t*, but the pointer is uninitialized, that is, the pointer does not point to anywhere in particular. Trying to access memory through that pointer will cause … Read more