243 Answered Questions for the topic C

C

05/05/19

Using boolean values in C?

C doesn't have any built-in boolean types. What's the best way to use them in C?
C

05/05/19

Why #define TRUE (1==1) in a C boolean macro instead of simply as 1?

I've seen definitions in C #define TRUE (1==1) #define FALSE (!TRUE)Is this necessary? What's the benefit over simply defining TRUE as 1, and FALSE as 0?
C

05/05/19

How to convert integer to string in C?

I tried this example: /* itoa example */ #include <stdio.h> #include <stdlib.h> int main () { int i; char buffer [33]; printf ("Enter a number: "); ... more
C

05/05/19

Why should we typedef a struct so often in C?

I have seen many programs consisting of structures like the one below typedef struct { int i; char k; } elem; elem user;Why is it needed so often? Any specific reason or... more
C

05/05/19

Does Objective C have garbage collection?

C

05/05/19

Difference between a Structure and a Union?

Is there any good example to give the difference between a `struct` and a `union`?Basically I know that `struct` uses all the memory of its member and `union` uses the largest members memory space.... more
C

05/04/19

How to achieve function overloading in C?

Is there any way to achieve function overloading in C? I am looking at simple functions to be overloaded like foo (int a) foo (char b) foo (float c , int d)I think there is no... more
C

05/04/19

Getting an incorrect output for e^x function I made for class, and getting the wrong number of terms?

So for my Intro to computer programming class we have to write 3 separate functions, one to calculate factorials, one to calculate powers (x^n), and one to calculate the number of terms of the... more
C

05/04/19

What is the difference between ++i and i++?

In C, what is the difference between using `++i` and `i++`, and which should be used in the incrementation block of a `for` loop?
C

05/04/19

close vs shutdown socket?

In C, I understood that if we close a socket, it means the socket will be destroyed and can be re-used later.How about shutdown? The description said it closes half of a duplex connection to that... more
C

05/03/19

How do you format an unsigned long long int using printf?

#include <stdio.h> int main() {  unsigned long long int num = 285212672; //FYI: fits in 29 bits  int normalInt = 5;  printf("My number is %d bytes wide and its value is %ul. A... more
C

05/01/19

how to use #ifdef with an OR condition?

Sorry for asking very basic question. I would like to set OR condition in #ifdef directive.?How to do that ?I tried #ifdef LINUX | ANDROID ... .. #endif It did not work? What is the... more
C

04/30/19

Why does this for loop exit on some platforms and not on others?

I have recently started to learn C and I am taking a class with C as the subject. I'm currently playing around with loops and I'm running into some odd behaviour which I don't know how to explain. ... more
C

04/28/19

This C function should always return false, but it doesn’t?

I stumbled over an interesting question in a forum a long time ago and I want to know the answer.Consider the following C function:f1.c-- #include <stdbool.h> bool f1() {  int... more
C

04/28/19

What is the printf format specifier for bool?

Since ANSI C99 there is `_Bool` or `bool` via `stdbool.h`. But is there also a `printf` format specifier for bool?I mean something like in that pseudo code: bool x = true; printf("%B\ ",... more

What is ":-!!" in C code?

I bumped into this strange macro code in [/usr/include/linux/kernel.h][1]: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the... more
C

04/26/19

Printing leading 0's in C?

I'm trying to find a good way to print leading 0's, such as 01001 for a zipcode. While the number would be stored as 1001, what is a good way to do it?I thought of using either case statements/if... more

04/26/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 <stdio.h> int main(void) { int linux = 5; ... more
C

04/23/19

How does C compute sin() and other math functions?

I've been poring through .NET disassemblies and the GCC source code, but can't seem to find anywhere the actual implementation of `sin()` and other math functions... they always seem to be... more
C

04/20/19

C default arguments?

Is there a way to specify default arguments to a function in C?

Syntax highlighting in Microsoft Office Word?

How do I easily highlight the syntax of PHP code in Word? I need to paste some code (ANSI C) in Microsoft Office Word, and I need some form of syntax highlighting (instead of simply changing the... more

What do pty and tty mean?

I noticed there are many mentions of `pty` and `tty` in some opensource projects, could someone can tell me what do they mean and what is the difference between them? Thanks!
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

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.