Pointers, Arrays, and Data Structure
Rodrigo Zarate Algecira
Full stack | php | Developer | Drupal | SQL | Linux | Powershell | GO
What are pointers and how to use them
What are arrays and how to use them
Types of Arrays
We can divide arrays into 3 types.
Following is a syntax of a one-dimensional array.
type arrName[size];
Two Dimensional Array
To create a two-dimensional array we use the following syntax.
type arrName[rows][cols];
Syntax to create a Multi-dimensional Array
//scoreboard[player][match][year]
int scoreboard[2][3][2];
Types of Array initialization
There are two types of array initialization.
What are the differences between pointers and arrays
How to use strings and how to manipulate them
A string is a sequence of characters enclosed in double-quotes.
There is no string data type in C.
To store string values in C we create an array of type char.
The syntax of a character array to store string value is given below.
char strName[size];
Where strName is the name of the variable and size tells us about the number of characters the array will hold.
1 strcpy(s1, s2);
Purpose: Copies string s2 into string s1.
2 strcat(s1, s2);
Purpose: Concatenates string s2 onto the end of string s1.
3 strlen(s1);
Purpose: Returns the length of string s1.
4 strcmp(s1, s2);
Purpose: Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.
5 strchr(s1, ch);
Purpose: Returns a pointer to the first occurrence of character ch in string s1.
6 strstr(s1, s2);
Purpose: Returns a pointer to the first occurrence of string s2 in string s1.