243 Answered Questions for the topic C

C

05/20/19

How do I concatenate const/literal strings in C?

I'm working in C, and I have to concatenate a few things.Right now I have this: message = strcat("TEXT ", var); message2 = strcat(strcat("TEXT ", foo), strcat(" TEXT ", bar));Now if you have... more
C

05/20/19

What REALLY happens when you don't free after malloc?

This has been something that has bothered me for ages now.We are all taught in school (at least, I was) that you MUST free every pointer that is allocated. I'm a bit curious, though, about the... more
C

05/20/19

Why does printf not flush after the call unless a newline is in the format string?

Why does `printf` not flush after the call unless a newline is in the format string? Is this POSIX behavior? How might I have `printf` immediately flush every time?
C

05/20/19

Is an array name a pointer?

Is an array's name a pointer in C?If not, what is the difference between an array's name and a pointer variable?
C

05/19/19

Pointers in C: when to use the ampersand and the asterisk?

I'm just starting out with pointers, and I'm slightly confused. I know `&` means the address of a variable and that `*` can be used in front of a pointer variable to get the value of the object... more
C

05/19/19

Most Efficient Algorithm for Bit Reversal ( from MSB->LSB to LSB->MSB) in C?

What is the best algorithm to achieve the following:`0010 0000 => 0000 0100`The conversion is from MSB->LSB to LSB->MSB. All bits must be reversed; that is, this is *not*... more
C

05/19/19

How to make a variadic macro (variable number of arguments)?

I want to write a macro in C that accepts any number of parameters, not a specific numberexample: #define macro( X ) something_complicated( whatever( X ) )where `X` is any number of parametersI... more
C

05/19/19

Why does the arrow (->) operator in C exist?

The dot (`.`) operator is used to access a member of a struct, while the arrow operator (`->`) in C is used to access a member of a struct which is referenced by the pointer in question.The... more
C

05/19/19

How to define an enumerated type (enum) in C?

I'm not sure what is the proper syntax for using C enums. I have the following code: enum {RANDOM, IMMEDIATE, SEARCH} strategy; strategy = IMMEDIATE;But this does not compile, with the... more
C

05/18/19

Forward an invocation of a variadic function in C?

In C, is it possible to forward the invocation of a variadic function? As in, int my_printf(char *fmt, ...) { fprintf(stderr, "Calling printf with fmt %s", fmt); return... more
C

05/18/19

How to expand nested variables in makefile?

I am using simulink to generate c-code. For the compilation of the code a generate makefile is used. In this make file the following variable "MAKECMD" is made. This variable is used to make a... more
C

05/18/19

How do I use extern to share variables between source files?

I know that global variables in C sometimes have the `extern` keyword. What is an `extern` variable? What is the declaration like? What is its scope?This is related to sharing variables across... more
C

05/17/19

Arrow operator (->) usage in C?

I am currently learning C by reading a good beginner's book called "Teach Yourself C in 21 Days" (I have already learned Java and C# so I am moving at a much faster pace). I was reading the chapter... more
C

05/15/19

Why use double pointer? or Why use pointers to pointers?

When should a double pointer be used in C? Can anyone explain with a example?What I know is that a double pointer is a pointer to a pointer. Why would I need a pointer to a pointer?

05/14/19

C fopen vs open?

Is there any reason (other than syntactic ones) that you'd want to use FILE *fdopen(int fd, const char *mode);or FILE *fopen(const char *path, const char *mode);instead of int open(const... more

What is a bus error?

What does the "bus error" message mean, and how does it differ from a segfault?

How to convert between lux and exposure value?

How to convert from an [exposure value][1] to [lux][2]? Thanks! i.e. what's the formula behind [this chart][3]? [1]:... more
C

05/10/19

What is the >>>= operator in C?

Given by a colleague as a puzzle, I cannot figure out how this C program actually compiles and runs. What is this `>>>=` operator and the strange `1P1` literal? I have tested in Clang and... more
C

05/10/19

Effects of the extern keyword on C functions?

In C, I did not notice any effect of the `extern` keyword used before function declaration.At first, I thought that when defining `extern int f();` in a single file **forces** you to implement it... more
C

05/08/19

size_t vs. uintptr_t?

The C standard guarantees that `size_t` is a type that can hold any array index. This means that, logically, `size_t` should be able to hold any pointer type. I've read on some sites that I found... more
C

05/08/19

How to correctly use the extern keyword in C?

My question is about when a function should be referenced with the `extern` keyword in C.I am failing to see when this should be used in practice. As I am writing a program all of the functions... more
C

05/08/19

register keyword in C?

What does the `register` keyword do in C language? I have read that it is used for optimizing but is not clearly defined in any standard. Is it still relevant and if so, when would you use it?
C

05/07/19

Divide a number by 3 without using *, /, +, -, % operators?

How would you divide a number by 3 without using `*`, `/`, `+`, `-`, `%`, operators?The number may be signed or unsigned.

05/06/19

What are the differences between .so and .dylib on osx?

.dylib is the dynamic library extension on OSX, but it's never been clear to me when I can't / shouldn't use a traditional unix .so shared object.Some of the questions I have: - At a conceptual... more
C

05/05/19

How come an array's address is equal to its value in C?

In the following bit of code, pointer values and pointer addresses differ as expected.But array values and addresses don't!How can this be?Output my_array = 0022FF00 &my_array = 0022FF00 ... 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.