C Reference
Element
Description
Example
printf
Prints formatted output to the console.
printf("Hello, %s!\n", "World");
scanf
Reads formatted input from the console.
scanf("%d", &num);
getchar
Reads a single character from the console.
char ch = getchar();
putchar
Writes a single character to the console.
putchar('A');
fabs
Returns the absolute value of a floating-point number.
double result = fabs(-3.14);
ceil
Rounds up a floating-point number to the nearest integer.
double rounded = ceil(3.14);
floor
Rounds down a floating-point number to the nearest integer.
double rounded = floor(3.14);
sqrt
Calculates the square root of a number.
double squareRoot = sqrt(25.0);
pow
Calculates the power of a number.
double power = pow(2, 3);
strlen
Returns the length of a string.
int length = strlen("Hello");
strcpy
Copies one string to another.
char dest[20]; strcpy(dest, "Hello");
strcat
Concatenates two strings.
char str1[20] = "Hello, "; strcat(str1, "World");
strcmp
Compares two strings.
int result = strcmp("abc", "abd");
strchr
Finds the first occurrence of a character in a string.
char *position = strchr("Hello", 'e');
malloc
Allocates a block of memory on the heap.
int *arr = (int*)malloc(5 * sizeof(int));
calloc
Allocates a block of memory on the heap and initializes it to zero.
int *arr = (int*)calloc(5, sizeof(int));
realloc
Changes the size of a previously allocated block of memory.
arr = (int*)realloc(arr, 10 * sizeof(int));
free
Deallocates a block of memory on the heap.
free(arr);
isalpha
Checks if a character is an alphabetic character.
int result = isalpha('A');
isdigit
Checks if a character is a digit.
int result = isdigit('5');
toupper
Converts a character to uppercase.
char upper = toupper('a');
tolower
Converts a character to lowercase.
char lower = tolower('A');
fclose
Opens a file.
FILE *file = fopen("example.txt", "r");
fclose
Closes a file.
fclose(file);
fread
Reads data from a file.
fread(buffer, sizeof(char), 100, file);
fwrite
Writes data to a file.
fwrite(data, sizeof(int), 5, file);
rand
Generates a pseudo-random number.
int randomNum = rand();
srand
Seeds the random number generator.
srand(time(NULL));
time
Returns the current calendar time.
time_t t = time(NULL);
ctime
Converts a time value to a string.
char *str = ctime(&t);
localtime
Converts a time value to a structure representing local time.
struct tm *local = localtime(&t);
memcpy
Copies a block of memory.
int source[5] = {1, 2, 3, 4, 5}; memcpy(dest, source, 5 * sizeof(int));
memmove
Moves a block of memory, even if the source and destination overlap.
memmove(dest, source, 5 * sizeof(int));
memset
Sets a block of memory to a specific value.
int arr[10]; memset(arr, 0, 10 * sizeof(int));
strncpy
Copies a certain number of characters from one string to another.
char dest[10]; strncpy(dest, "Hello", 5);
strncat
Concatenates a certain number of characters from one string to another.
char str1[10] = "Hello, "; strncat(str1, "World", 3);
strncmp
Compares a certain number of characters in two strings.
int result = strncmp("abc", "abd", 2);
getenv
Retrieves the value of an environment variable.
char *value = getenv("PATH");
system
Executes a shell command.
system("ls -l");
exit
Exits the program.
exit(0);