All Questions

500
votes
11answers
129381 views

Why isn't sizeof for a struct equal to the sum of sizeof of each member?

Why does the 'sizeof' operator return a size larger for a structure than the total sizes of the structure's members?
758
votes
14answers
520096 views

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 source fi...
225
votes
15answers
261922 views

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\n", sizeof(days)); printf("%u\n", sizeof(ptr)); return 0; } Is there a way to ...
649
votes
23answers
239954 views
412
votes
13answers
248306 views

What is the difference between char s[] and char *s?

In C, one can use a string literal in a declaration like this: char s[] = "hello"; or like this: char *s = "hello"; So what is the difference? I want to know what actually happens in terms of st...
1354
votes
15answers
75984 views

With arrays, why is it the case that a[5] == 5[a]?

As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it's because of pointer ari...
395
votes
12answers
91312 views

Where do I find the current C or C++ standard documents?

For many questions the answer seems to be found in "the standard". However, where do we find that? Preferably online. Googling can sometimes feel futile, again especially for the C standards, since t...
151
votes
10answers
43643 views

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?
395
votes
9answers
240859 views

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?
42
votes
9answers
25261 views

How to access a local variable from a different function using pointers?

May I have any access to a local variable in a different function? If so, how? void replaceNumberAndPrint(int array[3]) { printf("%i\n", array[1]); printf("%i\n", array[1]); } int * getArray...

Previous Next