void pointer in C [duplicate] - c

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is void* and to what variables/objects it can point to
What does void* represent in C?
Please give a reason for the use, too...

void * is a "typeless" pointer in C, that is, a pointer that may point to an object of any type. It is used if one does not know the type of the data to be stored beforehand.

Related

Is there a way to detect wheter a pointer has been initialized or not in C? [duplicate]

This question already has answers here:
How to find uninitialized variables in C on Linux?
(2 answers)
How to check if a variable has been initialized in C?
(3 answers)
Closed 2 years ago.
I pass a pointer to my function but if this is not initialized I get, obviously, segmentation fault. I could solve this porblem by assigning NULL to that pointer when declared (or, in general, before passing it to my function), but if I wanted my funtion to detect that pointer is not initialized?
The common way is to always initialize pointers to NULL when you first declare them or after freeing them so that whenever you have to manipulate a pointer, if it's equal to NULL, you know that you have to allocate them and populate their data.

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

Does it matter where you put the pointer? (asterix) sign? [duplicate]

This question already has answers here:
Why is the asterisk before the variable name, rather than after the type?
(12 answers)
Closed 7 years ago.
I Just want to know what is the difference between the following way of assigning a pointer. i was watching a C tutorial online and couldn't understand why he used the second pointer like this char * buffer;. Instead of char *buffer
Like the way I use the pointer in all my C learning. is it style?
e.g
FILE *pFile;
struct product *next;
does it matter where you put the asterix (pointer) or what is the meaning behind it?
Nope, there is no difference, it's a matter of preference.
I tend to put it as struct product* next because it makes it clearer that the type of next is product*, AKA a pointer to a product. But different people advocate different things.

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:)

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