This repository contains a collection of simple C programming examples that cover fundamental concepts of the C language. Each file demonstrates a specific topic, making it a valuable resource for beginners looking to learn and practice C programming.
C is a powerful general-purpose programming language that is widely used for system programming, embedded systems, and application development. This collection aims to introduce the core concepts of C programming in a straightforward manner.
-
0.HelloWorld.c: A simple program that prints "Hello, World!" to the console. This file introduces the basic structure of a C program.
-
1.Variables.c: Demonstrates how to declare and initialize variables of different data types, including integers, floats, and characters.
-
2.DataTypes.c: Explains the various data types available in C, such as
int
,float
,char
, and their characteristics. -
3.FormatSpecifiers.c: Shows how to use format specifiers in
printf
andscanf
for displaying and taking input of different data types. -
4.Constants.c: Introduces constants in C, including how to define and use constant values in programs.
-
5.ArithmeticOperators.c: Demonstrates the use of arithmetic operators (
+
,-
,*
,/
,%
) for performing basic mathematical calculations. -
6.UserInput.c: Shows how to read user input using
scanf
, along with basic input validation. -
7.MathFunctions.c: An introduction to standard math functions provided by the
math.h
library for performing advanced mathematical operations. -
8.IfStatements.c: Explains conditional statements using
if
,else if
, andelse
to control the flow of execution. -
9.SwitchStatements.c: Demonstrates the use of the
switch
statement for multi-way branching based on variable values. -
10.LogicalOperators.c: Introduces logical operators (
&&
,||
,!
) and their use in forming complex conditions. -
11.Functions.c: Covers the concept of functions in C, including function declaration, definition, and how to call them.
-
12.Arguments.c: Demonstrates how to pass arguments to functions and use them within the function body.
-
13.Return.c: Explains the use of
return
statements in functions and how to return values from them. -
14.TernaryOperator.c: Introduces the ternary conditional operator for simplifying conditional expressions.
-
15.FunctionPrototype.c: Covers the use of function prototypes to declare functions before they are defined.
-
16.StringFunctions.c: Demonstrates basic string operations using functions from the
string.h
library, including string length and concatenation. -
17.ForLoops.c: An introduction to
for
loops, covering their syntax and how to use them for iterating over a range of values. -
18.WhileLoops.c: Explains
while
loops and their use for repeated execution based on a condition. -
19.DoWhileLoops.c: Introduces
do while
loops and how they ensure at least one execution of the loop body. -
20.NestedLoops.c: Demonstrates nested loops and their applications in multi-dimensional data processing.
-
21.ControlFlowKeywords.c: Covers various control flow keywords in C, including
break
,continue
, andgoto
, explaining their purposes and use cases. -
23.2DArrays.c: Demonstrates the use of two-dimensional arrays for storing and manipulating tabular data, including accessing and modifying elements.
-
24.ArrayOfStrings.c: Shows how to handle arrays of strings in C, including declaration, initialization, and basic string manipulation.
-
25.SwapValues.c: Demonstrates different methods for swapping the values of two variables using temporary variables and pointers.
-
26.SortAnArray.c: Introduces basic sorting algorithms, such as bubble sort and selection sort, for organizing data in arrays.
-
27.Structs.c: Explains how to define and use structures for grouping related variables of different data types under a single name.
-
28.Typedef.c: Demonstrates how to create new type names (aliases) for existing data types using
typedef
, enhancing code readability. -
29.Enums.c: Covers enumerated types (enums) for defining variables that can hold a set of predefined constants, enhancing code readability.
-
30.RandomNumbers.c: Shows how to generate random numbers in C using the
rand()
function and seed them withsrand()
for randomness. -
31.BitwiseOperators.c: Introduces bitwise operators (
&
,|
,^
,~
,<<
,>>
) and their applications in low-level programming and data manipulation. -
32.Memory.c: Covers concepts of memory management, including stack vs. heap memory allocation and the importance of freeing dynamically allocated memory.
-
33.Pointers.c: Provides a deeper understanding of pointers, including pointer arithmetic and the relationship between arrays and pointers.
-
34.WritingFiles.c: Demonstrates how to create and write data to files using
fopen()
andfprintf()
, along with error checking for file operations. -
35.ReadingFiles.c: Explains how to read data from files using
fopen()
andfscanf()
, demonstrating techniques for processing file input.
To compile and run the examples, you'll need a C compiler (e.g., GCC) installed on your machine. You can compile an example with the following command:
gcc <filename.c> -o <output_executable>