CC103 Arrays

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What are the data types int, float, double and char referred to as?

Simple data types

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?

Structured data types

What is a structured data type?

<p>It is a collection of variables, organized in a systematic way so that it is easy to access and refer to them.</p> Signup and view all the answers

Name two kinds of structured data types.

<p>Arrays and Structures</p> Signup and view all the answers

What is an array?

<p>It is a collection of variables of the same type and organized in sequence.</p> Signup and view all the answers

The data types of all boxes in an array are the same.

<p>True (A)</p> Signup and view all the answers

When using an array in a program, how do you define an array variable?

<p>By specifying its data type of its elements, name, and the number of elements of the array.</p> Signup and view all the answers

In the context of arrays, what is an element?

<p>It is an individual value stored inside an array.</p> Signup and view all the answers

In the context of arrays, what is an index?

<p>It represents the position of an element in the array. It always starts at 0.</p> Signup and view all the answers

When initializing an array, what are the values enclosed with?

<p>Curly braces <code>{}</code></p> Signup and view all the answers

When accessing an array element, how do you refer to it?

<p>Refer to its index number</p> Signup and view all the answers

When changing the value of a specific element, how do you refer to the index number?

<p>Assign a new value</p> Signup and view all the answers

What represents the position of an element in the array?

<p>Index</p> Signup and view all the answers

What is a collection of variables of the same type and organized in sequence?

<p>Array</p> Signup and view all the answers

What is a collection of variables, organized in a systematic way so that it is easy to access and refer to them?

<p>Structured data type</p> Signup and view all the answers

What is an individual value stored inside an array?

<p>Element</p> Signup and view all the answers

What is a basic data type used to store a single value at a time?

<p>Simple data type</p> Signup and view all the answers

To access an array element, we need to specify its element number.

<p>True (A)</p> Signup and view all the answers

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.

<p>True (A)</p> Signup and view all the answers

The values/elements of an array are enclosed with square brackets and separated by commas.

<p>False (B)</p> Signup and view all the answers

Index number always starts at 1.

<p>False (B)</p> Signup and view all the answers

If we have 5 array elements in an array, the 4th element is at index 4.

<p>False (B)</p> Signup and view all the answers

How do you declare an array named age with 5 integer elements?

<p>int age[5];</p> Signup and view all the answers

How do you initialize the array named grades with the values: A, B, C, D, E, F?

<p>char grades[6] = {'A', 'B', 'C', 'D', 'E', 'F'};</p> Signup and view all the answers

How do you access and display the 2nd element of the array in instruction number 12?

<p>printf(&quot;%c&quot;, grades[1]);</p> Signup and view all the answers

How do you access the 5th element of the array in instruction number 12?

<p><code>grades[4]</code></p> Signup and view all the answers

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]);

<p>The value of 3rd element is C</p> Signup and view all the answers

Flashcards

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

A collection of variables organized for easy access and reference.

Array

A collection of variables of the same type, stored in a contiguous memory location.

Array declaration

Specifies the data type, name, and number of elements for an array.

Signup and view all the flashcards

Element (in array)

A value stored within an array.

Signup and view all the flashcards

Index (in array)

Position of an element in the array, starting from 0.

Signup and view all the flashcards

Array initialization

Assigning initial values to elements of an array during declaration.

Signup and view all the flashcards

Accessing array elements

To access a specific value inside the array with its index number.

Signup and view all the flashcards

Changing array element

Change value of specific array element.

Signup and view all the flashcards

Storing values in array

Storing values into the 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 and char 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 array arr 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 a for loop.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Data Structures and Arrays Quiz
18 questions
Data Structures and Arrays Quiz
5 questions
Computer Science Chapter 5: Arrays
21 questions
Use Quizgecko on...
Browser
Browser