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

ARRAY

Rating
-
Sold
-
Pages
5
Uploaded on
31-12-2024
Written in
2024/2025

C LANGUAGE NOTES ON ANSHUMAN SHARMA BOOK LEARN PROGRAMMING IN C

Institution
Course

Content preview

What is Array in C?
Arrays are used to store multiple values in a single variable, instead of declaring
separate variables for each value
An array is a variable that can store multiple values. For example, if you want
to store 100 integers, you can create an array for it.

int data[100];




How to declare an array?
In C, we have to declare the array like any other variable before using it. We
can declare an array by specifying its name, the type of its elements, and the
size of its dimensions. When we declare an array in C, the compiler allocates
the memory block of the specified size to the array name.
Syntax: dataType arrayName[arraySize];

For example, float mark[5];

Here, we declared an array, mark, of floating-point type. And its size is 5.
Meaning, it can hold 5 floating-point values.
It's important to note that the size and type of an array cannot be changed once it
is declared.

Example:

###include<stdio.h>
void main()
{
int i;
int arr[] = {2, 3, 4}; // Compile time array initialization
for(i = 0 ; i < 3 ; i++)
{
printf("%d \t",arr[i]);
}
}

, Types of Array in C
There are two types of arrays based on the number of dimensions it has. They
are as follows:
1. One Dimensional Arrays (1D Array)
2. Multidimensional Arrays
1. One Dimensional Array in C
The One-dimensional arrays, also known as 1-D arrays in C are those arrays
that have only one dimension.
Syntax of 1D Array in C

array_name [size];




Example:

#include <stdio.h>

main()
{

int values[5];

printf("Enter 5 integers: ");

// taking input and storing it in an array
for(int i = 0; i < 5; ++i)
{
scanf("%d", &values[i]);
}

printf("Displaying integers: ");

// printing elements of an array
for(int i = 0; i < 5; ++i)
{
printf("%d\n", values[i]);
}

}

Written for

Institution
Course

Document information

Uploaded on
December 31, 2024
Number of pages
5
Written in
2024/2025
Type
Class notes
Professor(s)
Kanika jindal
Contains
Commerce 1st semester

Subjects

$26.89
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
Himanshugupta01

Get to know the seller

Seller avatar
Himanshugupta01 GUJRANWALA GURU NANAK INSTITUTE OF MANAGEMENT AND TECHNOLOGY
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
10
Last sold
-
PTU EDUCATOR

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