Detailed notes of C language

Posted by wxflint on Tue, 04 Jan 2022 12:02:29 +0100

  • The meaning of i + + equihyphenation
    ++i  i Add 1 and then participate in other operations
    --i  i Participate in other operations after subtracting 1
    i++  i After participating in the operation, i The value of is increased by 1
    i--  i After participating in the operation, i The value of is subtracted by 1

    eg: 
    i=5;
    y=i++;   So now i=6,y=5


    eg: 
    i=5;
    y=++i;   So now i=6,y=6

For this kind of continuous addition and subtraction, you can try it yourself first

#include<stdio.h>
int main()
{    
    int i=8;
    printf("%d\n",++i);
    printf("%d\n",--i);
    printf("%d\n",i++);
    printf("%d\n",i--);
    printf("%d\n",-i++);
    printf("%d\n",-i--);
    return 0;
}

See what these print out

This will have a deeper understanding of C language learning!

#include<stdio.h>
int main()
{
    int i=5,j=5,p,q;
    p=(i++)+(++i)+(--i)+(i--);
    q=(j++)+(++j)+(--j)+(j--)-(-j++);
    printf("%d,%d,%d,%d",p,q,i,j);
    return 0;
}

For example, the above formula can assign the quantities of i and j at will and see what is typed by the computer

  • Assignment operator

Assignment operator '='
a=b=c=5 means a=(b=(c=5)); Calculate the value in parentheses first, and assign it from the right

Remember to assign values from the right;

Compound assignment operator
a+=5 is equivalent to a=a+5
         x*=y+7                                                                        x=x*(y+7)
         r%=p                                                                            r=r%p

Is to move the front a + to the right and leave the front letter in place

For example, cattle + = horse is cattle = cattle + horse

High number + = me is (failed) high number = high number + me

  • putchar function

 putchar(""); Special character output function
Before using this function, you must include the command in the file:
                       #include<stdio. h> Or #include"stdio.h"

#include<stdio.h>
int main()
{
    char a='A',b='B',c='C',d='D',e='F',f='E',r='G',p='CH';
    putchar(a);putchar(b);putchar(c);putchar(d);putchar('\n');
    putchar(e);putchar(f);
    putchar('\t');
    putchar(r);putchar(p);
    return 0;
}

You can practice properly. You can change the characters inside. As for what kind of characters you can change.  

  • printf output function

When we first learn the C language, we will type a hello world command, and we need to use the printf function

Format output function
printf("format control string", output table column);
% d indicates decimal shaping output;
% ld indicates decimal long integer output;
% c means output by character type, etc;

#include<stdio.h>
int main()
{
    int a=88,b=89;
    printf("%d%d\n",a,b);
    printf("l%d,l%d\n",a,b);
    printf("%c,%c\n",a,b);
    printf("a=%d,b=%d",a,b);
    return 0;
}

Also try what the computer prints. Knock it yourself. Mine is not necessarily right. In the process of knocking the code, you will find many shortcomings and improve them!

  • scanf function

Scanf} the C language allows scanf functions to be preceded by stdio H file.
scanf("format control string", address table column);    &
    &a,&b;
Width: Specifies the width of the input (i.e. the number of characters) with a decimal integer
For example: scanf ('% 5D', & A);
Enter 123456789
He will only assign 12345 to variable a, and the rest will be truncated.
For example: scanf ("% 4D% 4D", & A, & B);
Enter 12345678
Only 1234 will be assigned to a and 5678 to b.
Note:
When inputting character data, if there are no non format characters in the format control string, it is considered that all input characters are valid characters.
For example:
    scanf("%c%c%c",&a,&b,&c);
The input is: d e f (there is a space between each letter)
Then'd 'is assigned to a', 'b' and 'e' to c.
Therefore, the value can be assigned correctly only when you enter def (there is no space between each letter)!

#include<stdio.h>
int main()
{
    int a,b,c;
    printf("input a,b,c\n");
    scanf("%d%d%d",&a,&b,&c);
    printf("a=%d,b=%d,c=%d",a,b,c);
    return 0;
}

As mentioned above, you still have to type it yourself!  

  • Byte code occupied
#include<stdio.h>
int main()
{
int a;
    long b;
    float f;
    double d;
    char c;
    printf("int:%d\nlong:%d\nfloat:%f\ndouble:%f\nchar:%c\n",sizeof(a),sizeof(b),sizeof(f),sizeof(d),sizeof(c));
return 0;
}

This can be copied directly and put on the computer. You can deepen your image of bytes

This is the end of today's content. You can pay attention to me and you will see the gradual changes in me!

Topics: C Back-end