248 Answered Questions for the topic C
C
04/18/19
What is the difference between char * const and const char *?
What's the difference between: char * const and const char *
C
04/18/19
How to printf "unsigned long" in C?
I can never understand how to print `unsigned long` datatype in C.Suppose `unsigned_foo` is an `unsigned long`, then I try:* `printf("%lu\ ", unsigned_foo)`* `printf("%du\ ", unsigned_foo)`*...
more
C
04/18/19
What is size_t in C?
I am getting confused with `size_t` in C. I know that it is returned by the `sizeof` operator. But what exactly is it? Is it a data type?Let's say I have a `for` loop: for(i = 0; i <...
more
C: XNOR / Exclusive-Nor gate?
I am trying to find the most effective way of writing a XNOR gate in C.
if(VAL1 XNOR VAL2)
{
BLOCK;
}
Any suggestions?
Thanks.
C
04/16/19
static const vs "#define" vs "enum"?
Which one is better to use among the below statements in C? static const int var = 5;or #define var 5or enum { var = 5 };
C
04/13/19
Correct format specifier for double in printf?
What is the correct format specifier for `double` in printf? Is it `%f` or is it `%lf`? I believe it's `%f`, but I am not sure.###Code sample #include int main() { double d = 1.4; ...
more
C
04/12/19
What is the difference between NULL, '\\0' and 0?
In C, there appear to be differences between various values of zero -- `NULL`, `NUL` and `0`.I know that the ASCII character `'0'` evaluates to `48` or `0x30`.The `NULL` pointer is usually defined...
more
Why does ENOENT mean "No such file or directory"?
What is "ENT" short for?
The `error` :
>No such file or directory
should just be named by "ENOFILE".
Is there any story or reason?
C
04/11/19
How to print a int64_t type in C?
C99 standard has integer types with bytes size like int64_t. I am using the following code: #include #include int64_t my_int = 999999999999999999; printf("This is my_int: %I64d\ ",...
more
C
04/11/19
Difference between malloc and calloc?
What is the difference between doing: ptr = (char **) malloc (MAXELEMS * sizeof(char *));or: ptr = (char **) calloc (MAXELEMS, sizeof(char*));When is it a good idea to use calloc over malloc...
more
C
04/10/19
What does "static" mean in C?
I've seen the word `static` used in different places in C code; is this like a static function/class in C# (where the implementation is shared across objects)?
C
04/08/19
MIN and MAX in C?
Where are `MIN` and `MAX` defined in C, if at all?What is the best way to implement these, as generically and type safely as possible? (Compiler extensions/builtins for mainstream compilers...
more
C
04/06/19
What exactly is a C pointer if not a memory address?
In a reputable source about C, the following information is given after discussing the `&` operator:> ... It's a bit unfortunate that the terminology *[address of]* remains, because it...
more
C Logic
04/04/19
1 = false and 0 = true?
I came across an is_equals() function in a c API at work that returned 1 for non-equal sql tables (false) and 0 for equal ones (true). I only realized it after running test cases on my code, one...
more
C
04/04/19
How to convert a string to integer in C?
I am trying to find out if there is an alternative way of converting string to integer in C.I regularly pattern the following in my code. char s[] = "45"; int num = atoi(s);So, is there a...
more
What is Linux’s native GUI API?
I hope this doesn’t come across as a stupid question but it’s always something I have wondered. Both Windows (Win32 API) and OS X (Cocoa) have their own APIs to handle windows, events and other OS...
more
Differences between fork and exec?
What are the differences between `fork` and `exec`?
04/02/19
Why does the C preprocessor interpret the word "linux" as the constant "1"?
Why does the C preprocessor in GCC interpret the word `linux` (small letters) as the constant `1`?
test.c:
#include
int main(void)
{
int linux = 5;
return 0;
}
Result of `$ gcc -E...
more
C
04/02/19
How do I determine the size of my array in C?
How do I determine the size of my array in C? That is, the number of elements the array can hold?
C
03/30/19
typedef fixed length array?
I have to define a 24-bit data type.I am using `char[3]` to represent the type. Can I typedef `char[3]` to `type24`? I tried it in a code sample. I put `typedef char[3] type24;` in my header file....
more
C
03/29/19
How do you pass a function as a parameter in C?
I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?
C
03/27/19
How does free know how much to free?
In C programming, you can pass any kind of pointer you like as an argument to free, how does it know the size of the allocated memory to free? Whenever I pass a pointer to some function, I have to...
more
C
03/27/19
How to know what the 'errno' means?
When calling `execl(...)`, I get an `errno=2`. What does it mean? How can I know the meaning of this `errno`?
C
03/27/19
Is it better to use C void arguments "void foo(void)" or not "void foo()"?
What is better: `void foo()` or `void foo(void)`?With void it looks ugly and inconsistent, but I've been told that it is good. Is this true?Edit: I know some old compilers do weird things, but if...
more
C
03/26/19
How to find the 'sizeof' (a pointer pointing to an array)?
First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\ ", sizeof(days)); printf("%u\ ", sizeof(ptr)); ...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.