0% found this document useful (0 votes)
30 views9 pages

C Unit 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views9 pages

C Unit 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Module IV: Arrays and Strings

Arrays – Declaration and Definition of Array, accessing elements in array, Storing values in

array, linear search, binary search, bubble sort, Two – dimensional arrays, multidimensional

arrays. Arrays and Pointers, Pointer Arithmetic and arrays, array of pointers, Passing array

to function.

Strings – Declaration and Definition of String, String Initialization, unformatted I/O

functions, arrays of strings, string manipulation functions, string and pointers


Arrays
 Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the
same type.

 These are used to store multiple values in a single variable, instead of declaring separate variables
for each value.

 Arrays are the derived data type in C programming language which can store the primitive type of
data such as int, char, double, float, etc.

 The array is the simplest data structure where each data element can be randomly accessed by
using its index number.

 All arrays consist of contiguous memory locations.

 The lowest address corresponds to the first element and the highest address to the last element.
Why do we need arrays?

We can use normal variables (v1, v2, v3, ..) when we have a small number of objects, but if
we want to store a large number of instances, it becomes difficult to manage them with normal
variables. The idea of an array is to represent many instances in one variable.
Declaring Arrays:

 We can declare an array in the c language in the following way.

type arrayName [ arraySize ];

 This is called a single-dimensional array.

 The arraySize must be an integer constant greater than zero and type can be any valid C data
type.

Example:

int marks[5];

Or

float mark[5];
Initialization of C Array:

 The simplest way to initialize an array is by using the index of each element.

 We can initialize each element of the array by using the index.

 Consider the following methods to initialize array


Change Value of Array elements:

Input and Output Array Elements


Two Dimensional Array
 In C programming, you can create an array of arrays. These arrays are known as multidimensional
arrays.

 The simplest form of multidimensional array is the two-dimensional array.

 The 2D array is organized as matrices which can be represented as the collection of rows and
columns.

Example:
• Initializing Two-Dimensional Arrays:

You might also like