Passing an array by reference in C?

In C arrays are passed as a pointer to the first element. They are the only element that is not really passed by value (the pointer is passed by value, but the array is not copied). That allows the called function to modify the contents. Now, if what you want is changing the array itself … Read more

Zero an array in C code

C99 [$6.7.8/21] If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have … Read more

Reversing a string in C

If you want to practice advanced features of C, how about pointers? We can toss in macros and xor-swap for fun too! A pointer (e.g. char *, read from right-to-left as a pointer to a char) is a data type in C that is used to refer to location in memory of another value. In this case, the location where … Read more

Variable warning set but not used

none shows up twice in this code snippet: And then: If, for example, you later had: or or something to that effect, we would say none is “used”, but as the code is, you have: “none” set but not used; exactly what the compiler said. In the pastebin link I see your problem: You wrote this: You meant to write this: … Read more

How do I concatenate const/literal strings in C?

In C, “strings” are just plain char arrays. Therefore, you can’t directly concatenate them with other “strings”. You can use the strcat function, which appends the string pointed to by src to the end of the string pointed to by dest: Here is an example from cplusplus.com: For the first parameter, you need to provide the destination buffer itself. The destination buffer must … Read more