Podcast
Questions and Answers
What are the data types int
, float
, double
and char
referred to as?
What are the data types int
, float
, double
and char
referred to as?
Simple data types
What is a simple data type?
What is a simple data type?
It is a basic data type used to store a single value at a time.
What does C provide aside from simple data types?
What does C provide aside from simple data types?
Structured data types
What is a structured data type?
What is a structured data type?
Name two kinds of structured data types.
Name two kinds of structured data types.
What is an array?
What is an array?
The data types of all boxes
in an array are the same.
The data types of all boxes
in an array are the same.
When using an array in a program, how do you define an array variable?
When using an array in a program, how do you define an array variable?
In the context of arrays, what is an element?
In the context of arrays, what is an element?
In the context of arrays, what is an index?
In the context of arrays, what is an index?
When initializing an array, what are the values enclosed with?
When initializing an array, what are the values enclosed with?
When accessing an array element, how do you refer to it?
When accessing an array element, how do you refer to it?
When changing the value of a specific element, how do you refer to the index number?
When changing the value of a specific element, how do you refer to the index number?
What represents the position of an element in the array?
What represents the position of an element in the array?
What is a collection of variables of the same type and organized in sequence?
What is a collection of variables of the same type and organized in sequence?
What is a collection of variables, organized in a systematic way so that it is easy to access and refer to them?
What is a collection of variables, organized in a systematic way so that it is easy to access and refer to them?
What is an individual value stored inside an array?
What is an individual value stored inside an array?
What is a basic data type used to store a single value at a time?
What is a basic data type used to store a single value at a time?
To access an array element, we need to specify its element number.
To access an array element, we need to specify its element number.
In declaring/defining an array variable, we need to specify its data type of its element, name, and the number of elements of the array.
In declaring/defining an array variable, we need to specify its data type of its element, name, and the number of elements of the array.
The values/elements of an array are enclosed with square brackets and separated by commas.
The values/elements of an array are enclosed with square brackets and separated by commas.
Index number always starts at 1.
Index number always starts at 1.
If we have 5 array elements in an array, the 4th element is at index 4.
If we have 5 array elements in an array, the 4th element is at index 4.
How do you declare an array named age with 5 integer elements?
How do you declare an array named age with 5 integer elements?
How do you initialize the array named grades with the values: A, B, C, D, E, F?
How do you initialize the array named grades with the values: A, B, C, D, E, F?
How do you access and display the 2nd element of the array in instruction number 12?
How do you access and display the 2nd element of the array in instruction number 12?
How do you access the 5th element of the array in instruction number 12?
How do you access the 5th element of the array in instruction number 12?
What will be the output of the statement below, considering the array in instruction number 12? printf("The value of 3rd element is %c \n", grades[2]);
What will be the output of the statement below, considering the array in instruction number 12? printf("The value of 3rd element is %c \n", grades[2]);
Flashcards
Simple data types
Simple data types
Data types that can hold only a single value at a time, such as int, float, double, and char.
Structured data types
Structured data types
A collection of variables organized for easy access and reference.
Array
Array
A collection of variables of the same type, stored in a contiguous memory location.
Array declaration
Array declaration
Signup and view all the flashcards
Element (in array)
Element (in array)
Signup and view all the flashcards
Index (in array)
Index (in array)
Signup and view all the flashcards
Array initialization
Array initialization
Signup and view all the flashcards
Accessing array elements
Accessing array elements
Signup and view all the flashcards
Changing array element
Changing array element
Signup and view all the flashcards
Storing values in array
Storing values in array
Signup and view all the flashcards
Study Notes
- CC103 - Computer Programming 2, Chapter C is about Arrays
Desired Learning Outcomes
- Distinguish between structured and simple data types, understanding their differences and applications.
- Arrays can be defined and there purpose understood.
- Arrays can be implemented in a program to store and manipulate data efficiently.
Course Content
- Structured Data Types
- Defining an Array
- Array Initialization
- Operations on Arrays
- Array of Arrays
- Pointers and Arrays
- Arrays as Function Parameters
- Strings
Simple Data Types
- Data types
int
,float
,double
andchar
are simple data types because they can only contain a single value. - A simple data type is used to store one value at a time.
- Variables of these types can be seen as boxes where you may store a value using the assignment operator (=).
- C provides structured data types as well as simple data types.
Structured Data Types
- A structured data type is a collection of variables organized so they can be accessed and referred to easily.
- Structured data types can collectively store several values.
- Structured data types can store 10 integer values, 1000 character values, or a combination of 20 float values and 25 integer values.
- Arrays and Structures are the two kinds of structured data types.
Arrays
- An array is a collection of variables that are of the same type and organized sequentially.
- Arrays can be viewed as a sequence of boxes where each box represents a variable for storing a value of some type.
- The data types of boxes in an array are the same: integer, character, float, or even another array.
Array Declaration
- An array variable is defined by specifying its element data type, name, and the number of elements in the array.
datatype arrayName[size];
is the syntax for declaring an array.int arr[10];
defines an arrayarr
that has 10 elements, each can store an integer value.
Accessing elements
- Each element is numbered from index 0 successively, up to index 9. Index numbers are used to access elements.
- Each element can be used as an ordinary integer variable.
- Element - An individual value stored inside an array, like numbers, text, and other data types.
- Index - The position of an element in the array, starting at 0.
Array Initialization
- An array can be initialized by specifying a value for each element.
- The values are enclosed in curly braces
{}
and separated by commas,
. int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
defines an array of 10 integers and stores the values 1 to 10.- To access an array element, refer to its index number:
arrayName[n];
, where n is the index of the element to access. - To change an array's element value, refer to its index number and assign it a new value:
arrayName[n] = newValue;
, where n is the index number.
Array Input
- Arrays can have values stored in them by the
scanf()
function inside afor
loop.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.