Pointers, Arrays, and Data Structure

Pointers, Arrays, and Data Structure

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.

  • One Dimensional Array

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

  • Multi-Dimensional Array

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.

  • Compile-time Initialization
  • Run time 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.

Scope of variables

要查看或添加评论,请登录

Rodrigo Zarate Algecira的更多文章

  • The /proc filesystem the /proc/maps and the /proc/mem files

    The /proc filesystem the /proc/maps and the /proc/mem files

    How to parse the /proc/maps file in order to read the virtual memory. The proc file system acts as an interface to…

  • How works the Shell in the background

    How works the Shell in the background

    If you type ls *.c at the prompt of the Linux Shell it will interpret this command and will print on the screen all…

  • C Static Libraries

    C Static Libraries

    Static libraries are compiled object files that hold all variables and functions an application needs to run (symbols),…

社区洞察

其他会员也浏览了