Monday, 25 February 2013
Single Integer
Another array example
//Find
the lowest number in the array num[10]
main()
{
int
num[10]={4,9,11,2,13,77,8,19,21,1};
int min,
i;
min =
num[0];
for (i=1; i<10;
i++) {
if (num[i]
< min)
min =
num[i];
}
printf(“The
minimum is %d”, min);
}
Array
example
/* which
type of integer is valid in array declaration*/
#include <stdio.h>
int main(void)
{
int
x[5]; /* x[5] is array initialization /
x[0]=23; /* valid */
x[2.3]=5; /* invalid: index is not an int */
return
0;
}
Examples
int x
[5] = { 1,2,3,4,5 }; size 10 bytes
creates array with elements 0-4
values 1-5
int x
[5] = {4,3}; size 10 bytes
creates array with elements 0-4
values 4,3,0,0,0
int x
[ ] = {1,2,3}; size 6 bytes
creates array with elements 0-2
values 1,2,3
char
c[4] = {‘M’, ‘o’ , ‘o’ }; size 4 bytes
creates array with elements 0-3
values M o o NULL
1-D Array Declaration
To
declare a 1-D Array, we specify 1 size
data_type array_name [size];
For
Eg.
int number[30];
float marks[60];
char name[15];
Difference Between Ordinary Variable & Arrays
Ordinary variable store one
value
at a time
Arrays are used for storing more than one value at a
time in a single variable name
Arrays
What
is an array?
An array is a consecutive series
of variables that
share one variable name
The individual data items in an
array must all be of the same data type,
accessed using an index
Often used when dealing with
multiple data items possessing common characteristics
Ex. 24 hourly temperature readings
might be stored in array named temperature
Subscribe to:
Posts (Atom)
String functions
Read This: strncpy() strncat() strstr () strlen() Predefined function defined in string.h . Returns the len...
-
Each variable must have a field specification For each field specification there must be variable address The scanf reads unti...
-
Implicit type conversion, also known as coercion An automatic type conversion by the compiler If operands are of differ...