Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - * What's the difference between A and a[]?
* What's the difference between A and a[]?
What's the difference between *a and a[]: char a[] defines an array, and char *a defines a pointer.

1.char a[]="asdf "。 At this time, the array A is stored in the stack of the function, and this stack is emptied when the function is pushed out.

2.char *a="asdf ","asdf "is a constant, not stored in the stack, but stored in a special section.

3. You can use printf("0X%x\t0X%x\n ",name, a); Take a look. When defined as an array, these two addresses are very close, but when defined as a pointer, they are different.

If the difference between int *a and int a[] is simple, then int *a is a pointer to an integer. Int a[] is an integer array named as the first address of its first element. One of them is a formal parameter and the other is an actual parameter. The formal parameter points to the address of the actual parameter. The above program is wrong and has nothing to do with these two parameters. The second line of Fun is changed to for(I = 0;; I<n-1; I+= 1) can be sorted from largest to smallest.

Extended data:

The advantages of C language are as follows:

1, concise, compact, flexible and convenient.

C language * * * has only 32 keywords and 9 control statements. The writing form of the program is free and case-sensitive. Combine the basic structure and sentences of high-level language with the practicality of low-level language. C language can manipulate bits, bytes and addresses like assembly language, which are the most basic working units of a computer. ?

2. Rich operators

Operators in C language cover a wide range, and there are 34 operators in * *. C language regards parentheses, assignment and cast as operators. Therefore, C language has extremely rich operation types and diverse expression types. Flexible use of various operators can achieve operations that are difficult to achieve in other high-level languages. ?

3. Rich data types

The data types of C language are: integer, real number, character, array, pointer, structure and * * * object. Can be used to realize the operation of various complex data structures. The concept of pointer is introduced to improve the efficiency of the program.

4. Flexible and practical expression.

C language provides a variety of operators and methods to represent values, and the expression of problems can be obtained in many ways, so its programming is more active and flexible. Its grammatical restrictions are not strict, and its programming freedom is great. For example, it can be used for integer data, character data and logical data. ?

5. Allow direct access to physical addresses to operate hardware.

Because C language allows direct access to physical addresses and direct operation of hardware, it has both the functions of high-level language and many functions of low-level language, and can operate on bits, bytes and addresses like assembly language. These are the most basic working units of computers and can be used to write system software.

6. The generated object code has high quality and high program execution efficiency.

C language is faster than assembly language in describing problems, less workload, good readability, easy debugging, modification and transplantation, and the code quality is equivalent to that of assembly language. Generally speaking, C language is only less efficient than the object code generated by assembler 10% ~ 20%.

7. Good portability

86% of C compilers of C language on different machines are common, so C compilers are easy to transplant. A program written in C language in one environment can be transplanted to another completely different environment without any changes or slight changes. ?

8. Strong expression

C language has rich data structures and operators. Including integer, array type, pointer type, union type and other data structures, to achieve the operation of various data structures. There are 34 kinds of operators in C language, with a wide range. Flexible use of various operators can achieve extremely difficult operations.

C language can directly access the physical address of hardware and perform bit operation. It has many advantages of both high-level and low-level languages. It can be used to write system software and develop application software, and has become a general programming language. In addition, C language has powerful graphics functions and supports a variety of displays and drivers. And the calculation function and logical judgment function are powerful.

References:

Baidu encyclopedia -C language