Computer Professional C language Programming learning Focus: pointer-to-easy

Source: Internet
Author: User
Tags function prototype

C language is process-oriented, and C + + is Object-oriented

The difference between C and C + +:

C is a structured language that focuses on algorithms and data structures. The design of the C program is primarily concerned with the output (or implementation process (transaction) control) of the input (or environmental conditions) that is processed through a process.

C + +, the first consideration is how to construct an object model, so that the model can fit with the corresponding problem domain, so that you can get the state information of the object to get output or implementation process (transaction) control. So the biggest difference between C and C + + is that their way of thinking about solving problems is different. C + + is more advanced than C because "the concept of design has been incorporated into C + +".

The biggest difference between C and C + + is that their way of thinking is different for solving problems. The reason that C + + is more advanced than C is because "the concept of design has been incorporated into C + +", and in terms of language itself, in C more is the concept of algorithms. Then C is not important, wrong! Algorithm is the basis of programming, good design if there is no good algorithm, just as not. Moreover, "C plus good design" can also write very good things.

I believe the pointer has always been a difficult point for people who have studied C language. In fact, C language has only such a difficult point, the breach of this difficult point, to do is to practice, after all, want to learn a language is not practice is not good.

Each variable has a memory location, and each memory location defines an address that can be accessed using the hyphen (&) operator, which represents an address in memory, and we first understand what the memory address is and how to access it. Look at the following instance, which will output the defined variable address:

Small series recommended a learning C language/c++ study Skirt "730, 130, 221", whether you are Daniel or small white, is to change careers or want to join the study together to learn about progress together! The skirt has the development tool, many dry goods and the technical information to share!

When the above code is compiled and executed, it produces the following results:

Next, let's see what a pointer is!

A pointer is a variable whose value is the address of another variable, which is the direct address of the memory location. Just like any other variable or constant, you must declare it before using the pointer to store other variable addresses. The general form of a pointer variable declaration is:

Type *name;

The type here is the base type of the pointer, it must be a valid C data type, and name is a pointer variable. The asterisk * used to declare the pointer is the same as the asterisk used in the multiplication. However, in this statement, the asterisk is used to specify that a variable is a pointer. The following is a valid pointer declaration:

The actual data type of the value of all pointers, whether integer, float, character, or other data type, is the same as a long hexadecimal number representing the memory address. The only difference between pointers to different data types is that the data type of the variable or constant that the pointer points to is different.

Here are some examples of pointers that may be used normally

Small series recommended a learning C language/c++ study Skirt "730, 130, 221", whether you are Daniel or small white, is to change careers or want to join the study together to learn about progress together! The skirt has the development tool, many dry goods and the technical information to share!

Next we'll look at what a function pointer

A function always occupies a contiguous area of memory, and the function name is sometimes converted to the first address of the memory region where the function is located, which is very similar to the name of the array. We can assign the first address of the function (or the entry address) to a pointer variable so that the pointer variable points to the area of memory where the function resides, and then the function can be found and invoked by a pointer variable. This pointer is a function pointer.

function pointers are defined in the following form:

ReturnType (*pointername) (param list);

ReturnType returns a value type for the function, pointernmae as the pointer name, and PARAM list as the function argument.

Attention:

() priority is higher than *, the first parenthesis cannot be omitted if writing ReturnType *pointername (paramlist);

Is the function prototype, which indicates that the function's return value type is ReturnType *.

Write a simple chestnut below:

The results of compiling and running are as follows:

The MSG function is called above, and fun_p is a function pointer.

Summarize:

The pointer (Pointer) is the address of the memory, and the C language allows a variable to hold the pointer, a variable called a pointer variable. Pointer variables can hold the address of the base type data, as well as the addresses of arrays, functions, and other pointer variables.

Common pointers mean:

Small series recommended a learning C language/c++ study Skirt "730, 130, 221", whether you are Daniel or small white, is to change careers or want to join the study together to learn about progress together! The skirt has the development tool, many dry goods and the technical information to share!

These are the things that C + + can do

Server Development Engineer, AI, cloud computing engineer, information security (hacker anti-hacker), big data, data platform, embedded engineer, streaming media server, Data control solution, image processing, audio and video development engineer, game server, distributed system, game assistant, etc.

Computer Professional C language Programming learning Focus: pointer-to-easy

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.