[First introduction to C language (Part 2)] # Must Read for Getting Started #

Preface

A deep understanding of basic knowledge can help us use code flexibly.

1. Array

1. Definition of array

The definition of array is given in C language: a set of elements of the same type.

Example: int arr[10] = {1,2,3,4,5,6,7,8,9,10};//Define an integer array with a maximum of 10 elements.

2. Subscript of array

C language stipulates that each element of the array has a subscript, and the subscript starts from 0.
Arrays can be accessed through subscripts.

For example: int arr[10] = {0};
If the array has 10 elements, the subscript range is 0-9

3. Use of arrays

#include <stdio.h>
int main()
{
int i = 0;
int arr[10] = {1,2,3,4,5,6,7,8,9,10};
for(i=0; i<10; i++)
{
printf(“%d “, arr[i]);
}
printf(”\n”);
return 0;
}

2. Operator

Just a simple list

1. Arithmetic operators

++ - * / %

2. Shift operator

<< >>

3. Bit operators

& | ^

4. Assignment operator

= += -= *= /= &= ^= |= >>= <<=

5. Unary operator

! Logical inverse operation
- negative value
+ positive value
&Get address
Type length of sizeof operand (in bytes)
~Bitwise inversion of a number
– Prefix, Post-position –
++Pre-position, post-position++
Example: – Pre-position Insert image description here
Post-position – Post++
Insert image description here
++Front
Insert image description here

Insert image description here

*Indirect access operator (operator for parsing)
(type) Forced type conversion

6. Relational operators

< <= > >= != (indicates inequality) == (indicates equality)

7. Logical operators

&&Logical AND (meaning AND)
||Logical OR (meaning OR)

8. Conditional operators

is also called the ternary operator, expressed as exp1?exp2:exp3
Example: Insert image description here

9. Comma expression

exp1,exp2,exp3,…expN
例:Insert image description here

10. Subscript references, function calls and structure members

[ ] (This is used for array subscript reference)
() (call function)
. Example:
Insert image description here
Insert image description here

->
Example: ->Equivalent to (*)
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_73807021/article/details/128976173