Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arrays - Definition, Declaration of Array, Initialization, Storing

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 57

UNIT II

 
Arrays – Definition, declaration of array, Initialization, storing
values in array, Two dimensional arrays, Multi-dimensional
arrays. Arrays and Pointers, Array of pointers
 
Strings – Declaration and Initialization, String Input / Output
functions, String manipulation functions, strings and pointers,
Arrays of strings

Pointers – Pointer variable, pointer declaration, Initialization of


pointer, Accessing variables through pointers, Pointer Arithmetic,
pointers to pointers, void pointers

1
Arrays
An array is defined as the collection of similar data items
stored at contiguous memory locations under the same name.
Arrays are the derived data type in C programming language
which can store the primitive type of data such as int, char,
double, float, etc.

Properties of Array

• Each element of an array is of same data type and carries the


same size, i.e., int = 4 bytes.
• Elements of the array are stored at contiguous memory
locations where the first element is stored at the smallest
memory location.
• Elements of the array can be randomly accessed using base
address and the size of the data element.
Types of Arrays
1-D Array Declaration

An array which has only one subscript is known as one dimensional


array. Arrays must be declared before they are used. General form of
array declaration is,
data_type array_name[size];

Example : int arr[10];

• Here int is the data type, arr is the name of the array and 10 is the
size of array. It means array arr can only contain 10 elements of int
type.
• Index of an array starts from 0 to size-1 i.e first element of arr array
will be stored at arr[0] address and the last element will occupy
arr[9].
1-D Array Initialization
It is possible to initialize an array during declaration.
Syntax: datatype array_name[size] = { val1, val2, val3, ..... valN };
Example:
int mark[5] = {19, 10, 8, 17, 9};
You can also initialize an array like this:
int mark[] = {19, 10, 8, 17, 9};
Here, we haven't specified the size. However, the compiler knows its
size is 5 as we are initializing it with 5 elements.
Accessing 1-D Arrays
Elements of an array can be accessed by indices.

The first element is mark[0], the second element is mark[1] and so on.

Few keynotes:
• Arrays have 0 as the first index, not 1. In this example, mark[0] is
the first element.
• If the size of an array is n, to access the last element, the n-1 index
is used. In this example, mark[4]
• Suppose the starting address of mark[0] is 2120. Then, the address
of the mark[1] will be 2124. Similarly, the address of mark[2] will
be 2128 and so on.
• This is because the size of a int is 4 bytes.
1-D Arrays-Example
// Program to read and print an array
#include <stdio.h>
int main()
{
int marks[10];
printf("Enter number of subjects: ");
scanf("%d", &n);
printf("Enter marks");
for(i=0; i<n; i++)
{
scanf("%d", &marks[i]);
}
for(i=0; i<n; i++)
Output
{
Enter number of subjects: 5
printf("%d", marks[i]);
Enter marks 50 60 70 80 90
}
50 60 70 80 90
return 0;
}
1-D Arrays-Example
// Program to print the array in reverse
#include <stdio.h>
int main()
{
int a[10];
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter elements");
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for(i=n-1; i>=0; i--)
{ Output
printf("%d", a[i]); Enter number of elements: 6
} Enter elements 5 8 9 2 1 6
return 0; 612985
}
1-D Arrays-Example
// Program to find the average of n numbers using arrays
#include<stdio.h>
int main()
{
int marks[10], i, n, sum = 0, avg; Output
printf("Enter number of subjects: "); Enter number of subjects: 5
scanf("%d", &n); Enter marks 50 60 70 80 90
printf("Enter marks: "); Sum = 350
for(i=0; i<n; i++) Average = 70.00
{
scanf("%d", &marks[i]);
}
for(i=0; i<n; i++) avg=sum/n;
{ Printf(“sum=%d”,sum);
sum=sum+marks[i]; printf("Average = %d", avg);
} return 0;
}
//program to find largest and smallest number in an array
int main()
{
int a[50],i,n,large,small;
printf("Enter the number of elements : ");
scanf("%d",&n);
printf("Enter the elements : ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]); Output
} Enter the number of elements: 6
large = small =a[0]; Enter elements: 40 60 20 80 90 50
for(i=1;i<n;i++) largest number is 90
{
if(a[i]>large)
smallest number is 20
large=a[i];
if(a[i]<small)
small=a[i];
}
printf("largest number is %d \n",large);
printf("smallest number is %d",small); return 0;
}
2-D Arrays
The two-dimensional array can be defined as an array of arrays.
The 2D array is organized as matrices which can be represented as the
collection of rows and columns.

Two-dimensional arrays are declared as


data-type array-name[row-size][column-size];
Example: int a[3][4];
2-D Arrays- Initialization
// Different ways to initialize two-dimensional array

int c[2][3] = {{1, 3, 0}, {-1, 5, 9}};

int c[][3] = {{1, 3, 0}, {-1, 5, 9}};

int c[2][3] = {1, 3, 0, -1, 5, 9};


// Program to read and print an two dimensional array
#include <stdio.h>
int main()
{
int a[5][5],i,j;
printf("Enter elements into an array");
for(i=0; i<2; i++)
{
for(j=0;j<2;j++)
{
scanf("%d", &a[i][j]); Output
}
Enter elements into an array 1 2 3 4
}
for(i=0; i<2; i++)
{ 12
for(j=0;j<2;j++) 34
{
printf("%d", a[i][j]);
}
printf(“\n”);
}
}
#include <stdio.h>
int main()
{
int a[5][5],i,j,r,c;
printf("enter row and column size of matrix :");
scanf("%d %d",&r,&c);
printf("Enter elements into the matrix");
for(i=0; i<r; i++)
{
for(j=0;j<c;j++)
{ Output
scanf("%d", &a[i][j]); enter row and column size of matrix :3 2
}
}
for(i=0; i<r; i++) Enter the elements into the matrix 8 9 7 6 5 4
{
for(j=0;j<c;j++)
{ 89
printf("%d", a[i][j]);
} 76
printf(“\n”); 54
}
}
#include<stdio.h> Transpose of a matrix
int main()
{
int r, c, i, j, matrix[10][10];
printf("Enter the number of rows and columns of a matrix : ");
scanf("%d%d", &r, &c);
printf("Enter elements of the matrix\n");
for (i = 0; i < r; i++)
{ Output
for (j = 0; j < c; j++) Enter the number of rows and columns of
{ a matrix : 3 2
scanf("%d", &matrix[i][j]);
} Enter elements of the matrix
} 89
printf(“Transpose of a matrix is : \n”); 76
for (i = 0; i < c; i++) 54
{ Transpose of a matrix is :
for (j = 0; j < r; j++) 875
{ 964
printf("%d\t",matrix[j][i]);
}
printf("\n");
}
#include<stdio.h> Sum of all elements in an array
int main()
{
int m, n, i, j, matrix[10][10],sum=0;
printf("Enter the number of rows and columns of a matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of the matrix\n");
for (i = 0; i < m; i++)
{ Output
for (j = 0; j < n; j++)
Enter the number of rows and columns of
{
a matrix : 3 3
scanf("%d", &matrix[i][j]);
}
Enter elements of the matrix
}
897
for (i = 0; i < n; i++)
765
{
543
for (j = 0; j < m; j++)
Sum= 54
{
sum = sum+matrix[i][j];
}
}
printf(“sum=%d”,sum);
}
Trace of a matrix
int main()
{
int m, n, i, j, matrix[10][10],sum=0;
printf("Enter the number of rows and columns of a matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of the matrix\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++) Output
{
Enter the number of rows and columns of
scanf("%d", &matrix[i][j]);
a matrix : 3 3
}
}
Enter elements of the matrix
for (i = 0; i < m; i++)
897
{
765
for (j = 0; j < n; j++)
543
{
sum=17
if(i==j)
sum = sum+matrix[i][j];
}
}
printf(“sum=%d”,sum);
return 0;
}
Addition of two Matrices
#include <stdio.h>
int main()
{ for ( i = 0; i < r; i++)
int a[5][5], b[5][5], result[5][5],i,j,r,c; {
printf("Enter the number of rows and for ( j = 0; j < c; j++)
columns of a matrices: "); {
scanf("%d%d", &r, &c); result[i][j] = a[i][j] + b[i][j];
}
printf("Enter elements of 1st matrix\n"); }
for (i = 0; i < r; i++) printf("\nSum Of Matrix: \n");
for (j = 0; j < c; j++) for ( i = 0; i < r; i++)
scanf("%d", &a[i][j]); {
for (j = 0; j < c; j++)
printf("Enter elements of 2nd matrix\n"); {
for (i = 0; i < r; i++) printf("%d \t", result[i][j]);
for ( j = 0; j < c;j++) }
scanf("%d", &b[i][j]); printf("\n");
}
return 0;
}
#include <stdio.h>
for (i = 0; i < p; i++)
int main()
for (j = 0; j< q; j++)
{
scanf("%d", &b[i][j]);
int m, n, p, q, i, j, k, sum = 0;
int a[10][10], b[10][10], c[10][10];
for (i = 0; i < m; i++)
for (j = 0; j< n; j++)
printf("Enter number of rows and columns of
{
first matrix\n");
c[i][j] =0;
scanf("%d%d", &m, &n);
for (k = 0; k < n; k++)
printf("Enter elements of first matrix\n");
{
c[i][j]= c[i][j] + a[i][k]*b[k][j];
for (i = 0; i < m; i++)
}
for (j = 0; j < n; j++)
}
scanf("%d", &a[i][j]);
printf("Product of the matrices:\n");
printf("Enter number of rows and columns of
for (i = 0; i < m; i++)
second matrix\n");
{
scanf("%d%d", &p, &q);
for (j = 0; j < q; j++)
printf("%d\t", c[i][j]);
if (n != p)
printf("\n");
printf("The multiplication isn't possible.\n");
}
else
}
{
return 0;
printf("Enter elements of second matrix\n");
}
OUTPUT
Enter number of rows and columns of first matrix

22

Enter elements of first matrix

12

34

Enter number of rows and columns of second matrix

22

Enter elements of second matrix

12

34
Multi – Dimensional Array

• It is a collection of homogeneous elements where each element is


referenced by more than 2 dimensions is called multi-dimensional
array.
• The general format for declaration of multi dimensional array is

datatype array_name [s1][s2][s3]…….[sn];

• Example : int a[5][6][5] 150 elements


float b[1][2][3][4] 24 elements
Strings
String is a sequence of characters that is treated as a single data item
and terminated by null character '\0’.
A string is actually one-dimensional array of characters in C language.

For example: The string "hello world" contains 12 characters


including '\0' character which is automatically added by the compiler
at the end of the string.

char str[10];

char str[10]=“Hello”;
Strings-Declaring and Initializing
There are different ways to initialize a character array variable.

char name[6] = “MRCET"; // valid character array initialization


char name[10] = {'L','e','s','s','o','n','s','\0'}; // valid initialization
char name[ ] = {'L','e','s','s','o','n','s','\0'}; // valid initialization

Remember that when you initialize a character array by listing all of


its characters separately then you must supply the '\0' character
explicitly.

Some examples of illegal initialization of character array are,

char ch[3] = "hell"; // Illegal


char str[4];
str = "hell"; // Illegal
Strings-Example Programs

#include<stdio.h>
int main( )
{
char str[15] = "hello mrcet";
char str1[15] ={'h','o','w',' ','a','r','e',' ','y','o','u'};
printf("%s %s",str,str1);
return 0;
}

Output
hello mrcet how are you 
Strings-Example Programs
//program to read and print city
#include<stdio.h> #include<stdio.h>
int main() #include <string.h>
{ int main()
char city[50]; {
printf("Enter your city: "); char city[50];
scanf(“%s”,city); printf("Enter your city: ");
printf("Your city is: "); gets(city);
printf(“%s”,city); printf("Your city is: ");
return 0; puts(city);
} return 0;
}
Output
Enter your city: Delhi
Your city is: Delhi
Output
Enter your city: New Delhi
Your city is: New Delhi
Enter your city: New Delhi
Your city is: New
getchar() and putchar()
getchar() function reads the next available character from the screen and returns it as an
integer. This function reads only single character at a time. You can use this method in the
loop in case you want to read more than one character from the screen.

//program to read and print name #include<stdio.h>


int main( )
#include<stdio.h> {
int main( ) int c,i;
{ printf("Enter your name”);
int c; for(i=0;i<12;i++)
printf("Enter your name”); {
c = getchar( );
c = getchar( ); putchar( c );
putchar( c ); }
return 0; return 0;
} }
Output Output
Enter your name Rama Enter your name Rama Krishna
R Rama Krishna
String Handling Functions
C supports a large number of string handling functions in the standard
library "string.h".
Few commonly used string handling functions are :

Function Work of Function

strlen() computes string's length

strcpy() copies a string to another

strcat() concatenates(joins) two strings

strcmp() compares two strings

strlwr() converts string to lowercase

strupr() converts string to uppercase

strrev() returns reverse of the given string.


Strlen()
The strlen() function takes a string as an argument and returns its length.

Example:
#include <stdio.h>
#include <string.h>
int main()
{
char a[20]="Program";
char b[20]={'P','r','o','g','r','a','m','\0'};
printf("Length of string a = %d \n",strlen(a));
printf("Length of string b = %d \n",strlen(b));
return 0;
}

Output:
Length of string a = 7
Length of string b = 7
Example:
#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
int length;
printf("\n\nEnter a string you wish to calculate the length of : ");
gets(a);
length = strlen(a);
printf("\n\nThe length of the input string is: %d\n\n", length);
return 0;
}

OUTPUT:
Enter a string you wish to calculate the length of : mrcet
The length of the input string is: 5
Strcpy()
The strcpy() function copies the string pointed by source to the destination.
The strcpy() function also returns the copied string.

Syntax: strcpy(destination, source);

Example:
#include<stdio.h>
#include<string.h>
int main()
{
char a[50], b[50];
strcpy(a, "Engineering");
strcpy(b, a);
printf("%s\n", b);
return 0;
}
Output: Engineering
Strcat()
The Syntax: strcat(first_string, second_string) function
concatenates two strings and result is returned to first_string.

#include <stdio.h>
#include <string.h>
int main()
{
char str1[100] = "This is ", str2[] = “MRCET";
strcat(str1, str2);
puts(str1);
puts(str2);
return 0;
}
Output:
This is MRCET
MRCET
Strcmp()
The strcmp() function takes two strings and returns an integer.
The strcmp() compares two strings character by character.
If the first character of two strings is equal, the next character of two
strings are compared. This continues until the corresponding
characters of two strings are different or a null character '\0' is
reached.

Return Value Remarks


0 if both strings are identical (equal)
if the ASCII value of the first unmatched
negative
character is less than second.

positive if the ASCII value of the first unmatched


integer character is greater than second.
The strcmp(first_string, second_string) function compares two string and
returns 0 if both strings are equal.

#include<stdio.h>
#include <string.h>
int main()
{
char str1[20],str2[20];
printf("Enter 1st string: ");
gets(str1);
printf("Enter 2nd string: ");
gets(str2);
if(strcmp(str1,str2)==0)
printf("Strings are equal");
else
printf("Strings are not equal");
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd";
int result;

// comparing strings str1 and str2


result = strcmp(str1, str2);
printf("strcmp(str1, str2) = %d\n", result);

// comparing strings str1 and str3


result = strcmp(str1, str3);
printf("strcmp(str1, str3) = %d\n", result);
return 0;
}
OUTPUT
strcmp(str1, str2) = 32
strcmp(str1, str3) = 0
Strlwr()
The strlwr(string) function returns string characters in lowercase.
Example:
#include<stdio.h>
#include <string.h>
int main()
{
char str[20];
printf("Enter string: ");
gets(str);
printf("String is: %s",str);
printf("\nLower String is: %s",strlwr(str));
return 0;
}
Output:
Enter string: MALLAreddy
String is: MALLAreddy
Lower String is: mallareddy
Strupr()
The strupr(string) function returns string characters in uppercase.
Example:
#include<stdio.h>
#include <string.h>
int main()
{
char str[20];
printf("Enter string: ");
gets(str);
printf("String is: %s",str);
printf("\nUpper String is: %s", strupr(str));
return 0;
}
Output:
Enter string: mallareddy
String is: mallareddy
Upper String is: MALLAREDDY
Strrev()
The strrev(string) function returns reverse of the given string.
Example:
#include<stdio.h>
#include <string.h>
int main()
{
char str[20];
printf("Enter string: ");
gets(str);
printf("String is: %s",str);
printf("\nReverse String is: %s",strrev(str));
return 0;
}
Output:
Enter string: destiny
String is: destiny
Reverse String is: ynitsed
Pointers
Pointer Definition and syntax
The pointer in C language is a variable which stores the address of
another variable. This variable can be of type int, char, array, or any
other pointer.
Syntax:
Data_type *variable_name;
• Asterisk(*)is called as Indirection Operator. It is also called as
Value at Address Operator.
• It Indicates Variable declared is of Pointer type. variable_name
must follow the rules of an identifier.
Example
int *ip; //pointer to an integer

38
double *dp //pointer to double
Pointer Variable Declaration
• The syntax for declaration of a pointer variable is

Datatype *pointer_name;
Example : int *ptr;
• It declares the variable ‘ptr’ is a pointer variable that can point to
an int datatype.
float *ptr;
• It declares the variable ‘ptr’ is a pointer variable that can point to
an float datatype.
int a, *ptr;
ptr = &a;
• The pointer variable should always point to the corresponding
type of data.
Pointer Variable Declaration

Example : float a;
int *p; This is illegal because of the type mismatch
p =&a;
• Assigning absolute address to a pointer variable is prohibited
int *p;
p=5000; //illegal

• int a,*p=&a; // it is valid


• int *p=&a , a; // not valid

Target variable must be declared first


Pointer concept with diagram

int i=5; int i=5, *j;


int *j; or
j=&i;
j=&i;
Pointer Basics
• Normal variable stores the value whereas pointer variable stores
the address of the variable.
• The content of the C pointer always be a whole number i.e.
address.
• Always C pointer is initialized to null, i.e. int *p = null.
• The value of null pointer is 0.
• & symbol is used to get the address of the variable.
• * symbol is used to get the value of the variable that the pointer
is pointing to.
• If a pointer in C is assigned to NULL, it means it is pointing to
nothing.
Pointer Basic Example – Accessing variable through pointer

#include <stdio.h>
int main() a ptr
{ 50 5025
int *ptr, a;
a = 50; 5025 5045
ptr = &a;
printf("Value of a =%d\t", a);
printf("Address of a =%u\n", &a);
printf("Address of ptr =%u\t", &ptr);
printf("Value of ptr =%d", *ptr);
printf(“Address in ptr =%u", ptr);
return 0;
}
OUTPUT:
Value of a = 50 Address of a = 5025
Address of ptr = 5045 Value of ptr = 50 Address in ptr = 5025
Pointer Basic Example – Accessing variable through pointer

#include<stdio.h>
int main()
{
int i=5,*p; i p
p=&i; 5 2002
printf(“Value of i=%d",i);
printf(“Address of i=%u ",&i); 2002 2010
printf(“Value at address of i=%d ",*(&i));
printf(“Address in p=%u ",p);
printf(“Address of p =%u ",&p);
printf(“Value at p=%d ",*p);
OUTPUT
return 0; Value of i=5
} Address of i=2002
Value at address of i=5
Address in p = 2002
Address of p = 2010
Value at p=5
Program on Reference(&) and De-reference operator(*)

#include <stdio.h>
int main()
{
int *pc, c=22;
printf("Address of c:%u\n",&c);
printf("Value of c:%d\n\n",c);
pc=&c;
printf("Address in pointer pc:%u\n",pc);
printf("Content of pointer pc:%d\n",*pc);
c=11;
printf("Address in pointer pc:%u\n",pc);
printf("Content of pointer pc:%d\n",*pc);
*pc=2;
printf("Address of c:%u\n",&c);
printf("Value of c:%d\n",c);
return 0;
}
Output
• Address of c: 26867
• Value of c: 22
• Address in pointer pc:26867
• Content of pointer pc: 22
• Address in pointer pc:26867
• Content of pointer pc: 11
• Address of c: 26867
• Value of c: 2

46
Pointer to Pointer
If a pointer holds the address of another pointer then such type of
pointer is known as pointer-to-pointer or double pointer

Syntax: int **ptr;

Example :
int a, *p1, **p2;
a=65;
p1=&a;
p2=&p1;
47
Pointer to Pointer Example

#include<stdio.h>
int main()
{
int a, *p1, **p2;
a=65;
p1=&a;
p2=&p1;
printf("a = %d\n", a);
printf("address of a = %u\n", &a);
printf("p1 = %d\n", p1);
printf("address p1 = %d\n", &p1);
printf("*p1 = %d\n", *p1);
printf("p2 = %d\n", p2);
printf("*p2 = %d\n", *p2);
printf("**p2 = %d\n", **p2);
return 0;
}
48
void pointers

• A void pointer is nothing but a pointer variable declared using the


reserved word in C 'void'.

• When a pointer variable is declared using keyword void – it becomes


a general purpose pointer variable.

• Address of any variable of any data type (char, int, float etc.) can be
assigned to a void pointer variable.

Ex:- void *ptr; // Now ptr is a general purpose pointer variable

49
void pointer - Example
#include<stdio.h>
int main()
{
int a = 7;
float b = 7.6;
void *p;
p = &a;
printf("Integer variable is = %d", *( (int*) p) );
p = &b;
printf("\nFloat variable is = %f", *( (float*) p) );
return 0;
}
OUTPUT
Integer variable is = 7
Float variable is = 7.600000
50
Pointer Arithmetic

Pointer Arithmetic on Integers

Pointer Expression How it is evaluated ?


ip = ip + 1 ip => ip + 1 => 1000 + 1*4 => 1004
ip++ or ++ip ip++ => ip + 1 => 1004 + 1*4 => 1008
ip = ip + 5 ip => ip + 5 => 1008 + 5*4 => 1028
ip = ip - 2 ip => ip - 2 => 1028 - 2*4 => 1020
ip-- or --ip ip => ip - 1 => 1020 - 1*4 => 1016

51
Arrays and pointers
• When an array is declared, compiler allocates sufficient amount of
memory to contain all the elements of the array.
• Base address i.e address of the first element of the array is also
allocated by the compiler.

• Example : int x[5] ={1,2,3,4,5};

X[0] X[1] X[2] X[3] X[4]


5 6 7 8 9
1000 1004 1008 1012 1016

Base address

• If int *p; p=&x[0] is equal to p=x , it means p is pointer


52
only to the first element not the whole array.
Arrays and pointers
From the above example,
p = &x[0] = 1000
p+1 = &x[1] =1004
p+2 = &x[2] =1008
p+3 = &x[3] =1012
p+4 = &x[4] = 1016

• As the array elements are always stored in contiguous memory


locations. A pointer increment always points to an immediate next
location of its type.

• Array elements can be accessed using pointers as


*p = x[0]
*(p+1) = x[1];
*(p+2) = x[2];
*(p+3) = x[3];
*(p+4) = x[4];
53
Example 1: Pointers and Arrays
#include <stdio.h>
int main()
{
int x[5]={5,6,7,8,9};
int *p,i=0;
p=x;
printf(“Element value address\n\n”);
while(i<5)
{
printf(“x[%d]\t %d \t %u\n”,i,*p, p);
p++;
i++; OUTPUT
} Element value address
return 0;
X[0] 5 1000
} X[1] 6 1004
X[2] 7 1008
X[3] 8 1012
X[4] 9 1016
Example 2: Pointers and Arrays

#include <stdio.h>
int main()
{
int x[5] = {1, 2, 3, 4, 5};
int* ptr;
ptr = &x[2]; // ptr is assigned the address of the third element
printf("*ptr = %d \n", *ptr);
printf("*(ptr+1) = %d \n", *(ptr+1));
printf("*(ptr-1) = %d", *(ptr-1));
return 0;
}
OUTPUT
*ptr= 3

*(ptr+1) = 4
*(ptr-1) = 2
Array of Pointers

We can also have array of pointers. Pointers are very helpful in


handling character array with rows of varying length.

char *name[3] = {
"Adam",
"chris",
"Deniel"
};
//Now lets see same array without using pointer
char name[3][20] = {
"Adam",
"chris",
"Deniel"
};

You might also like