0% found this document useful (0 votes)
10 views

Notes on Arrays in C

Uploaded by

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

Notes on Arrays in C

Uploaded by

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

Notes on Arrays in C++

Definition
• An array is a collection of elements of the same data type stored in
contiguous memory locations.
• It allows random access using indices, where the first element is
accessed with index 0.
Syntax for Array Declaration and Initialization
1. Declaration:
2. dataType arrayName[arraySize];
Example:
int arr[5]; // Declares an array of 5 integers
3. Initialization:
4. dataType arrayName[arraySize] = {value1, value2, ..., valueN};
Example:
int arr[5] = {1, 2, 3, 4, 5};
5. Accessing Elements:
6. arrayName[index];
Example:
int x = arr[2]; // Accesses the third element (index 2)
7. Size of an Array:
8. sizeof(arr) / sizeof(arr[0]); // Gives the total number of elements
Commonly Asked Array Questions in Interviews
Easy Questions
1. Find the largest/smallest element in an array.
2. Reverse an array.
3. Find the second largest element in an array.
4. Check if an array is sorted.
5. Find the sum of all elements in an array.
6. Remove duplicates from a sorted array.
7. Move all zeros to the end of the array.
8. Find the maximum and minimum of an array using a single traversal.
Moderate Questions
1. Find a subarray with a given sum (positive numbers).
2. Find the "Kth" smallest or largest element in an array.
3. Rearrange the array in alternating positive and negative numbers.
4. Merge two sorted arrays without using extra space.
5. Find the missing number in an array of size n containing numbers from
1 to n.
6. Find all pairs in an array that sum up to a given number.
7. Kadane's Algorithm: Find the maximum sum of a contiguous subarray.
8. Find the longest subarray with the sum equal to 0.
9. Find the majority element (element appearing more than n/2 times).
10.Search in a rotated sorted array.
11.Rotate an array.

You might also like