Two-dimensional Arrays or Matrices in C

by Dinesh Thakur Category: Array

A two-dimensional array (commonly called a matrix) consists of elements of the same type arranged in rows and columns. The rows and columns of a matrix are numbered starting from 0. Thus, for an array of size rows x cols, the row subscripts are in the range 0 to rows - 1 and the column subscripts are in the range 0 to cols - 1.

Global Arrays in C

by Dinesh Thakur Category: Array

As in case of scalar variables, we can also use external or global arrays in a program, i. e., the arrays which are defined outside any function. These arrays have global scope.

C Program HSC mark list for a single student

by Dinesh Thakur Category: Array

In the HSC examination, there are six subjects each having a maximum of 100 marks. To pass the examination, a student has to score at least 35 marks in each subject. If a student passes, total marks and percentage marks are calculated and a class is awarded based on the percentage marks (perce)as follows:

C program to calculate the mean and standard deviation

by Dinesh Thakur Category: Array

For a list of numbers x whose elements are referred to as x0, x1,…..., xn-1, the mean bar x and the standard deviation a are defined as

C program to add two vectors of size n

by Dinesh Thakur Category: Array

For two vectors a and b having n elements each, the addition operation yields a vector (say c) of size n. The ith element of the result vector is obtained by adding the corresponding vector elements, i.e., ci =ai+ bi. The algorithm to perform the desired addition is given below.

C Program Print a list of numbers in reverse order

by Dinesh Thakur Category: Array

In this program, an array num of type int is used to store the given integer numbers and variable nelem to store their count. First, the value of nelem is read. Then a for loop is used to read the given numbers and store them in array num. Finally, another for loop is used to print the given numbers in reverse order.

Static Arrays in C

by Dinesh Thakur Category: Array

This feature can be used with arrays as well. A static array has the following characteristics:

const Vectors in C

by Dinesh Thakur Category: Array

If we desire that the elements of a vector should not be modified, we can declare that vector as a const vector. However, we must initialize this vector when it is declared, as it is not possible to modify it subsequently. Thus, a const vector can be declared and initialized as shown below.

Arrays as Function Parameters in C

by Dinesh Thakur Category: Array

We can pass an array (one-, two- or multidimensional) as an argument to a function. The C language allows us to define functions that have one or more arrays as parameters. These parameters can be of different types and sizes. Moreover, we can mix scalar and array parameters. A function that uses a single one-dimensional array as a parameter can be defined as shown below.

One-dimensional Arrays C

by Dinesh Thakur Category: Array

Array Declaration

Every array is given a name. The rules for naming arrays are the same as those used for variable names. As with scalar variables, an array must be declared before it is used. The declaration of a one-dimensional array takes the following form:

What is Arrays? Type of array

by Dinesh Thakur Category: Array

Declaration of arrays, Initialization of arrays, Multi dimensional Arrays, Elements of multi dimension arrays and Initialization of multidimensional arrays. The C language provides a capability that enables the user to define a set of ordered data items known as an array.

What is arrays? How is Array declared. Explain with Example

by Dinesh Thakur Category: Array

Often, we have to deal with groups of objects of same type such as names of persons, instrument readings in an experiment, roll numbers of students, and so on. These groups can be conveniently represented as elements of arrays. An array is defined as a sequence of objects of the same data type. All the elements of an array are either of type int (whole numbers), or all of them are of type char, or all of them are of floating decimal point type, etc. An array cannot have a mixture of different data types as its elements. Also, array elements cannot be functions; however, they may be pointers to functions. In computer memory, array elements are stored in a sequence of adjacent memory blocks. Since all the elements of an array are of same data type, the memory blocks allocated to elements of an array are also of same size. Each element of an array occupies one block of memory. The size of memory blocks allocated depends on the data type and it is same as for different data types.

How can we declare an Array

by Dinesh Thakur Category: Array

Declaring Arrays : Arrays are declared with the bracket punctuators [ ], as shown in the following syntax :

How do I know how many elements an Array can hold

by Dinesh Thakur Category: Array

The amount of memory an array can consume depends on the data type of an array. In DOS environment, the amount of memory an array can consume depends on the current memory model (i.e. Tiny, Small, Large, Huge, etc.).

Characteristics of Arrays in C

by Dinesh Thakur Category: Array

1) An array holds elements that have the same data type.

2) Array elements are stored in subsequent memory locations.

Compare and relate Pointers with Arrays

by Dinesh Thakur Category: Array

Pointers and Arrays : Data objects in an array can be referenced through pointers instead of using array subscripts. The data type of such a pointer is referred to as "pointer to array of type". The array name itself behaves like a pointer, so there are several alternative methods to accessing array elements. For example :

What are the steps to initialize an Array

by Dinesh Thakur Category: Array

Initializing Arrays : Arrays are initialized with a brace-enclosed list of constant expressions. A list of initializers for an incomplete array declaration completes the array's type and completely defines the array size.

Difference Between Strings and Character Arrays

by Dinesh Thakur Category: Array

A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicitly specified by using the static keyword. Actually, a string is a character array with following properties :

What is the difference between a String and an Array

by Dinesh Thakur Category: Array

An array is an array of anything. A string is a specific kind of an array with a well-known convention to determine its length.

Page 3 of 3

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles