why global variable in C takes zero as initial value? [duplicate] - c

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Static variable initialization?
why global variable in C takes zero as initial value?

This required for a compiler to conform to the C standard.
The reason for the design choice is likely that having random garbage in your uninitialized variables makes errors much harder to detect.

Related

In C++11 when should we explicitly use std::decay? [duplicate]

This question already has answers here:
What is std::decay and when it should be used?
(2 answers)
Closed 6 years ago.
We know that compiler will decay array/function to pointers when needed(according to context), then when is the time we should explicitly use std::decay?
Is there any task that requires us to use it, or else, compiler doesn't know how to handle it?
Thanks.
Simply put, decay::type is the identity type-transformation except if T is an array type or a reference to a function type. In those cases the decay::type yields a pointer or a pointer to a function, respectively.
For more detail please see this https://stackoverflow.com/a/25732651/1691223

Getting an overflow when creating an integer array? [duplicate]

This question already has answers here:
what is causing SIGSEV?
(3 answers)
Closed 8 years ago.
I am getting an overflow for using this.
int x[471][640];
Someone told me to use Malloc? I have no idea what that is. Its not in my book nor my lectures. Any fix to this?
If you do not know yet about C function malloc then you can try another approach. For example declare your local array as
static int x[471][640];
that is as having static storage duration.
If you also do not know yet about the keyword static then the only approach I can suggest is to declare the array globally that is outside any function. for example before main:)

What does `register` do in GStreamer [duplicate]

This question already has answers here:
"register" keyword in C?
(19 answers)
Closed 8 years ago.
I was reading some gstreamer code and fell on this line
register int i;
Does anyone know what the register keyword does ?
Another SO question has already answered this.
Answer From Brian Knoblauch:
It's a hint to the compiler that the variable will be heavily used and
that you recommend it be kept in a processor register if possible.
Most modern compilers do that automatically, and are better at picking
them than us humans. :-)
So, essentially, it assures the programmer that the compiler will know that the variable will be utilized numerous times and to keep that variable in the CPU register. As stated in the other answer, most compilers do this automatically.

What section of memory are static local constants stored in? [duplicate]

This question already has answers here:
Where are static variables stored in C and C++?
(16 answers)
Closed 9 years ago.
I know global constant will be stored in "Read Only" section. But What section of memory are static local constants stored in?
It depends on the compiler and the platform you're compiling for. They may be placed on the bottom of the stack, in the data segment of the primary thread, or simply on the heap, or even somewhere else.

Concept of function pointers in C? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What is the point of function pointers?
hi all,
I want to get the basic and concrete idea of function pointers in C language.
ie 1) its usage in C
2) main applications it is currently using
3) unique features
4) its scope in embedded applciations etc
Hoping your co operation in this too.
__Kanu
Function Pointers are pointers, that is variables, which point to the address of a function.
Nice example here. Also this answer is a must read.

Resources