malloc c
#include <stdlib.h>
void *malloc(size_t size);
void exemple(void)
{
char *string;
string = malloc(sizeof(char) * 5);
if (string == NULL)
return;
string[0] = 'H';
string[1] = 'e';
string[2] = 'y';
string[3] = '!';
string[4] = '\0';
printf("%s\n", string);
free(string);
}
/// output : "Hey!"int main(int argc, char *argv[])
{
int* memoireAllouee = NULL;
memoireAllouee = malloc(sizeof(int));
if (memoireAllouee == NULL) // Si l'allocation a échoué
{
exit(0); // On arrête immédiatement le programme
}
// On peut continuer le programme normalement sinon
return 0;
}
ptr = malloc(size); //You dont need to cast
Also in C:
- scanf in c
- hello world program in c
- where is my vimrc
- how to add to the end of a linked list
- addition of two numbers in c
- undefined reference to `cv::VideoCapture::VideoCapture(cv::String const&)'
- c programming print pattern pyramid
- coin row problem in linear time
- kadane's algorithm
- prime check in c
- blockchain implementation
- semicolong after for() loop stackoverflow
- malloc c
- passing 2d array as parameter to function in c
- what is strikethrough in markdown
- 32bit or 64bit
- lazer codechef
- how to pass an array to a thread in c?
- fgets c
- amazon kinesis disaster recovery
- matplotlib pyplot legend location
- concatenate two strings in c
- the best programming language in 2021
- c how to define a variable