c Programming
c Programming
IN C
Presented By : Raj Verma
1
INTRODUCTION TO ARRAYS
What is an Array?
• A data structure that stores multiple elements of
the same type in a contiguous memory block.
• Each element can be accessed using an index.
Why Arrays Are Important:
• Simplifies handling large amounts of related data.
• Crucial for efficient data organization and
manipulation.
int number[5];
Example:
C PROGRAMMING
2
KEY CHARACTERISTICS OF ARRAYS
Contiguous Memory Allocation: All elements are
stored in
adjacent memory locations.
Fixed Size: Declared size cannot be changed during
program execution.
Index-Based Access:
Elements number[2]
are accessed via their index (starting from
0).
Example: accesses the third
element. C PROGRAMMING
Homogeneous Elements: All elements must be of the
3
DECLARING AND INITIALIZING ARRAYS
Declaration Initialization
Syntax Methods
At the time of declaration
data_type
array_name[size]; int marks[5] = {10, 20, 30, 40, 50};
Example: int marks[5]; Assigning values later
marks[0] = 10;
C PROGRAMMING
4
ACCESSING ARRAY ELEMENTS
Accessing Modifying
•Elements
Use the array name Elements
marks[2] = 75;
and index to retrieve // Updates the third element
values. to Note:
75. Index starts at 0
• Example: marks[2]);
printf("%d",
and goes up to size - 1.
// Outputs the third
element
C PROGRAMMING
5
TYPES OF ARRAYS IN C
Multi-Dimensional Arrays
Used for higher-dimensional
data (rarely needed).
6
LOOPING THROUGH ARRAYS
Why Loops Are Useful:
1
C PROGRAMMING
Uninitialized Arrays:
Arrays not explicitly initialized may contain
garbage
C PROGRAMMING
values.
Incorrect Indexing: Forgetting the 0-based
10
CONCLUSION
Key Takeaways:
• Arrays are essential for managing
collections of homogeneous data.
• Provide efficient storage and access
mechanisms.
• Useful for algorithms, matrix operations,
and string manipulations.
Next Steps:
• Explore dynamic arrays and pointers to
arrays.
• Practice using arrays in real-world
C PROGRAMMING
scenarios for deeper understanding.
THANK
FOR YOUR
ATTENTION
YOU !