Fundamentals of C
What is C?
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.It is a very popular language, despite being old. The main reason for its popularity is because it is a fundamental language in the field of computer science.C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
Constants
constants are the values which will never change during the execution of program.
There are two type of Constants
- Primary constants
- Secondary constants
Primary constants are of three types.
- Integer Constants
- Real Constant or Floating Point Constant
- Character Constant
Variables
Variables are nothing but the name of the locations or addresses of memory which is given by programmer.
In Variables we can store any constants like integer, character or Real.
int
- stores integers (whole numbers), without decimals, such as123
or-123
float
- stores floating point numbers, with decimals, such as19.99
or-19.99
char
- stores single characters, such as'a'
or'B'
. Characters are surrounded by single quotes
To create a variable, specify the type and assign it a value:
1
type variableName = value;
Data Types
The data type specifies the size and type of information the variable will store.
Data Type | Size (bytes) | Description |
---|---|---|
int | 4 | Stores integers (whole numbers) |
float | 4 | Stores decimal numbers (single precision) |
double | 8 | Stores decimal numbers (double precision) |
char | 1 | Stores a single character |
void | 0 | Represents “no type” (used for functions) |
Operators
Operators in C are symbols that perform operations on variables and values. They are categorized into different types:
- Arithmetic Operators.
- Augmented Assignment Operators.
- Comparison Operators.
- Logical operators.
Header File Libraries
A header file in C is a file that contains function declarations, macros, and definitions. It helps you use built-in functions without writing them yourself.
💡 Think of a header file like a toolbox—it gives you ready-made tools (functions) so you don’t have to build them from scratch.
Common C Header Files & Their Uses
Header File | What It Does |
---|---|
<stdio.h> | Input & output (e.g.,printf , scanf ) |
<stdlib.h> | Memory management (malloc , free ), conversions |
<string.h> | String handling (strlen , strcpy , strcmp ) |
<math.h> | Math operations (sqrt , pow , sin , cos ) |
<ctype.h> | Character handling (toupper , isdigit ) |
<time.h> | Date & time functions (time , clock ) |
<stdbool.h> | Boolean values (true , false ) |
hello-world.c
1
2
3
4
5
6
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}