Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Suggestion

Rating
-
Sold
-
Pages
10
Uploaded on
12-11-2024
Written in
2024/2025

Lecture notes of 10 pages for the course Tech 120 at MANONMANIUM SUNDARANAR UNIVERSITY (Data science)

Institution
Course

Content preview

Unit-III
ARRAYS
Introduction
✓ An array is a collection of homogeneous (similar) data items that are stored under
one common name.
✓ Individual data item (array elements) in an array is identified by index or subscript
enclosed in square brackets with array name.
✓ The elements in an array are stored in continuous memory location.
DECLARATION OF AN ARRAY
✓ Like other variable an array must be declared before they are used so that the
compiler can allocate space for them in memory.
✓ The syntax for array declaration is:
data type array_name [size];
✓ The data type specifies the array elements data type.
✓ Size indicates the maximum number of elements that can be stored in the array.
✓ For example
float height [10];
The above array declaration represents the array name is height, we can store a maximum
of 10 elements and the array elements are floating point data type.


ARRAY INITIALIZATION
The array elements can be initialized when they are declared like ordinary variables
otherwise they will take garbage values.
Syntax: data type array_name [size] = {value 0, value 1, . . . , value n-1)
The initialized values are specified within curly braces separated by commas.
Example: int Marks [3] = {70, 80, 90};
This statement declares the variable Marks as an array of 3 elements and will be assigned
the values specified in list as below.

70
Marks [0]
80
Marks [1]
90
Marks [2]

, Like ordinary variables, the values to the array can be initialized as follows.
int Marks[3];
Marks [0] = 70;
Marks [1] = 80;
Marks [2] = 90;
Character array can be initialized as follows:
char gender[2] = {'M','F'};
Classification of Array
✓ One Dimensional Array
✓ Two Dimensional Array
One dimensional array:
If the array has only one subscript then it is called one dimensional or single dimensional
array.
Syntax:
data type array_name [size];
Declaration Example:
int height[10], weight[10];
char name[20];
Initialization Example:
int marks[3] = {20,60,67};
Characteristics of One Dimensional Array
✓ Array size must be positive number.
✓ Array elements are counted from 0 to size-1.
✓ String arrays are terminated with null character ('\0').
Example Program 1:
// Program to print total marks of a student
# include <stdio.h>
void main()
{
int marks[10], i, n, Total = 0;

Written for

Institution
Course

Document information

Uploaded on
November 12, 2024
Number of pages
10
Written in
2024/2025
Type
Class notes
Professor(s)
Anitha
Contains
All classes

Subjects

$5.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
anithas

Get to know the seller

Seller avatar
anithas Holy cross
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions