Bird
0
0
DSA Cprogramming~5 mins

Array Declaration and Initialization in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an array in C?
An array in C is a collection of elements of the same type stored in contiguous memory locations. It allows storing multiple values under a single name.
Click to reveal answer
beginner
How do you declare an integer array of size 5 in C?
You declare it as: int arr[5]; This creates space for 5 integers in memory.
Click to reveal answer
beginner
What is the difference between declaration and initialization of an array?
Declaration creates the array with a specified size but does not assign values. Initialization assigns values to the array elements at the time of declaration or later.
Click to reveal answer
beginner
How to initialize an array with values at the time of declaration?
Example: int arr[3] = {10, 20, 30}; This creates an array of size 3 with elements 10, 20, and 30.
Click to reveal answer
intermediate
What happens if you initialize fewer elements than the declared size?
The remaining elements are automatically set to zero. For example, int arr[5] = {1, 2}; sets arr[0]=1, arr[1]=2, and arr[2], arr[3], arr[4] = 0.
Click to reveal answer
How do you declare an array of 10 floats in C?
Aint arr[10];
Bfloat arr;
Cfloat arr[10];
Darr float[10];
What is the index of the first element in a C array?
ADepends on the array size
B0
C-1
D1
What will be the value of arr[3] after this declaration? <br> int arr[5] = {1, 2, 3};
A0
B3
CUndefined
DGarbage value
Which of the following is a valid initialization of an array in C?
Aint arr = {5, 10, 15};
Bint arr[3] = (5, 10, 15);
Cint arr[3] = 5, 10, 15;
Dint arr[] = {5, 10, 15};
What is the size of the array declared as int arr[4];?
A4 elements
BDepends on the values
CSize of int in bytes
DCannot be determined
Explain how to declare and initialize an integer array of size 5 with values 1 to 5 in C.
Use int arr[5] = {...}; syntax.
You got /3 concepts.
    Describe what happens when you declare an array but do not initialize it in C.
    Think about default values in local arrays.
    You got /3 concepts.