Home / Tutorial / Programming / C / C ++ Programming Tutorials (Part 16) Relationships and differences between pointer and arrays
c programming tutorial

C / C ++ Programming Tutorials (Part 16) Relationships and differences between pointer and arrays

Pointer Pointer

We know that the pointer is a special type of variable, which points to the other variables in different ways in different ways. Variables are of different types, such as pointers, integers, double etc. Such as int * I; Here i is a pointer, which can point to variables of integer type. In this way, the pointer can be declared for various variables in the program, as well as pointers for different pointers. That is, in this case, the pointer will not point to any variable, rather it will point to another pointer. Such as int ** p; Here p is an integer type pointer. That is, the pointer can be pointing to p, which is what points to an integer.

Again char ** c; Here c is a character type pointer. Noteworthy, the number of variable variables in a specific type of variable, all of them must be of the same type (exception void type). There is no pointer that is itself an integer type, but it is pointing to a double-type pointer. In this way using multiple signals is necessary to make pointers. Such as int *** p; Here three signatures have been used. Which means the p is a pointer that points to the integer type of the pointer to the pointers of the variable.

Pointer and arrays

There is a close connection between pointer and array in c. Many things of the array are like the pointer. Again the pointer structure can be said to be very similar to an array. An array is discussed in the previous issue. But to discuss pointer and array, all the features of the array must be remembered. So a brief idea about arrays is given earlier.

A brief idea about arrays

The array is basically one of the main features of the high-level language and it is one of the main features of C. To understand what the array is, you have to go back a little bit. We know, variables can be declared in C. We know what the variable is, what it declares and how it works. The core idea of the array is nothing new. Arrays are a method of declaring multiple variables together. Suppose, there is a need to declare five variables in a program simultaneously. Then the user can declare five variables in common rules. For this, you need to write five statements, and in the same statement, you can declare five variables. But the statement would be very big. But using the array, it is possible to declare five variables simultaneously with a statement.

It may not be very important for only five variables, but when it is necessary to declare 100 or 1000 variables simultaneously in a large program, coding can be much easier when using arrays. An array is the sum of several variables. So, declare the array as variable declaration. Need to write a data type before the variable declaration, as is the need for arrays also. Array declaration syntax: data_type array_name [array_size] | The name of the array is the name of any variable. This means that the names of the variables will be named according to the rules of the array. The new thing here is the array size. Since the array is the sum of many variables.

So, we have to say how many arrays are declared with variables. This is the array size. The size of the array will be composed of variables. The main difference between an array and variable declaration is the size. Such as int prime [10], valid [5]; Etc. Here are ten titles named Prime, five integers named Valid. And 10 variables named Prime can be accessed separately. In that case prime [0], prime [1], prime [2] etc. will be the names of each variable. The number that is used in the parentheses after the name of the prime is called the index of the element of the array. It allows access to all the elements of an array. Indexing array starts with 0.

The pointer is of different types and their works are of different types. Just use the Constant Pointer to control whether to read the file or not. Each pointer of this type has specific uses.

Thanks for staying with TeachDoor.

About Admin

Leave a Reply

Your email address will not be published. Required fields are marked *