C Language Reference

Complete reference for C programming language including syntax, data types, operators, control structures, and standard library functions.

Language Fundamentals

Data Types

Fundamental data types in C programming

int

Integer data type

int age = 25;
float

Floating-point data type

float price = 19.99;
double

Double-precision floating-point

double pi = 3.14159;
char

Character data type

char grade = 'A';
void

Absence of type

void function();

Operators

C programming operators and their usage

Arithmetic

+, -, *, /, %

int result = a + b;
Assignment

=, +=, -=, *=, /=

a += 5;
Comparison

==, !=, <, >, <=, >=

if (a == b)
Logical

&&, ||, !

if (a && b)
Bitwise

&, |, ^, ~, <<, >>

int result = a & b;

Control Structures

Conditional and loop statements

if-else

Conditional execution

if (condition) { } else { }
switch

Multi-way selection

switch (value) { case 1: break; }
for

For loop

for (int i = 0; i < 10; i++)
while

While loop

while (condition) { }
do-while

Do-while loop

do { } while (condition);

Functions

Function declaration and definition

Declaration

Function prototype

int add(int a, int b);
Definition

Function implementation

int add(int a, int b) { return a + b; }
Parameters

Function arguments

void print(char* message);
Return

Return statement

return value;
Recursion

Function calling itself

int factorial(int n) { return n * factorial(n-1); }

Arrays

Array declaration and manipulation

Declaration

Array declaration

int numbers[10];
Initialization

Array initialization

int arr[] = {1, 2, 3};
Access

Array element access

int value = arr[0];
2D Arrays

Two-dimensional arrays

int matrix[3][3];
Strings

Character arrays

char name[50];

Pointers

Pointer variables and operations

Declaration

Pointer declaration

int *ptr;
Address

Address operator

ptr = &variable;
Dereference

Value at address

int value = *ptr;
Arithmetic

Pointer arithmetic

ptr++;
Dynamic

Dynamic memory allocation

int *arr = malloc(10 * sizeof(int));

Standard Library Functions

stdio.h

printf

Print formatted output

printf("Hello %s", name);
scanf

Read formatted input

scanf("%d", &number);
getchar

Read a character

char c = getchar();
putchar

Write a character

putchar('A');
gets

Read a line

gets(buffer);
puts

Write a string

puts("Hello");

stdlib.h

malloc

Allocate memory

int *ptr = malloc(sizeof(int));
free

Free allocated memory

free(ptr);
calloc

Allocate and initialize memory

int *arr = calloc(10, sizeof(int));
realloc

Reallocate memory

ptr = realloc(ptr, new_size);
exit

Terminate program

exit(0);
atoi

String to integer

int num = atoi("123");

string.h

strlen

String length

int len = strlen(str);
strcpy

Copy string

strcpy(dest, src);
strcat

Concatenate strings

strcat(str1, str2);
strcmp

Compare strings

if (strcmp(str1, str2) == 0)
strchr

Find character in string

char *pos = strchr(str, 'a');
strstr

Find substring

char *pos = strstr(haystack, needle);

math.h

sqrt

Square root

double result = sqrt(16);
pow

Power function

double result = pow(2, 3);
sin

Sine function

double result = sin(angle);
cos

Cosine function

double result = cos(angle);
abs

Absolute value

int result = abs(-5);
ceil

Ceiling function

double result = ceil(4.2);

Practice What You Learn

The best way to master C programming is through hands-on practice. Use our online compiler to try out the examples and experiment with the concepts.

Try Our Online C Compiler